repo
stringlengths
5
67
path
stringlengths
4
116
func_name
stringlengths
0
58
original_string
stringlengths
52
373k
language
stringclasses
1 value
code
stringlengths
52
373k
code_tokens
list
docstring
stringlengths
4
11.8k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
86
226
partition
stringclasses
1 value
eslint/eslint
tools/internal-rules/no-invalid-meta.js
hasMetaDocsDescription
function hasMetaDocsDescription(metaPropertyNode) { const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value); return metaDocs && getPropertyFromObject("description", metaDocs.value); }
javascript
function hasMetaDocsDescription(metaPropertyNode) { const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value); return metaDocs && getPropertyFromObject("description", metaDocs.value); }
[ "function", "hasMetaDocsDescription", "(", "metaPropertyNode", ")", "{", "const", "metaDocs", "=", "getPropertyFromObject", "(", "\"docs\"", ",", "metaPropertyNode", ".", "value", ")", ";", "return", "metaDocs", "&&", "getPropertyFromObject", "(", "\"description\"", ",", "metaDocs", ".", "value", ")", ";", "}" ]
Whether this `meta` ObjectExpression has a `docs.description` property defined or not. @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule. @returns {boolean} `true` if a `docs.description` property exists.
[ "Whether", "this", "meta", "ObjectExpression", "has", "a", "docs", ".", "description", "property", "defined", "or", "not", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/tools/internal-rules/no-invalid-meta.js#L62-L66
train
eslint/eslint
tools/internal-rules/no-invalid-meta.js
hasMetaDocsCategory
function hasMetaDocsCategory(metaPropertyNode) { const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value); return metaDocs && getPropertyFromObject("category", metaDocs.value); }
javascript
function hasMetaDocsCategory(metaPropertyNode) { const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value); return metaDocs && getPropertyFromObject("category", metaDocs.value); }
[ "function", "hasMetaDocsCategory", "(", "metaPropertyNode", ")", "{", "const", "metaDocs", "=", "getPropertyFromObject", "(", "\"docs\"", ",", "metaPropertyNode", ".", "value", ")", ";", "return", "metaDocs", "&&", "getPropertyFromObject", "(", "\"category\"", ",", "metaDocs", ".", "value", ")", ";", "}" ]
Whether this `meta` ObjectExpression has a `docs.category` property defined or not. @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule. @returns {boolean} `true` if a `docs.category` property exists.
[ "Whether", "this", "meta", "ObjectExpression", "has", "a", "docs", ".", "category", "property", "defined", "or", "not", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/tools/internal-rules/no-invalid-meta.js#L74-L78
train
eslint/eslint
tools/internal-rules/no-invalid-meta.js
hasMetaDocsRecommended
function hasMetaDocsRecommended(metaPropertyNode) { const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value); return metaDocs && getPropertyFromObject("recommended", metaDocs.value); }
javascript
function hasMetaDocsRecommended(metaPropertyNode) { const metaDocs = getPropertyFromObject("docs", metaPropertyNode.value); return metaDocs && getPropertyFromObject("recommended", metaDocs.value); }
[ "function", "hasMetaDocsRecommended", "(", "metaPropertyNode", ")", "{", "const", "metaDocs", "=", "getPropertyFromObject", "(", "\"docs\"", ",", "metaPropertyNode", ".", "value", ")", ";", "return", "metaDocs", "&&", "getPropertyFromObject", "(", "\"recommended\"", ",", "metaDocs", ".", "value", ")", ";", "}" ]
Whether this `meta` ObjectExpression has a `docs.recommended` property defined or not. @param {ASTNode} metaPropertyNode The `meta` ObjectExpression for this rule. @returns {boolean} `true` if a `docs.recommended` property exists.
[ "Whether", "this", "meta", "ObjectExpression", "has", "a", "docs", ".", "recommended", "property", "defined", "or", "not", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/tools/internal-rules/no-invalid-meta.js#L86-L90
train
eslint/eslint
lib/rules/space-infix-ops.js
getFirstNonSpacedToken
function getFirstNonSpacedToken(left, right, op) { const operator = sourceCode.getFirstTokenBetween(left, right, token => token.value === op); const prev = sourceCode.getTokenBefore(operator); const next = sourceCode.getTokenAfter(operator); if (!sourceCode.isSpaceBetweenTokens(prev, operator) || !sourceCode.isSpaceBetweenTokens(operator, next)) { return operator; } return null; }
javascript
function getFirstNonSpacedToken(left, right, op) { const operator = sourceCode.getFirstTokenBetween(left, right, token => token.value === op); const prev = sourceCode.getTokenBefore(operator); const next = sourceCode.getTokenAfter(operator); if (!sourceCode.isSpaceBetweenTokens(prev, operator) || !sourceCode.isSpaceBetweenTokens(operator, next)) { return operator; } return null; }
[ "function", "getFirstNonSpacedToken", "(", "left", ",", "right", ",", "op", ")", "{", "const", "operator", "=", "sourceCode", ".", "getFirstTokenBetween", "(", "left", ",", "right", ",", "token", "=>", "token", ".", "value", "===", "op", ")", ";", "const", "prev", "=", "sourceCode", ".", "getTokenBefore", "(", "operator", ")", ";", "const", "next", "=", "sourceCode", ".", "getTokenAfter", "(", "operator", ")", ";", "if", "(", "!", "sourceCode", ".", "isSpaceBetweenTokens", "(", "prev", ",", "operator", ")", "||", "!", "sourceCode", ".", "isSpaceBetweenTokens", "(", "operator", ",", "next", ")", ")", "{", "return", "operator", ";", "}", "return", "null", ";", "}" ]
Returns the first token which violates the rule @param {ASTNode} left - The left node of the main node @param {ASTNode} right - The right node of the main node @param {string} op - The operator of the main node @returns {Object} The violator token or null @private
[ "Returns", "the", "first", "token", "which", "violates", "the", "rule" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-infix-ops.js#L50-L60
train
eslint/eslint
lib/rules/space-infix-ops.js
checkBinary
function checkBinary(node) { const leftNode = (node.left.typeAnnotation) ? node.left.typeAnnotation : node.left; const rightNode = node.right; // search for = in AssignmentPattern nodes const operator = node.operator || "="; const nonSpacedNode = getFirstNonSpacedToken(leftNode, rightNode, operator); if (nonSpacedNode) { if (!(int32Hint && sourceCode.getText(node).endsWith("|0"))) { report(node, nonSpacedNode); } } }
javascript
function checkBinary(node) { const leftNode = (node.left.typeAnnotation) ? node.left.typeAnnotation : node.left; const rightNode = node.right; // search for = in AssignmentPattern nodes const operator = node.operator || "="; const nonSpacedNode = getFirstNonSpacedToken(leftNode, rightNode, operator); if (nonSpacedNode) { if (!(int32Hint && sourceCode.getText(node).endsWith("|0"))) { report(node, nonSpacedNode); } } }
[ "function", "checkBinary", "(", "node", ")", "{", "const", "leftNode", "=", "(", "node", ".", "left", ".", "typeAnnotation", ")", "?", "node", ".", "left", ".", "typeAnnotation", ":", "node", ".", "left", ";", "const", "rightNode", "=", "node", ".", "right", ";", "const", "operator", "=", "node", ".", "operator", "||", "\"=\"", ";", "const", "nonSpacedNode", "=", "getFirstNonSpacedToken", "(", "leftNode", ",", "rightNode", ",", "operator", ")", ";", "if", "(", "nonSpacedNode", ")", "{", "if", "(", "!", "(", "int32Hint", "&&", "sourceCode", ".", "getText", "(", "node", ")", ".", "endsWith", "(", "\"|0\"", ")", ")", ")", "{", "report", "(", "node", ",", "nonSpacedNode", ")", ";", "}", "}", "}" ]
Check if the node is binary then report @param {ASTNode} node node to evaluate @returns {void} @private
[ "Check", "if", "the", "node", "is", "binary", "then", "report" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-infix-ops.js#L103-L117
train
eslint/eslint
lib/rules/space-infix-ops.js
checkConditional
function checkConditional(node) { const nonSpacedConsequesntNode = getFirstNonSpacedToken(node.test, node.consequent, "?"); const nonSpacedAlternateNode = getFirstNonSpacedToken(node.consequent, node.alternate, ":"); if (nonSpacedConsequesntNode) { report(node, nonSpacedConsequesntNode); } else if (nonSpacedAlternateNode) { report(node, nonSpacedAlternateNode); } }
javascript
function checkConditional(node) { const nonSpacedConsequesntNode = getFirstNonSpacedToken(node.test, node.consequent, "?"); const nonSpacedAlternateNode = getFirstNonSpacedToken(node.consequent, node.alternate, ":"); if (nonSpacedConsequesntNode) { report(node, nonSpacedConsequesntNode); } else if (nonSpacedAlternateNode) { report(node, nonSpacedAlternateNode); } }
[ "function", "checkConditional", "(", "node", ")", "{", "const", "nonSpacedConsequesntNode", "=", "getFirstNonSpacedToken", "(", "node", ".", "test", ",", "node", ".", "consequent", ",", "\"?\"", ")", ";", "const", "nonSpacedAlternateNode", "=", "getFirstNonSpacedToken", "(", "node", ".", "consequent", ",", "node", ".", "alternate", ",", "\":\"", ")", ";", "if", "(", "nonSpacedConsequesntNode", ")", "{", "report", "(", "node", ",", "nonSpacedConsequesntNode", ")", ";", "}", "else", "if", "(", "nonSpacedAlternateNode", ")", "{", "report", "(", "node", ",", "nonSpacedAlternateNode", ")", ";", "}", "}" ]
Check if the node is conditional @param {ASTNode} node node to evaluate @returns {void} @private
[ "Check", "if", "the", "node", "is", "conditional" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-infix-ops.js#L125-L134
train
eslint/eslint
lib/rules/space-infix-ops.js
checkVar
function checkVar(node) { const leftNode = (node.id.typeAnnotation) ? node.id.typeAnnotation : node.id; const rightNode = node.init; if (rightNode) { const nonSpacedNode = getFirstNonSpacedToken(leftNode, rightNode, "="); if (nonSpacedNode) { report(node, nonSpacedNode); } } }
javascript
function checkVar(node) { const leftNode = (node.id.typeAnnotation) ? node.id.typeAnnotation : node.id; const rightNode = node.init; if (rightNode) { const nonSpacedNode = getFirstNonSpacedToken(leftNode, rightNode, "="); if (nonSpacedNode) { report(node, nonSpacedNode); } } }
[ "function", "checkVar", "(", "node", ")", "{", "const", "leftNode", "=", "(", "node", ".", "id", ".", "typeAnnotation", ")", "?", "node", ".", "id", ".", "typeAnnotation", ":", "node", ".", "id", ";", "const", "rightNode", "=", "node", ".", "init", ";", "if", "(", "rightNode", ")", "{", "const", "nonSpacedNode", "=", "getFirstNonSpacedToken", "(", "leftNode", ",", "rightNode", ",", "\"=\"", ")", ";", "if", "(", "nonSpacedNode", ")", "{", "report", "(", "node", ",", "nonSpacedNode", ")", ";", "}", "}", "}" ]
Check if the node is a variable @param {ASTNode} node node to evaluate @returns {void} @private
[ "Check", "if", "the", "node", "is", "a", "variable" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-infix-ops.js#L142-L153
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
isInRange
function isInRange(node, reference) { const or = node.range; const ir = reference.identifier.range; return or[0] <= ir[0] && ir[1] <= or[1]; }
javascript
function isInRange(node, reference) { const or = node.range; const ir = reference.identifier.range; return or[0] <= ir[0] && ir[1] <= or[1]; }
[ "function", "isInRange", "(", "node", ",", "reference", ")", "{", "const", "or", "=", "node", ".", "range", ";", "const", "ir", "=", "reference", ".", "identifier", ".", "range", ";", "return", "or", "[", "0", "]", "<=", "ir", "[", "0", "]", "&&", "ir", "[", "1", "]", "<=", "or", "[", "1", "]", ";", "}" ]
Checks whether or not a given reference is inside of a given node. @param {ASTNode} node - A node to check. @param {eslint-scope.Reference} reference - A reference to check. @returns {boolean} `true` if the reference is inside of the node.
[ "Checks", "whether", "or", "not", "a", "given", "reference", "is", "inside", "of", "a", "given", "node", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L82-L87
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
getEncloseFunctionDeclaration
function getEncloseFunctionDeclaration(reference) { let node = reference.identifier; while (node) { if (node.type === "FunctionDeclaration") { return node.id ? node : null; } node = node.parent; } return null; }
javascript
function getEncloseFunctionDeclaration(reference) { let node = reference.identifier; while (node) { if (node.type === "FunctionDeclaration") { return node.id ? node : null; } node = node.parent; } return null; }
[ "function", "getEncloseFunctionDeclaration", "(", "reference", ")", "{", "let", "node", "=", "reference", ".", "identifier", ";", "while", "(", "node", ")", "{", "if", "(", "node", ".", "type", "===", "\"FunctionDeclaration\"", ")", "{", "return", "node", ".", "id", "?", "node", ":", "null", ";", "}", "node", "=", "node", ".", "parent", ";", "}", "return", "null", ";", "}" ]
Gets the function which encloses a given reference. This supports only FunctionDeclaration. @param {eslint-scope.Reference} reference - A reference to get. @returns {ASTNode|null} The function node or null.
[ "Gets", "the", "function", "which", "encloses", "a", "given", "reference", ".", "This", "supports", "only", "FunctionDeclaration", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L115-L127
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
updateModifiedFlag
function updateModifiedFlag(conditions, modifiers) { for (let i = 0; i < conditions.length; ++i) { const condition = conditions[i]; for (let j = 0; !condition.modified && j < modifiers.length; ++j) { const modifier = modifiers[j]; let funcNode, funcVar; /* * Besides checking for the condition being in the loop, we want to * check the function that this modifier is belonging to is called * in the loop. * FIXME: This should probably be extracted to a function. */ const inLoop = condition.isInLoop(modifier) || Boolean( (funcNode = getEncloseFunctionDeclaration(modifier)) && (funcVar = astUtils.getVariableByName(modifier.from.upper, funcNode.id.name)) && funcVar.references.some(condition.isInLoop) ); condition.modified = inLoop; } } }
javascript
function updateModifiedFlag(conditions, modifiers) { for (let i = 0; i < conditions.length; ++i) { const condition = conditions[i]; for (let j = 0; !condition.modified && j < modifiers.length; ++j) { const modifier = modifiers[j]; let funcNode, funcVar; /* * Besides checking for the condition being in the loop, we want to * check the function that this modifier is belonging to is called * in the loop. * FIXME: This should probably be extracted to a function. */ const inLoop = condition.isInLoop(modifier) || Boolean( (funcNode = getEncloseFunctionDeclaration(modifier)) && (funcVar = astUtils.getVariableByName(modifier.from.upper, funcNode.id.name)) && funcVar.references.some(condition.isInLoop) ); condition.modified = inLoop; } } }
[ "function", "updateModifiedFlag", "(", "conditions", ",", "modifiers", ")", "{", "for", "(", "let", "i", "=", "0", ";", "i", "<", "conditions", ".", "length", ";", "++", "i", ")", "{", "const", "condition", "=", "conditions", "[", "i", "]", ";", "for", "(", "let", "j", "=", "0", ";", "!", "condition", ".", "modified", "&&", "j", "<", "modifiers", ".", "length", ";", "++", "j", ")", "{", "const", "modifier", "=", "modifiers", "[", "j", "]", ";", "let", "funcNode", ",", "funcVar", ";", "const", "inLoop", "=", "condition", ".", "isInLoop", "(", "modifier", ")", "||", "Boolean", "(", "(", "funcNode", "=", "getEncloseFunctionDeclaration", "(", "modifier", ")", ")", "&&", "(", "funcVar", "=", "astUtils", ".", "getVariableByName", "(", "modifier", ".", "from", ".", "upper", ",", "funcNode", ".", "id", ".", "name", ")", ")", "&&", "funcVar", ".", "references", ".", "some", "(", "condition", ".", "isInLoop", ")", ")", ";", "condition", ".", "modified", "=", "inLoop", ";", "}", "}", "}" ]
Updates the "modified" flags of given loop conditions with given modifiers. @param {LoopConditionInfo[]} conditions - The loop conditions to be updated. @param {eslint-scope.Reference[]} modifiers - The references to update. @returns {void}
[ "Updates", "the", "modified", "flags", "of", "given", "loop", "conditions", "with", "given", "modifiers", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L136-L160
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
report
function report(condition) { const node = condition.reference.identifier; context.report({ node, message: "'{{name}}' is not modified in this loop.", data: node }); }
javascript
function report(condition) { const node = condition.reference.identifier; context.report({ node, message: "'{{name}}' is not modified in this loop.", data: node }); }
[ "function", "report", "(", "condition", ")", "{", "const", "node", "=", "condition", ".", "reference", ".", "identifier", ";", "context", ".", "report", "(", "{", "node", ",", "message", ":", "\"'{{name}}' is not modified in this loop.\"", ",", "data", ":", "node", "}", ")", ";", "}" ]
Reports a given condition info. @param {LoopConditionInfo} condition - A loop condition info to report. @returns {void}
[ "Reports", "a", "given", "condition", "info", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L190-L198
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
registerConditionsToGroup
function registerConditionsToGroup(conditions) { for (let i = 0; i < conditions.length; ++i) { const condition = conditions[i]; if (condition.group) { let group = groupMap.get(condition.group); if (!group) { group = []; groupMap.set(condition.group, group); } group.push(condition); } } }
javascript
function registerConditionsToGroup(conditions) { for (let i = 0; i < conditions.length; ++i) { const condition = conditions[i]; if (condition.group) { let group = groupMap.get(condition.group); if (!group) { group = []; groupMap.set(condition.group, group); } group.push(condition); } } }
[ "function", "registerConditionsToGroup", "(", "conditions", ")", "{", "for", "(", "let", "i", "=", "0", ";", "i", "<", "conditions", ".", "length", ";", "++", "i", ")", "{", "const", "condition", "=", "conditions", "[", "i", "]", ";", "if", "(", "condition", ".", "group", ")", "{", "let", "group", "=", "groupMap", ".", "get", "(", "condition", ".", "group", ")", ";", "if", "(", "!", "group", ")", "{", "group", "=", "[", "]", ";", "groupMap", ".", "set", "(", "condition", ".", "group", ",", "group", ")", ";", "}", "group", ".", "push", "(", "condition", ")", ";", "}", "}", "}" ]
Registers given conditions to the group the condition belongs to. @param {LoopConditionInfo[]} conditions - A loop condition info to register. @returns {void}
[ "Registers", "given", "conditions", "to", "the", "group", "the", "condition", "belongs", "to", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L207-L221
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
hasDynamicExpressions
function hasDynamicExpressions(root) { let retv = false; Traverser.traverse(root, { visitorKeys: sourceCode.visitorKeys, enter(node) { if (DYNAMIC_PATTERN.test(node.type)) { retv = true; this.break(); } else if (SKIP_PATTERN.test(node.type)) { this.skip(); } } }); return retv; }
javascript
function hasDynamicExpressions(root) { let retv = false; Traverser.traverse(root, { visitorKeys: sourceCode.visitorKeys, enter(node) { if (DYNAMIC_PATTERN.test(node.type)) { retv = true; this.break(); } else if (SKIP_PATTERN.test(node.type)) { this.skip(); } } }); return retv; }
[ "function", "hasDynamicExpressions", "(", "root", ")", "{", "let", "retv", "=", "false", ";", "Traverser", ".", "traverse", "(", "root", ",", "{", "visitorKeys", ":", "sourceCode", ".", "visitorKeys", ",", "enter", "(", "node", ")", "{", "if", "(", "DYNAMIC_PATTERN", ".", "test", "(", "node", ".", "type", ")", ")", "{", "retv", "=", "true", ";", "this", ".", "break", "(", ")", ";", "}", "else", "if", "(", "SKIP_PATTERN", ".", "test", "(", "node", ".", "type", ")", ")", "{", "this", ".", "skip", "(", ")", ";", "}", "}", "}", ")", ";", "return", "retv", ";", "}" ]
Checks whether or not a given group node has any dynamic elements. @param {ASTNode} root - A node to check. This node is one of BinaryExpression or ConditionalExpression. @returns {boolean} `true` if the node is dynamic.
[ "Checks", "whether", "or", "not", "a", "given", "group", "node", "has", "any", "dynamic", "elements", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L242-L258
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
toLoopCondition
function toLoopCondition(reference) { if (reference.init) { return null; } let group = null; let child = reference.identifier; let node = child.parent; while (node) { if (SENTINEL_PATTERN.test(node.type)) { if (LOOP_PATTERN.test(node.type) && node.test === child) { // This reference is inside of a loop condition. return { reference, group, isInLoop: isInLoop[node.type].bind(null, node), modified: false }; } // This reference is outside of a loop condition. break; } /* * If it's inside of a group, OK if either operand is modified. * So stores the group this reference belongs to. */ if (GROUP_PATTERN.test(node.type)) { // If this expression is dynamic, no need to check. if (hasDynamicExpressions(node)) { break; } else { group = node; } } child = node; node = node.parent; } return null; }
javascript
function toLoopCondition(reference) { if (reference.init) { return null; } let group = null; let child = reference.identifier; let node = child.parent; while (node) { if (SENTINEL_PATTERN.test(node.type)) { if (LOOP_PATTERN.test(node.type) && node.test === child) { // This reference is inside of a loop condition. return { reference, group, isInLoop: isInLoop[node.type].bind(null, node), modified: false }; } // This reference is outside of a loop condition. break; } /* * If it's inside of a group, OK if either operand is modified. * So stores the group this reference belongs to. */ if (GROUP_PATTERN.test(node.type)) { // If this expression is dynamic, no need to check. if (hasDynamicExpressions(node)) { break; } else { group = node; } } child = node; node = node.parent; } return null; }
[ "function", "toLoopCondition", "(", "reference", ")", "{", "if", "(", "reference", ".", "init", ")", "{", "return", "null", ";", "}", "let", "group", "=", "null", ";", "let", "child", "=", "reference", ".", "identifier", ";", "let", "node", "=", "child", ".", "parent", ";", "while", "(", "node", ")", "{", "if", "(", "SENTINEL_PATTERN", ".", "test", "(", "node", ".", "type", ")", ")", "{", "if", "(", "LOOP_PATTERN", ".", "test", "(", "node", ".", "type", ")", "&&", "node", ".", "test", "===", "child", ")", "{", "return", "{", "reference", ",", "group", ",", "isInLoop", ":", "isInLoop", "[", "node", ".", "type", "]", ".", "bind", "(", "null", ",", "node", ")", ",", "modified", ":", "false", "}", ";", "}", "break", ";", "}", "if", "(", "GROUP_PATTERN", ".", "test", "(", "node", ".", "type", ")", ")", "{", "if", "(", "hasDynamicExpressions", "(", "node", ")", ")", "{", "break", ";", "}", "else", "{", "group", "=", "node", ";", "}", "}", "child", "=", "node", ";", "node", "=", "node", ".", "parent", ";", "}", "return", "null", ";", "}" ]
Creates the loop condition information from a given reference. @param {eslint-scope.Reference} reference - A reference to create. @returns {LoopConditionInfo|null} Created loop condition info, or null.
[ "Creates", "the", "loop", "condition", "information", "from", "a", "given", "reference", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L266-L311
train
eslint/eslint
lib/rules/no-unmodified-loop-condition.js
checkReferences
function checkReferences(variable) { // Gets references that exist in loop conditions. const conditions = variable .references .map(toLoopCondition) .filter(Boolean); if (conditions.length === 0) { return; } // Registers the conditions to belonging groups. registerConditionsToGroup(conditions); // Check the conditions are modified. const modifiers = variable.references.filter(isWriteReference); if (modifiers.length > 0) { updateModifiedFlag(conditions, modifiers); } /* * Reports the conditions which are not belonging to groups. * Others will be reported after all variables are done. */ conditions .filter(isUnmodifiedAndNotBelongToGroup) .forEach(report); }
javascript
function checkReferences(variable) { // Gets references that exist in loop conditions. const conditions = variable .references .map(toLoopCondition) .filter(Boolean); if (conditions.length === 0) { return; } // Registers the conditions to belonging groups. registerConditionsToGroup(conditions); // Check the conditions are modified. const modifiers = variable.references.filter(isWriteReference); if (modifiers.length > 0) { updateModifiedFlag(conditions, modifiers); } /* * Reports the conditions which are not belonging to groups. * Others will be reported after all variables are done. */ conditions .filter(isUnmodifiedAndNotBelongToGroup) .forEach(report); }
[ "function", "checkReferences", "(", "variable", ")", "{", "const", "conditions", "=", "variable", ".", "references", ".", "map", "(", "toLoopCondition", ")", ".", "filter", "(", "Boolean", ")", ";", "if", "(", "conditions", ".", "length", "===", "0", ")", "{", "return", ";", "}", "registerConditionsToGroup", "(", "conditions", ")", ";", "const", "modifiers", "=", "variable", ".", "references", ".", "filter", "(", "isWriteReference", ")", ";", "if", "(", "modifiers", ".", "length", ">", "0", ")", "{", "updateModifiedFlag", "(", "conditions", ",", "modifiers", ")", ";", "}", "conditions", ".", "filter", "(", "isUnmodifiedAndNotBelongToGroup", ")", ".", "forEach", "(", "report", ")", ";", "}" ]
Finds unmodified references which are inside of a loop condition. Then reports the references which are outside of groups. @param {eslint-scope.Variable} variable - A variable to report. @returns {void}
[ "Finds", "unmodified", "references", "which", "are", "inside", "of", "a", "loop", "condition", ".", "Then", "reports", "the", "references", "which", "are", "outside", "of", "groups", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-unmodified-loop-condition.js#L320-L349
train
eslint/eslint
lib/util/timing.js
time
function time(key, fn) { if (typeof data[key] === "undefined") { data[key] = 0; } return function(...args) { let t = process.hrtime(); fn(...args); t = process.hrtime(t); data[key] += t[0] * 1e3 + t[1] / 1e6; }; }
javascript
function time(key, fn) { if (typeof data[key] === "undefined") { data[key] = 0; } return function(...args) { let t = process.hrtime(); fn(...args); t = process.hrtime(t); data[key] += t[0] * 1e3 + t[1] / 1e6; }; }
[ "function", "time", "(", "key", ",", "fn", ")", "{", "if", "(", "typeof", "data", "[", "key", "]", "===", "\"undefined\"", ")", "{", "data", "[", "key", "]", "=", "0", ";", "}", "return", "function", "(", "...", "args", ")", "{", "let", "t", "=", "process", ".", "hrtime", "(", ")", ";", "fn", "(", "...", "args", ")", ";", "t", "=", "process", ".", "hrtime", "(", "t", ")", ";", "data", "[", "key", "]", "+=", "t", "[", "0", "]", "*", "1e3", "+", "t", "[", "1", "]", "/", "1e6", ";", "}", ";", "}" ]
Time the run @param {*} key key from the data object @param {Function} fn function to be called @returns {Function} function to be executed @private
[ "Time", "the", "run" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/util/timing.js#L114-L126
train
eslint/eslint
lib/rules/func-names.js
getConfigForNode
function getConfigForNode(node) { if ( node.generator && context.options.length > 1 && context.options[1].generators ) { return context.options[1].generators; } return context.options[0] || "always"; }
javascript
function getConfigForNode(node) { if ( node.generator && context.options.length > 1 && context.options[1].generators ) { return context.options[1].generators; } return context.options[0] || "always"; }
[ "function", "getConfigForNode", "(", "node", ")", "{", "if", "(", "node", ".", "generator", "&&", "context", ".", "options", ".", "length", ">", "1", "&&", "context", ".", "options", "[", "1", "]", ".", "generators", ")", "{", "return", "context", ".", "options", "[", "1", "]", ".", "generators", ";", "}", "return", "context", ".", "options", "[", "0", "]", "||", "\"always\"", ";", "}" ]
Returns the config option for the given node. @param {ASTNode} node - A node to get the config for. @returns {string} The config option.
[ "Returns", "the", "config", "option", "for", "the", "given", "node", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/func-names.js#L77-L87
train
eslint/eslint
lib/rules/func-names.js
isObjectOrClassMethod
function isObjectOrClassMethod(node) { const parent = node.parent; return (parent.type === "MethodDefinition" || ( parent.type === "Property" && ( parent.method || parent.kind === "get" || parent.kind === "set" ) )); }
javascript
function isObjectOrClassMethod(node) { const parent = node.parent; return (parent.type === "MethodDefinition" || ( parent.type === "Property" && ( parent.method || parent.kind === "get" || parent.kind === "set" ) )); }
[ "function", "isObjectOrClassMethod", "(", "node", ")", "{", "const", "parent", "=", "node", ".", "parent", ";", "return", "(", "parent", ".", "type", "===", "\"MethodDefinition\"", "||", "(", "parent", ".", "type", "===", "\"Property\"", "&&", "(", "parent", ".", "method", "||", "parent", ".", "kind", "===", "\"get\"", "||", "parent", ".", "kind", "===", "\"set\"", ")", ")", ")", ";", "}" ]
Determines whether the current FunctionExpression node is a get, set, or shorthand method in an object literal or a class. @param {ASTNode} node - A node to check. @returns {boolean} True if the node is a get, set, or shorthand method.
[ "Determines", "whether", "the", "current", "FunctionExpression", "node", "is", "a", "get", "set", "or", "shorthand", "method", "in", "an", "object", "literal", "or", "a", "class", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/func-names.js#L95-L105
train
eslint/eslint
lib/rules/func-names.js
hasInferredName
function hasInferredName(node) { const parent = node.parent; return isObjectOrClassMethod(node) || (parent.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.init === node) || (parent.type === "Property" && parent.value === node) || (parent.type === "AssignmentExpression" && parent.left.type === "Identifier" && parent.right === node) || (parent.type === "ExportDefaultDeclaration" && parent.declaration === node) || (parent.type === "AssignmentPattern" && parent.right === node); }
javascript
function hasInferredName(node) { const parent = node.parent; return isObjectOrClassMethod(node) || (parent.type === "VariableDeclarator" && parent.id.type === "Identifier" && parent.init === node) || (parent.type === "Property" && parent.value === node) || (parent.type === "AssignmentExpression" && parent.left.type === "Identifier" && parent.right === node) || (parent.type === "ExportDefaultDeclaration" && parent.declaration === node) || (parent.type === "AssignmentPattern" && parent.right === node); }
[ "function", "hasInferredName", "(", "node", ")", "{", "const", "parent", "=", "node", ".", "parent", ";", "return", "isObjectOrClassMethod", "(", "node", ")", "||", "(", "parent", ".", "type", "===", "\"VariableDeclarator\"", "&&", "parent", ".", "id", ".", "type", "===", "\"Identifier\"", "&&", "parent", ".", "init", "===", "node", ")", "||", "(", "parent", ".", "type", "===", "\"Property\"", "&&", "parent", ".", "value", "===", "node", ")", "||", "(", "parent", ".", "type", "===", "\"AssignmentExpression\"", "&&", "parent", ".", "left", ".", "type", "===", "\"Identifier\"", "&&", "parent", ".", "right", "===", "node", ")", "||", "(", "parent", ".", "type", "===", "\"ExportDefaultDeclaration\"", "&&", "parent", ".", "declaration", "===", "node", ")", "||", "(", "parent", ".", "type", "===", "\"AssignmentPattern\"", "&&", "parent", ".", "right", "===", "node", ")", ";", "}" ]
Determines whether the current FunctionExpression node has a name that would be inferred from context in a conforming ES6 environment. @param {ASTNode} node - A node to check. @returns {boolean} True if the node would have a name assigned automatically.
[ "Determines", "whether", "the", "current", "FunctionExpression", "node", "has", "a", "name", "that", "would", "be", "inferred", "from", "context", "in", "a", "conforming", "ES6", "environment", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/func-names.js#L113-L122
train
eslint/eslint
lib/rules/func-names.js
reportUnexpectedUnnamedFunction
function reportUnexpectedUnnamedFunction(node) { context.report({ node, messageId: "unnamed", data: { name: astUtils.getFunctionNameWithKind(node) } }); }
javascript
function reportUnexpectedUnnamedFunction(node) { context.report({ node, messageId: "unnamed", data: { name: astUtils.getFunctionNameWithKind(node) } }); }
[ "function", "reportUnexpectedUnnamedFunction", "(", "node", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"unnamed\"", ",", "data", ":", "{", "name", ":", "astUtils", ".", "getFunctionNameWithKind", "(", "node", ")", "}", "}", ")", ";", "}" ]
Reports that an unnamed function should be named @param {ASTNode} node - The node to report in the event of an error. @returns {void}
[ "Reports", "that", "an", "unnamed", "function", "should", "be", "named" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/func-names.js#L129-L135
train
eslint/eslint
Makefile.js
generateBlogPost
function generateBlogPost(releaseInfo, prereleaseMajorVersion) { const ruleList = ls("lib/rules") // Strip the .js extension .map(ruleFileName => ruleFileName.replace(/\.js$/u, "")) /* * Sort by length descending. This ensures that rule names which are substrings of other rule names are not * matched incorrectly. For example, the string "no-undefined" should get matched with the `no-undefined` rule, * instead of getting matched with the `no-undef` rule followed by the string "ined". */ .sort((ruleA, ruleB) => ruleB.length - ruleA.length); const renderContext = Object.assign({ prereleaseMajorVersion, ruleList }, releaseInfo); const output = ejs.render(cat("./templates/blogpost.md.ejs"), renderContext), now = new Date(), month = now.getMonth() + 1, day = now.getDate(), filename = `../eslint.github.io/_posts/${now.getFullYear()}-${ month < 10 ? `0${month}` : month}-${ day < 10 ? `0${day}` : day}-eslint-v${ releaseInfo.version}-released.md`; output.to(filename); }
javascript
function generateBlogPost(releaseInfo, prereleaseMajorVersion) { const ruleList = ls("lib/rules") // Strip the .js extension .map(ruleFileName => ruleFileName.replace(/\.js$/u, "")) /* * Sort by length descending. This ensures that rule names which are substrings of other rule names are not * matched incorrectly. For example, the string "no-undefined" should get matched with the `no-undefined` rule, * instead of getting matched with the `no-undef` rule followed by the string "ined". */ .sort((ruleA, ruleB) => ruleB.length - ruleA.length); const renderContext = Object.assign({ prereleaseMajorVersion, ruleList }, releaseInfo); const output = ejs.render(cat("./templates/blogpost.md.ejs"), renderContext), now = new Date(), month = now.getMonth() + 1, day = now.getDate(), filename = `../eslint.github.io/_posts/${now.getFullYear()}-${ month < 10 ? `0${month}` : month}-${ day < 10 ? `0${day}` : day}-eslint-v${ releaseInfo.version}-released.md`; output.to(filename); }
[ "function", "generateBlogPost", "(", "releaseInfo", ",", "prereleaseMajorVersion", ")", "{", "const", "ruleList", "=", "ls", "(", "\"lib/rules\"", ")", ".", "map", "(", "ruleFileName", "=>", "ruleFileName", ".", "replace", "(", "/", "\\.js$", "/", "u", ",", "\"\"", ")", ")", ".", "sort", "(", "(", "ruleA", ",", "ruleB", ")", "=>", "ruleB", ".", "length", "-", "ruleA", ".", "length", ")", ";", "const", "renderContext", "=", "Object", ".", "assign", "(", "{", "prereleaseMajorVersion", ",", "ruleList", "}", ",", "releaseInfo", ")", ";", "const", "output", "=", "ejs", ".", "render", "(", "cat", "(", "\"./templates/blogpost.md.ejs\"", ")", ",", "renderContext", ")", ",", "now", "=", "new", "Date", "(", ")", ",", "month", "=", "now", ".", "getMonth", "(", ")", "+", "1", ",", "day", "=", "now", ".", "getDate", "(", ")", ",", "filename", "=", "`", "${", "now", ".", "getFullYear", "(", ")", "}", "${", "month", "<", "10", "?", "`", "${", "month", "}", "`", ":", "month", "}", "${", "day", "<", "10", "?", "`", "${", "day", "}", "`", ":", "day", "}", "${", "releaseInfo", ".", "version", "}", "`", ";", "output", ".", "to", "(", "filename", ")", ";", "}" ]
Generates a release blog post for eslint.org @param {Object} releaseInfo The release metadata. @param {string} [prereleaseMajorVersion] If this is a prerelease, the next major version after this prerelease @returns {void} @private
[ "Generates", "a", "release", "blog", "post", "for", "eslint", ".", "org" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L121-L146
train
eslint/eslint
Makefile.js
generateFormatterExamples
function generateFormatterExamples(formatterInfo, prereleaseVersion) { const output = ejs.render(cat("./templates/formatter-examples.md.ejs"), formatterInfo); let filename = "../eslint.github.io/docs/user-guide/formatters/index.md", htmlFilename = "../eslint.github.io/docs/user-guide/formatters/html-formatter-example.html"; if (prereleaseVersion) { filename = filename.replace("/docs", `/docs/${prereleaseVersion}`); htmlFilename = htmlFilename.replace("/docs", `/docs/${prereleaseVersion}`); if (!test("-d", path.dirname(filename))) { mkdir(path.dirname(filename)); } } output.to(filename); formatterInfo.formatterResults.html.result.to(htmlFilename); }
javascript
function generateFormatterExamples(formatterInfo, prereleaseVersion) { const output = ejs.render(cat("./templates/formatter-examples.md.ejs"), formatterInfo); let filename = "../eslint.github.io/docs/user-guide/formatters/index.md", htmlFilename = "../eslint.github.io/docs/user-guide/formatters/html-formatter-example.html"; if (prereleaseVersion) { filename = filename.replace("/docs", `/docs/${prereleaseVersion}`); htmlFilename = htmlFilename.replace("/docs", `/docs/${prereleaseVersion}`); if (!test("-d", path.dirname(filename))) { mkdir(path.dirname(filename)); } } output.to(filename); formatterInfo.formatterResults.html.result.to(htmlFilename); }
[ "function", "generateFormatterExamples", "(", "formatterInfo", ",", "prereleaseVersion", ")", "{", "const", "output", "=", "ejs", ".", "render", "(", "cat", "(", "\"./templates/formatter-examples.md.ejs\"", ")", ",", "formatterInfo", ")", ";", "let", "filename", "=", "\"../eslint.github.io/docs/user-guide/formatters/index.md\"", ",", "htmlFilename", "=", "\"../eslint.github.io/docs/user-guide/formatters/html-formatter-example.html\"", ";", "if", "(", "prereleaseVersion", ")", "{", "filename", "=", "filename", ".", "replace", "(", "\"/docs\"", ",", "`", "${", "prereleaseVersion", "}", "`", ")", ";", "htmlFilename", "=", "htmlFilename", ".", "replace", "(", "\"/docs\"", ",", "`", "${", "prereleaseVersion", "}", "`", ")", ";", "if", "(", "!", "test", "(", "\"-d\"", ",", "path", ".", "dirname", "(", "filename", ")", ")", ")", "{", "mkdir", "(", "path", ".", "dirname", "(", "filename", ")", ")", ";", "}", "}", "output", ".", "to", "(", "filename", ")", ";", "formatterInfo", ".", "formatterResults", ".", "html", ".", "result", ".", "to", "(", "htmlFilename", ")", ";", "}" ]
Generates a doc page with formatter result examples @param {Object} formatterInfo Linting results from each formatter @param {string} [prereleaseVersion] The version used for a prerelease. This changes where the output is stored. @returns {void}
[ "Generates", "a", "doc", "page", "with", "formatter", "result", "examples" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L155-L170
train
eslint/eslint
Makefile.js
generateRuleIndexPage
function generateRuleIndexPage(basedir) { const outputFile = "../eslint.github.io/_data/rules.yml", categoryList = "conf/category-list.json", categoriesData = JSON.parse(cat(path.resolve(categoryList))); find(path.join(basedir, "/lib/rules/")).filter(fileType("js")) .map(filename => [filename, path.basename(filename, ".js")]) .sort((a, b) => a[1].localeCompare(b[1])) .forEach(pair => { const filename = pair[0]; const basename = pair[1]; const rule = require(filename); if (rule.meta.deprecated) { categoriesData.deprecated.rules.push({ name: basename, replacedBy: rule.meta.replacedBy || [] }); } else { const output = { name: basename, description: rule.meta.docs.description, recommended: rule.meta.docs.recommended || false, fixable: !!rule.meta.fixable }, category = lodash.find(categoriesData.categories, { name: rule.meta.docs.category }); if (!category.rules) { category.rules = []; } category.rules.push(output); } }); const output = yaml.safeDump(categoriesData, { sortKeys: true }); output.to(outputFile); }
javascript
function generateRuleIndexPage(basedir) { const outputFile = "../eslint.github.io/_data/rules.yml", categoryList = "conf/category-list.json", categoriesData = JSON.parse(cat(path.resolve(categoryList))); find(path.join(basedir, "/lib/rules/")).filter(fileType("js")) .map(filename => [filename, path.basename(filename, ".js")]) .sort((a, b) => a[1].localeCompare(b[1])) .forEach(pair => { const filename = pair[0]; const basename = pair[1]; const rule = require(filename); if (rule.meta.deprecated) { categoriesData.deprecated.rules.push({ name: basename, replacedBy: rule.meta.replacedBy || [] }); } else { const output = { name: basename, description: rule.meta.docs.description, recommended: rule.meta.docs.recommended || false, fixable: !!rule.meta.fixable }, category = lodash.find(categoriesData.categories, { name: rule.meta.docs.category }); if (!category.rules) { category.rules = []; } category.rules.push(output); } }); const output = yaml.safeDump(categoriesData, { sortKeys: true }); output.to(outputFile); }
[ "function", "generateRuleIndexPage", "(", "basedir", ")", "{", "const", "outputFile", "=", "\"../eslint.github.io/_data/rules.yml\"", ",", "categoryList", "=", "\"conf/category-list.json\"", ",", "categoriesData", "=", "JSON", ".", "parse", "(", "cat", "(", "path", ".", "resolve", "(", "categoryList", ")", ")", ")", ";", "find", "(", "path", ".", "join", "(", "basedir", ",", "\"/lib/rules/\"", ")", ")", ".", "filter", "(", "fileType", "(", "\"js\"", ")", ")", ".", "map", "(", "filename", "=>", "[", "filename", ",", "path", ".", "basename", "(", "filename", ",", "\".js\"", ")", "]", ")", ".", "sort", "(", "(", "a", ",", "b", ")", "=>", "a", "[", "1", "]", ".", "localeCompare", "(", "b", "[", "1", "]", ")", ")", ".", "forEach", "(", "pair", "=>", "{", "const", "filename", "=", "pair", "[", "0", "]", ";", "const", "basename", "=", "pair", "[", "1", "]", ";", "const", "rule", "=", "require", "(", "filename", ")", ";", "if", "(", "rule", ".", "meta", ".", "deprecated", ")", "{", "categoriesData", ".", "deprecated", ".", "rules", ".", "push", "(", "{", "name", ":", "basename", ",", "replacedBy", ":", "rule", ".", "meta", ".", "replacedBy", "||", "[", "]", "}", ")", ";", "}", "else", "{", "const", "output", "=", "{", "name", ":", "basename", ",", "description", ":", "rule", ".", "meta", ".", "docs", ".", "description", ",", "recommended", ":", "rule", ".", "meta", ".", "docs", ".", "recommended", "||", "false", ",", "fixable", ":", "!", "!", "rule", ".", "meta", ".", "fixable", "}", ",", "category", "=", "lodash", ".", "find", "(", "categoriesData", ".", "categories", ",", "{", "name", ":", "rule", ".", "meta", ".", "docs", ".", "category", "}", ")", ";", "if", "(", "!", "category", ".", "rules", ")", "{", "category", ".", "rules", "=", "[", "]", ";", "}", "category", ".", "rules", ".", "push", "(", "output", ")", ";", "}", "}", ")", ";", "const", "output", "=", "yaml", ".", "safeDump", "(", "categoriesData", ",", "{", "sortKeys", ":", "true", "}", ")", ";", "output", ".", "to", "(", "outputFile", ")", ";", "}" ]
Generate a doc page that lists all of the rules and links to them @param {string} basedir The directory in which to look for code. @returns {void}
[ "Generate", "a", "doc", "page", "that", "lists", "all", "of", "the", "rules", "and", "links", "to", "them" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L177-L215
train
eslint/eslint
Makefile.js
getFirstCommitOfFile
function getFirstCommitOfFile(filePath) { let commits = execSilent(`git rev-list HEAD -- ${filePath}`); commits = splitCommandResultToLines(commits); return commits[commits.length - 1].trim(); }
javascript
function getFirstCommitOfFile(filePath) { let commits = execSilent(`git rev-list HEAD -- ${filePath}`); commits = splitCommandResultToLines(commits); return commits[commits.length - 1].trim(); }
[ "function", "getFirstCommitOfFile", "(", "filePath", ")", "{", "let", "commits", "=", "execSilent", "(", "`", "${", "filePath", "}", "`", ")", ";", "commits", "=", "splitCommandResultToLines", "(", "commits", ")", ";", "return", "commits", "[", "commits", ".", "length", "-", "1", "]", ".", "trim", "(", ")", ";", "}" ]
Gets the first commit sha of the given file. @param {string} filePath The file path which should be checked. @returns {string} The commit sha.
[ "Gets", "the", "first", "commit", "sha", "of", "the", "given", "file", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L328-L333
train
eslint/eslint
Makefile.js
getFirstVersionOfFile
function getFirstVersionOfFile(filePath) { const firstCommit = getFirstCommitOfFile(filePath); let tags = execSilent(`git tag --contains ${firstCommit}`); tags = splitCommandResultToLines(tags); return tags.reduce((list, version) => { const validatedVersion = semver.valid(version.trim()); if (validatedVersion) { list.push(validatedVersion); } return list; }, []).sort(semver.compare)[0]; }
javascript
function getFirstVersionOfFile(filePath) { const firstCommit = getFirstCommitOfFile(filePath); let tags = execSilent(`git tag --contains ${firstCommit}`); tags = splitCommandResultToLines(tags); return tags.reduce((list, version) => { const validatedVersion = semver.valid(version.trim()); if (validatedVersion) { list.push(validatedVersion); } return list; }, []).sort(semver.compare)[0]; }
[ "function", "getFirstVersionOfFile", "(", "filePath", ")", "{", "const", "firstCommit", "=", "getFirstCommitOfFile", "(", "filePath", ")", ";", "let", "tags", "=", "execSilent", "(", "`", "${", "firstCommit", "}", "`", ")", ";", "tags", "=", "splitCommandResultToLines", "(", "tags", ")", ";", "return", "tags", ".", "reduce", "(", "(", "list", ",", "version", ")", "=>", "{", "const", "validatedVersion", "=", "semver", ".", "valid", "(", "version", ".", "trim", "(", ")", ")", ";", "if", "(", "validatedVersion", ")", "{", "list", ".", "push", "(", "validatedVersion", ")", ";", "}", "return", "list", ";", "}", ",", "[", "]", ")", ".", "sort", "(", "semver", ".", "compare", ")", "[", "0", "]", ";", "}" ]
Gets the tag name where a given file was introduced first. @param {string} filePath The file path to check. @returns {string} The tag name.
[ "Gets", "the", "tag", "name", "where", "a", "given", "file", "was", "introduced", "first", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L340-L353
train
eslint/eslint
Makefile.js
getFirstVersionOfDeletion
function getFirstVersionOfDeletion(filePath) { const deletionCommit = getCommitDeletingFile(filePath), tags = execSilent(`git tag --contains ${deletionCommit}`); return splitCommandResultToLines(tags) .map(version => semver.valid(version.trim())) .filter(version => version) .sort(semver.compare)[0]; }
javascript
function getFirstVersionOfDeletion(filePath) { const deletionCommit = getCommitDeletingFile(filePath), tags = execSilent(`git tag --contains ${deletionCommit}`); return splitCommandResultToLines(tags) .map(version => semver.valid(version.trim())) .filter(version => version) .sort(semver.compare)[0]; }
[ "function", "getFirstVersionOfDeletion", "(", "filePath", ")", "{", "const", "deletionCommit", "=", "getCommitDeletingFile", "(", "filePath", ")", ",", "tags", "=", "execSilent", "(", "`", "${", "deletionCommit", "}", "`", ")", ";", "return", "splitCommandResultToLines", "(", "tags", ")", ".", "map", "(", "version", "=>", "semver", ".", "valid", "(", "version", ".", "trim", "(", ")", ")", ")", ".", "filter", "(", "version", "=>", "version", ")", ".", "sort", "(", "semver", ".", "compare", ")", "[", "0", "]", ";", "}" ]
Gets the first version number where a given file is no longer present. @param {string} filePath The path to the deleted file. @returns {string} The version number.
[ "Gets", "the", "first", "version", "number", "where", "a", "given", "file", "is", "no", "longer", "present", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L371-L379
train
eslint/eslint
Makefile.js
lintMarkdown
function lintMarkdown(files) { const config = yaml.safeLoad(fs.readFileSync(path.join(__dirname, "./.markdownlint.yml"), "utf8")), result = markdownlint.sync({ files, config, resultVersion: 1 }), resultString = result.toString(), returnCode = resultString ? 1 : 0; if (resultString) { console.error(resultString); } return { code: returnCode }; }
javascript
function lintMarkdown(files) { const config = yaml.safeLoad(fs.readFileSync(path.join(__dirname, "./.markdownlint.yml"), "utf8")), result = markdownlint.sync({ files, config, resultVersion: 1 }), resultString = result.toString(), returnCode = resultString ? 1 : 0; if (resultString) { console.error(resultString); } return { code: returnCode }; }
[ "function", "lintMarkdown", "(", "files", ")", "{", "const", "config", "=", "yaml", ".", "safeLoad", "(", "fs", ".", "readFileSync", "(", "path", ".", "join", "(", "__dirname", ",", "\"./.markdownlint.yml\"", ")", ",", "\"utf8\"", ")", ")", ",", "result", "=", "markdownlint", ".", "sync", "(", "{", "files", ",", "config", ",", "resultVersion", ":", "1", "}", ")", ",", "resultString", "=", "result", ".", "toString", "(", ")", ",", "returnCode", "=", "resultString", "?", "1", ":", "0", ";", "if", "(", "resultString", ")", "{", "console", ".", "error", "(", "resultString", ")", ";", "}", "return", "{", "code", ":", "returnCode", "}", ";", "}" ]
Lints Markdown files. @param {Array} files Array of file names to lint. @returns {Object} exec-style exit code object. @private
[ "Lints", "Markdown", "files", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L387-L401
train
eslint/eslint
Makefile.js
getFormatterResults
function getFormatterResults() { const stripAnsi = require("strip-ansi"); const formatterFiles = fs.readdirSync("./lib/formatters/"), rules = { "no-else-return": "warn", indent: ["warn", 4], "space-unary-ops": "error", semi: ["warn", "always"], "consistent-return": "error" }, cli = new CLIEngine({ useEslintrc: false, baseConfig: { extends: "eslint:recommended" }, rules }), codeString = [ "function addOne(i) {", " if (i != NaN) {", " return i ++", " } else {", " return", " }", "};" ].join("\n"), rawMessages = cli.executeOnText(codeString, "fullOfProblems.js", true), rulesMap = cli.getRules(), rulesMeta = {}; Object.keys(rules).forEach(ruleId => { rulesMeta[ruleId] = rulesMap.get(ruleId).meta; }); return formatterFiles.reduce((data, filename) => { const fileExt = path.extname(filename), name = path.basename(filename, fileExt); if (fileExt === ".js") { const formattedOutput = cli.getFormatter(name)( rawMessages.results, { rulesMeta } ); data.formatterResults[name] = { result: stripAnsi(formattedOutput) }; } return data; }, { formatterResults: {} }); }
javascript
function getFormatterResults() { const stripAnsi = require("strip-ansi"); const formatterFiles = fs.readdirSync("./lib/formatters/"), rules = { "no-else-return": "warn", indent: ["warn", 4], "space-unary-ops": "error", semi: ["warn", "always"], "consistent-return": "error" }, cli = new CLIEngine({ useEslintrc: false, baseConfig: { extends: "eslint:recommended" }, rules }), codeString = [ "function addOne(i) {", " if (i != NaN) {", " return i ++", " } else {", " return", " }", "};" ].join("\n"), rawMessages = cli.executeOnText(codeString, "fullOfProblems.js", true), rulesMap = cli.getRules(), rulesMeta = {}; Object.keys(rules).forEach(ruleId => { rulesMeta[ruleId] = rulesMap.get(ruleId).meta; }); return formatterFiles.reduce((data, filename) => { const fileExt = path.extname(filename), name = path.basename(filename, fileExt); if (fileExt === ".js") { const formattedOutput = cli.getFormatter(name)( rawMessages.results, { rulesMeta } ); data.formatterResults[name] = { result: stripAnsi(formattedOutput) }; } return data; }, { formatterResults: {} }); }
[ "function", "getFormatterResults", "(", ")", "{", "const", "stripAnsi", "=", "require", "(", "\"strip-ansi\"", ")", ";", "const", "formatterFiles", "=", "fs", ".", "readdirSync", "(", "\"./lib/formatters/\"", ")", ",", "rules", "=", "{", "\"no-else-return\"", ":", "\"warn\"", ",", "indent", ":", "[", "\"warn\"", ",", "4", "]", ",", "\"space-unary-ops\"", ":", "\"error\"", ",", "semi", ":", "[", "\"warn\"", ",", "\"always\"", "]", ",", "\"consistent-return\"", ":", "\"error\"", "}", ",", "cli", "=", "new", "CLIEngine", "(", "{", "useEslintrc", ":", "false", ",", "baseConfig", ":", "{", "extends", ":", "\"eslint:recommended\"", "}", ",", "rules", "}", ")", ",", "codeString", "=", "[", "\"function addOne(i) {\"", ",", "\" if (i != NaN) {\"", ",", "\" return i ++\"", ",", "\" } else {\"", ",", "\" return\"", ",", "\" }\"", ",", "\"};\"", "]", ".", "join", "(", "\"\\n\"", ")", ",", "\\n", ",", "rawMessages", "=", "cli", ".", "executeOnText", "(", "codeString", ",", "\"fullOfProblems.js\"", ",", "true", ")", ",", "rulesMap", "=", "cli", ".", "getRules", "(", ")", ";", "rulesMeta", "=", "{", "}", "Object", ".", "keys", "(", "rules", ")", ".", "forEach", "(", "ruleId", "=>", "{", "rulesMeta", "[", "ruleId", "]", "=", "rulesMap", ".", "get", "(", "ruleId", ")", ".", "meta", ";", "}", ")", ";", "}" ]
Gets linting results from every formatter, based on a hard-coded snippet and config @returns {Object} Output from each formatter
[ "Gets", "linting", "results", "from", "every", "formatter", "based", "on", "a", "hard", "-", "coded", "snippet", "and", "config" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L407-L456
train
eslint/eslint
Makefile.js
hasIdInTitle
function hasIdInTitle(id) { const docText = cat(docFilename); const idOldAtEndOfTitleRegExp = new RegExp(`^# (.*?) \\(${id}\\)`, "u"); // original format const idNewAtBeginningOfTitleRegExp = new RegExp(`^# ${id}: `, "u"); // new format is same as rules index /* * 1. Added support for new format. * 2. Will remove support for old format after all docs files have new format. * 3. Will remove this check when the main heading is automatically generated from rule metadata. */ return idNewAtBeginningOfTitleRegExp.test(docText) || idOldAtEndOfTitleRegExp.test(docText); }
javascript
function hasIdInTitle(id) { const docText = cat(docFilename); const idOldAtEndOfTitleRegExp = new RegExp(`^# (.*?) \\(${id}\\)`, "u"); // original format const idNewAtBeginningOfTitleRegExp = new RegExp(`^# ${id}: `, "u"); // new format is same as rules index /* * 1. Added support for new format. * 2. Will remove support for old format after all docs files have new format. * 3. Will remove this check when the main heading is automatically generated from rule metadata. */ return idNewAtBeginningOfTitleRegExp.test(docText) || idOldAtEndOfTitleRegExp.test(docText); }
[ "function", "hasIdInTitle", "(", "id", ")", "{", "const", "docText", "=", "cat", "(", "docFilename", ")", ";", "const", "idOldAtEndOfTitleRegExp", "=", "new", "RegExp", "(", "`", "\\\\", "${", "id", "}", "\\\\", "`", ",", "\"u\"", ")", ";", "const", "idNewAtBeginningOfTitleRegExp", "=", "new", "RegExp", "(", "`", "${", "id", "}", "`", ",", "\"u\"", ")", ";", "return", "idNewAtBeginningOfTitleRegExp", ".", "test", "(", "docText", ")", "||", "idOldAtEndOfTitleRegExp", ".", "test", "(", "docText", ")", ";", "}" ]
Check if id is present in title @param {string} id id to check for @returns {boolean} true if present @private
[ "Check", "if", "id", "is", "present", "in", "title" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L817-L828
train
eslint/eslint
Makefile.js
isPermissible
function isPermissible(dependency) { const licenses = dependency.licenses; if (Array.isArray(licenses)) { return licenses.some(license => isPermissible({ name: dependency.name, licenses: license })); } return OPEN_SOURCE_LICENSES.some(license => license.test(licenses)); }
javascript
function isPermissible(dependency) { const licenses = dependency.licenses; if (Array.isArray(licenses)) { return licenses.some(license => isPermissible({ name: dependency.name, licenses: license })); } return OPEN_SOURCE_LICENSES.some(license => license.test(licenses)); }
[ "function", "isPermissible", "(", "dependency", ")", "{", "const", "licenses", "=", "dependency", ".", "licenses", ";", "if", "(", "Array", ".", "isArray", "(", "licenses", ")", ")", "{", "return", "licenses", ".", "some", "(", "license", "=>", "isPermissible", "(", "{", "name", ":", "dependency", ".", "name", ",", "licenses", ":", "license", "}", ")", ")", ";", "}", "return", "OPEN_SOURCE_LICENSES", ".", "some", "(", "license", "=>", "license", ".", "test", "(", "licenses", ")", ")", ";", "}" ]
Check if a dependency is eligible to be used by us @param {Object} dependency dependency to check @returns {boolean} true if we have permission @private
[ "Check", "if", "a", "dependency", "is", "eligible", "to", "be", "used", "by", "us" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L882-L893
train
eslint/eslint
Makefile.js
loadPerformance
function loadPerformance() { echo(""); echo("Loading:"); const results = []; for (let cnt = 0; cnt < 5; cnt++) { const loadPerfData = loadPerf({ checkDependencies: false }); echo(` Load performance Run #${cnt + 1}: %dms`, loadPerfData.loadTime); results.push(loadPerfData.loadTime); } results.sort((a, b) => a - b); const median = results[~~(results.length / 2)]; echo(""); echo(" Load Performance median: %dms", median); echo(""); }
javascript
function loadPerformance() { echo(""); echo("Loading:"); const results = []; for (let cnt = 0; cnt < 5; cnt++) { const loadPerfData = loadPerf({ checkDependencies: false }); echo(` Load performance Run #${cnt + 1}: %dms`, loadPerfData.loadTime); results.push(loadPerfData.loadTime); } results.sort((a, b) => a - b); const median = results[~~(results.length / 2)]; echo(""); echo(" Load Performance median: %dms", median); echo(""); }
[ "function", "loadPerformance", "(", ")", "{", "echo", "(", "\"\"", ")", ";", "echo", "(", "\"Loading:\"", ")", ";", "const", "results", "=", "[", "]", ";", "for", "(", "let", "cnt", "=", "0", ";", "cnt", "<", "5", ";", "cnt", "++", ")", "{", "const", "loadPerfData", "=", "loadPerf", "(", "{", "checkDependencies", ":", "false", "}", ")", ";", "echo", "(", "`", "${", "cnt", "+", "1", "}", "`", ",", "loadPerfData", ".", "loadTime", ")", ";", "results", ".", "push", "(", "loadPerfData", ".", "loadTime", ")", ";", "}", "results", ".", "sort", "(", "(", "a", ",", "b", ")", "=>", "a", "-", "b", ")", ";", "const", "median", "=", "results", "[", "~", "~", "(", "results", ".", "length", "/", "2", ")", "]", ";", "echo", "(", "\"\"", ")", ";", "echo", "(", "\" Load Performance median: %dms\"", ",", "median", ")", ";", "echo", "(", "\"\"", ")", ";", "}" ]
Run the load performance for eslint @returns {void} @private
[ "Run", "the", "load", "performance", "for", "eslint" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/Makefile.js#L1036-L1057
train
eslint/eslint
lib/rules/template-tag-spacing.js
checkSpacing
function checkSpacing(node) { const tagToken = sourceCode.getTokenBefore(node.quasi); const literalToken = sourceCode.getFirstToken(node.quasi); const hasWhitespace = sourceCode.isSpaceBetweenTokens(tagToken, literalToken); if (never && hasWhitespace) { context.report({ node, loc: tagToken.loc.start, messageId: "unexpected", fix(fixer) { const comments = sourceCode.getCommentsBefore(node.quasi); // Don't fix anything if there's a single line comment after the template tag if (comments.some(comment => comment.type === "Line")) { return null; } return fixer.replaceTextRange( [tagToken.range[1], literalToken.range[0]], comments.reduce((text, comment) => text + sourceCode.getText(comment), "") ); } }); } else if (!never && !hasWhitespace) { context.report({ node, loc: tagToken.loc.start, messageId: "missing", fix(fixer) { return fixer.insertTextAfter(tagToken, " "); } }); } }
javascript
function checkSpacing(node) { const tagToken = sourceCode.getTokenBefore(node.quasi); const literalToken = sourceCode.getFirstToken(node.quasi); const hasWhitespace = sourceCode.isSpaceBetweenTokens(tagToken, literalToken); if (never && hasWhitespace) { context.report({ node, loc: tagToken.loc.start, messageId: "unexpected", fix(fixer) { const comments = sourceCode.getCommentsBefore(node.quasi); // Don't fix anything if there's a single line comment after the template tag if (comments.some(comment => comment.type === "Line")) { return null; } return fixer.replaceTextRange( [tagToken.range[1], literalToken.range[0]], comments.reduce((text, comment) => text + sourceCode.getText(comment), "") ); } }); } else if (!never && !hasWhitespace) { context.report({ node, loc: tagToken.loc.start, messageId: "missing", fix(fixer) { return fixer.insertTextAfter(tagToken, " "); } }); } }
[ "function", "checkSpacing", "(", "node", ")", "{", "const", "tagToken", "=", "sourceCode", ".", "getTokenBefore", "(", "node", ".", "quasi", ")", ";", "const", "literalToken", "=", "sourceCode", ".", "getFirstToken", "(", "node", ".", "quasi", ")", ";", "const", "hasWhitespace", "=", "sourceCode", ".", "isSpaceBetweenTokens", "(", "tagToken", ",", "literalToken", ")", ";", "if", "(", "never", "&&", "hasWhitespace", ")", "{", "context", ".", "report", "(", "{", "node", ",", "loc", ":", "tagToken", ".", "loc", ".", "start", ",", "messageId", ":", "\"unexpected\"", ",", "fix", "(", "fixer", ")", "{", "const", "comments", "=", "sourceCode", ".", "getCommentsBefore", "(", "node", ".", "quasi", ")", ";", "if", "(", "comments", ".", "some", "(", "comment", "=>", "comment", ".", "type", "===", "\"Line\"", ")", ")", "{", "return", "null", ";", "}", "return", "fixer", ".", "replaceTextRange", "(", "[", "tagToken", ".", "range", "[", "1", "]", ",", "literalToken", ".", "range", "[", "0", "]", "]", ",", "comments", ".", "reduce", "(", "(", "text", ",", "comment", ")", "=>", "text", "+", "sourceCode", ".", "getText", "(", "comment", ")", ",", "\"\"", ")", ")", ";", "}", "}", ")", ";", "}", "else", "if", "(", "!", "never", "&&", "!", "hasWhitespace", ")", "{", "context", ".", "report", "(", "{", "node", ",", "loc", ":", "tagToken", ".", "loc", ".", "start", ",", "messageId", ":", "\"missing\"", ",", "fix", "(", "fixer", ")", "{", "return", "fixer", ".", "insertTextAfter", "(", "tagToken", ",", "\" \"", ")", ";", "}", "}", ")", ";", "}", "}" ]
Check if a space is present between a template tag and its literal @param {ASTNode} node node to evaluate @returns {void} @private
[ "Check", "if", "a", "space", "is", "present", "between", "a", "template", "tag", "and", "its", "literal" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/template-tag-spacing.js#L44-L78
train
eslint/eslint
lib/rules/jsx-quotes.js
usesExpectedQuotes
function usesExpectedQuotes(node) { return node.value.indexOf(setting.quote) !== -1 || astUtils.isSurroundedBy(node.raw, setting.quote); }
javascript
function usesExpectedQuotes(node) { return node.value.indexOf(setting.quote) !== -1 || astUtils.isSurroundedBy(node.raw, setting.quote); }
[ "function", "usesExpectedQuotes", "(", "node", ")", "{", "return", "node", ".", "value", ".", "indexOf", "(", "setting", ".", "quote", ")", "!==", "-", "1", "||", "astUtils", ".", "isSurroundedBy", "(", "node", ".", "raw", ",", "setting", ".", "quote", ")", ";", "}" ]
Checks if the given string literal node uses the expected quotes @param {ASTNode} node - A string literal node. @returns {boolean} Whether or not the string literal used the expected quotes. @public
[ "Checks", "if", "the", "given", "string", "literal", "node", "uses", "the", "expected", "quotes" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/jsx-quotes.js#L72-L74
train
eslint/eslint
lib/rules/strict.js
reportSlice
function reportSlice(nodes, start, end, messageId, fix) { nodes.slice(start, end).forEach(node => { context.report({ node, messageId, fix: fix ? getFixFunction(node) : null }); }); }
javascript
function reportSlice(nodes, start, end, messageId, fix) { nodes.slice(start, end).forEach(node => { context.report({ node, messageId, fix: fix ? getFixFunction(node) : null }); }); }
[ "function", "reportSlice", "(", "nodes", ",", "start", ",", "end", ",", "messageId", ",", "fix", ")", "{", "nodes", ".", "slice", "(", "start", ",", "end", ")", ".", "forEach", "(", "node", "=>", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ",", "fix", ":", "fix", "?", "getFixFunction", "(", "node", ")", ":", "null", "}", ")", ";", "}", ")", ";", "}" ]
Report a slice of an array of nodes with a given message. @param {ASTNode[]} nodes Nodes. @param {string} start Index to start from. @param {string} end Index to end before. @param {string} messageId Message to display. @param {boolean} fix `true` if the directive should be fixed (i.e. removed) @returns {void}
[ "Report", "a", "slice", "of", "an", "array", "of", "nodes", "with", "a", "given", "message", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/strict.js#L140-L144
train
eslint/eslint
lib/rules/strict.js
reportAll
function reportAll(nodes, messageId, fix) { reportSlice(nodes, 0, nodes.length, messageId, fix); }
javascript
function reportAll(nodes, messageId, fix) { reportSlice(nodes, 0, nodes.length, messageId, fix); }
[ "function", "reportAll", "(", "nodes", ",", "messageId", ",", "fix", ")", "{", "reportSlice", "(", "nodes", ",", "0", ",", "nodes", ".", "length", ",", "messageId", ",", "fix", ")", ";", "}" ]
Report all nodes in an array with a given message. @param {ASTNode[]} nodes Nodes. @param {string} messageId Message id to display. @param {boolean} fix `true` if the directive should be fixed (i.e. removed) @returns {void}
[ "Report", "all", "nodes", "in", "an", "array", "with", "a", "given", "message", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/strict.js#L153-L155
train
eslint/eslint
lib/rules/strict.js
reportAllExceptFirst
function reportAllExceptFirst(nodes, messageId, fix) { reportSlice(nodes, 1, nodes.length, messageId, fix); }
javascript
function reportAllExceptFirst(nodes, messageId, fix) { reportSlice(nodes, 1, nodes.length, messageId, fix); }
[ "function", "reportAllExceptFirst", "(", "nodes", ",", "messageId", ",", "fix", ")", "{", "reportSlice", "(", "nodes", ",", "1", ",", "nodes", ".", "length", ",", "messageId", ",", "fix", ")", ";", "}" ]
Report all nodes in an array, except the first, with a given message. @param {ASTNode[]} nodes Nodes. @param {string} messageId Message id to display. @param {boolean} fix `true` if the directive should be fixed (i.e. removed) @returns {void}
[ "Report", "all", "nodes", "in", "an", "array", "except", "the", "first", "with", "a", "given", "message", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/strict.js#L164-L166
train
eslint/eslint
lib/rules/strict.js
enterFunctionInFunctionMode
function enterFunctionInFunctionMode(node, useStrictDirectives) { const isInClass = classScopes.length > 0, isParentGlobal = scopes.length === 0 && classScopes.length === 0, isParentStrict = scopes.length > 0 && scopes[scopes.length - 1], isStrict = useStrictDirectives.length > 0; if (isStrict) { if (!isSimpleParameterList(node.params)) { context.report({ node: useStrictDirectives[0], messageId: "nonSimpleParameterList" }); } else if (isParentStrict) { context.report({ node: useStrictDirectives[0], messageId: "unnecessary", fix: getFixFunction(useStrictDirectives[0]) }); } else if (isInClass) { context.report({ node: useStrictDirectives[0], messageId: "unnecessaryInClasses", fix: getFixFunction(useStrictDirectives[0]) }); } reportAllExceptFirst(useStrictDirectives, "multiple", true); } else if (isParentGlobal) { if (isSimpleParameterList(node.params)) { context.report({ node, messageId: "function" }); } else { context.report({ node, messageId: "wrap", data: { name: astUtils.getFunctionNameWithKind(node) } }); } } scopes.push(isParentStrict || isStrict); }
javascript
function enterFunctionInFunctionMode(node, useStrictDirectives) { const isInClass = classScopes.length > 0, isParentGlobal = scopes.length === 0 && classScopes.length === 0, isParentStrict = scopes.length > 0 && scopes[scopes.length - 1], isStrict = useStrictDirectives.length > 0; if (isStrict) { if (!isSimpleParameterList(node.params)) { context.report({ node: useStrictDirectives[0], messageId: "nonSimpleParameterList" }); } else if (isParentStrict) { context.report({ node: useStrictDirectives[0], messageId: "unnecessary", fix: getFixFunction(useStrictDirectives[0]) }); } else if (isInClass) { context.report({ node: useStrictDirectives[0], messageId: "unnecessaryInClasses", fix: getFixFunction(useStrictDirectives[0]) }); } reportAllExceptFirst(useStrictDirectives, "multiple", true); } else if (isParentGlobal) { if (isSimpleParameterList(node.params)) { context.report({ node, messageId: "function" }); } else { context.report({ node, messageId: "wrap", data: { name: astUtils.getFunctionNameWithKind(node) } }); } } scopes.push(isParentStrict || isStrict); }
[ "function", "enterFunctionInFunctionMode", "(", "node", ",", "useStrictDirectives", ")", "{", "const", "isInClass", "=", "classScopes", ".", "length", ">", "0", ",", "isParentGlobal", "=", "scopes", ".", "length", "===", "0", "&&", "classScopes", ".", "length", "===", "0", ",", "isParentStrict", "=", "scopes", ".", "length", ">", "0", "&&", "scopes", "[", "scopes", ".", "length", "-", "1", "]", ",", "isStrict", "=", "useStrictDirectives", ".", "length", ">", "0", ";", "if", "(", "isStrict", ")", "{", "if", "(", "!", "isSimpleParameterList", "(", "node", ".", "params", ")", ")", "{", "context", ".", "report", "(", "{", "node", ":", "useStrictDirectives", "[", "0", "]", ",", "messageId", ":", "\"nonSimpleParameterList\"", "}", ")", ";", "}", "else", "if", "(", "isParentStrict", ")", "{", "context", ".", "report", "(", "{", "node", ":", "useStrictDirectives", "[", "0", "]", ",", "messageId", ":", "\"unnecessary\"", ",", "fix", ":", "getFixFunction", "(", "useStrictDirectives", "[", "0", "]", ")", "}", ")", ";", "}", "else", "if", "(", "isInClass", ")", "{", "context", ".", "report", "(", "{", "node", ":", "useStrictDirectives", "[", "0", "]", ",", "messageId", ":", "\"unnecessaryInClasses\"", ",", "fix", ":", "getFixFunction", "(", "useStrictDirectives", "[", "0", "]", ")", "}", ")", ";", "}", "reportAllExceptFirst", "(", "useStrictDirectives", ",", "\"multiple\"", ",", "true", ")", ";", "}", "else", "if", "(", "isParentGlobal", ")", "{", "if", "(", "isSimpleParameterList", "(", "node", ".", "params", ")", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"function\"", "}", ")", ";", "}", "else", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"wrap\"", ",", "data", ":", "{", "name", ":", "astUtils", ".", "getFunctionNameWithKind", "(", "node", ")", "}", "}", ")", ";", "}", "}", "scopes", ".", "push", "(", "isParentStrict", "||", "isStrict", ")", ";", "}" ]
Entering a function in 'function' mode pushes a new nested scope onto the stack. The new scope is true if the nested function is strict mode code. @param {ASTNode} node The function declaration or expression. @param {ASTNode[]} useStrictDirectives The Use Strict Directives of the node. @returns {void}
[ "Entering", "a", "function", "in", "function", "mode", "pushes", "a", "new", "nested", "scope", "onto", "the", "stack", ".", "The", "new", "scope", "is", "true", "if", "the", "nested", "function", "is", "strict", "mode", "code", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/strict.js#L175-L204
train
eslint/eslint
lib/formatters/codeframe.js
formatMessage
function formatMessage(message, parentResult) { const type = (message.fatal || message.severity === 2) ? chalk.red("error") : chalk.yellow("warning"); const msg = `${chalk.bold(message.message.replace(/([^ ])\.$/u, "$1"))}`; const ruleId = message.fatal ? "" : chalk.dim(`(${message.ruleId})`); const filePath = formatFilePath(parentResult.filePath, message.line, message.column); const sourceCode = parentResult.output ? parentResult.output : parentResult.source; const firstLine = [ `${type}:`, `${msg}`, ruleId ? `${ruleId}` : "", sourceCode ? `at ${filePath}:` : `at ${filePath}` ].filter(String).join(" "); const result = [firstLine]; if (sourceCode) { result.push( codeFrameColumns(sourceCode, { start: { line: message.line, column: message.column } }, { highlightCode: false }) ); } return result.join("\n"); }
javascript
function formatMessage(message, parentResult) { const type = (message.fatal || message.severity === 2) ? chalk.red("error") : chalk.yellow("warning"); const msg = `${chalk.bold(message.message.replace(/([^ ])\.$/u, "$1"))}`; const ruleId = message.fatal ? "" : chalk.dim(`(${message.ruleId})`); const filePath = formatFilePath(parentResult.filePath, message.line, message.column); const sourceCode = parentResult.output ? parentResult.output : parentResult.source; const firstLine = [ `${type}:`, `${msg}`, ruleId ? `${ruleId}` : "", sourceCode ? `at ${filePath}:` : `at ${filePath}` ].filter(String).join(" "); const result = [firstLine]; if (sourceCode) { result.push( codeFrameColumns(sourceCode, { start: { line: message.line, column: message.column } }, { highlightCode: false }) ); } return result.join("\n"); }
[ "function", "formatMessage", "(", "message", ",", "parentResult", ")", "{", "const", "type", "=", "(", "message", ".", "fatal", "||", "message", ".", "severity", "===", "2", ")", "?", "chalk", ".", "red", "(", "\"error\"", ")", ":", "chalk", ".", "yellow", "(", "\"warning\"", ")", ";", "const", "msg", "=", "`", "${", "chalk", ".", "bold", "(", "message", ".", "message", ".", "replace", "(", "/", "([^ ])\\.$", "/", "u", ",", "\"$1\"", ")", ")", "}", "`", ";", "const", "ruleId", "=", "message", ".", "fatal", "?", "\"\"", ":", "chalk", ".", "dim", "(", "`", "${", "message", ".", "ruleId", "}", "`", ")", ";", "const", "filePath", "=", "formatFilePath", "(", "parentResult", ".", "filePath", ",", "message", ".", "line", ",", "message", ".", "column", ")", ";", "const", "sourceCode", "=", "parentResult", ".", "output", "?", "parentResult", ".", "output", ":", "parentResult", ".", "source", ";", "const", "firstLine", "=", "[", "`", "${", "type", "}", "`", ",", "`", "${", "msg", "}", "`", ",", "ruleId", "?", "`", "${", "ruleId", "}", "`", ":", "\"\"", ",", "sourceCode", "?", "`", "${", "filePath", "}", "`", ":", "`", "${", "filePath", "}", "`", "]", ".", "filter", "(", "String", ")", ".", "join", "(", "\" \"", ")", ";", "const", "result", "=", "[", "firstLine", "]", ";", "if", "(", "sourceCode", ")", "{", "result", ".", "push", "(", "codeFrameColumns", "(", "sourceCode", ",", "{", "start", ":", "{", "line", ":", "message", ".", "line", ",", "column", ":", "message", ".", "column", "}", "}", ",", "{", "highlightCode", ":", "false", "}", ")", ")", ";", "}", "return", "result", ".", "join", "(", "\"\\n\"", ")", ";", "}" ]
Gets the formatted output for a given message. @param {Object} message The object that represents this message. @param {Object} parentResult The result object that this message belongs to. @returns {string} The formatted output.
[ "Gets", "the", "formatted", "output", "for", "a", "given", "message", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/formatters/codeframe.js#L48-L71
train
eslint/eslint
lib/formatters/codeframe.js
formatSummary
function formatSummary(errors, warnings, fixableErrors, fixableWarnings) { const summaryColor = errors > 0 ? "red" : "yellow"; const summary = []; const fixablesSummary = []; if (errors > 0) { summary.push(`${errors} ${pluralize("error", errors)}`); } if (warnings > 0) { summary.push(`${warnings} ${pluralize("warning", warnings)}`); } if (fixableErrors > 0) { fixablesSummary.push(`${fixableErrors} ${pluralize("error", fixableErrors)}`); } if (fixableWarnings > 0) { fixablesSummary.push(`${fixableWarnings} ${pluralize("warning", fixableWarnings)}`); } let output = chalk[summaryColor].bold(`${summary.join(" and ")} found.`); if (fixableErrors || fixableWarnings) { output += chalk[summaryColor].bold(`\n${fixablesSummary.join(" and ")} potentially fixable with the \`--fix\` option.`); } return output; }
javascript
function formatSummary(errors, warnings, fixableErrors, fixableWarnings) { const summaryColor = errors > 0 ? "red" : "yellow"; const summary = []; const fixablesSummary = []; if (errors > 0) { summary.push(`${errors} ${pluralize("error", errors)}`); } if (warnings > 0) { summary.push(`${warnings} ${pluralize("warning", warnings)}`); } if (fixableErrors > 0) { fixablesSummary.push(`${fixableErrors} ${pluralize("error", fixableErrors)}`); } if (fixableWarnings > 0) { fixablesSummary.push(`${fixableWarnings} ${pluralize("warning", fixableWarnings)}`); } let output = chalk[summaryColor].bold(`${summary.join(" and ")} found.`); if (fixableErrors || fixableWarnings) { output += chalk[summaryColor].bold(`\n${fixablesSummary.join(" and ")} potentially fixable with the \`--fix\` option.`); } return output; }
[ "function", "formatSummary", "(", "errors", ",", "warnings", ",", "fixableErrors", ",", "fixableWarnings", ")", "{", "const", "summaryColor", "=", "errors", ">", "0", "?", "\"red\"", ":", "\"yellow\"", ";", "const", "summary", "=", "[", "]", ";", "const", "fixablesSummary", "=", "[", "]", ";", "if", "(", "errors", ">", "0", ")", "{", "summary", ".", "push", "(", "`", "${", "errors", "}", "${", "pluralize", "(", "\"error\"", ",", "errors", ")", "}", "`", ")", ";", "}", "if", "(", "warnings", ">", "0", ")", "{", "summary", ".", "push", "(", "`", "${", "warnings", "}", "${", "pluralize", "(", "\"warning\"", ",", "warnings", ")", "}", "`", ")", ";", "}", "if", "(", "fixableErrors", ">", "0", ")", "{", "fixablesSummary", ".", "push", "(", "`", "${", "fixableErrors", "}", "${", "pluralize", "(", "\"error\"", ",", "fixableErrors", ")", "}", "`", ")", ";", "}", "if", "(", "fixableWarnings", ">", "0", ")", "{", "fixablesSummary", ".", "push", "(", "`", "${", "fixableWarnings", "}", "${", "pluralize", "(", "\"warning\"", ",", "fixableWarnings", ")", "}", "`", ")", ";", "}", "let", "output", "=", "chalk", "[", "summaryColor", "]", ".", "bold", "(", "`", "${", "summary", ".", "join", "(", "\" and \"", ")", "}", "`", ")", ";", "if", "(", "fixableErrors", "||", "fixableWarnings", ")", "{", "output", "+=", "chalk", "[", "summaryColor", "]", ".", "bold", "(", "`", "\\n", "${", "fixablesSummary", ".", "join", "(", "\" and \"", ")", "}", "\\`", "\\`", "`", ")", ";", "}", "return", "output", ";", "}" ]
Gets the formatted output summary for a given number of errors and warnings. @param {number} errors The number of errors. @param {number} warnings The number of warnings. @param {number} fixableErrors The number of fixable errors. @param {number} fixableWarnings The number of fixable warnings. @returns {string} The formatted output summary.
[ "Gets", "the", "formatted", "output", "summary", "for", "a", "given", "number", "of", "errors", "and", "warnings", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/formatters/codeframe.js#L81-L109
train
eslint/eslint
lib/rules/no-native-reassign.js
checkVariable
function checkVariable(variable) { if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) { variable.references.forEach(checkReference); } }
javascript
function checkVariable(variable) { if (variable.writeable === false && exceptions.indexOf(variable.name) === -1) { variable.references.forEach(checkReference); } }
[ "function", "checkVariable", "(", "variable", ")", "{", "if", "(", "variable", ".", "writeable", "===", "false", "&&", "exceptions", ".", "indexOf", "(", "variable", ".", "name", ")", "===", "-", "1", ")", "{", "variable", ".", "references", ".", "forEach", "(", "checkReference", ")", ";", "}", "}" ]
Reports write references if a given variable is read-only builtin. @param {Variable} variable - A variable to check. @returns {void}
[ "Reports", "write", "references", "if", "a", "given", "variable", "is", "read", "-", "only", "builtin", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-native-reassign.js#L79-L83
train
eslint/eslint
lib/rules/space-unary-ops.js
overrideExistsForOperator
function overrideExistsForOperator(operator) { return options.overrides && Object.prototype.hasOwnProperty.call(options.overrides, operator); }
javascript
function overrideExistsForOperator(operator) { return options.overrides && Object.prototype.hasOwnProperty.call(options.overrides, operator); }
[ "function", "overrideExistsForOperator", "(", "operator", ")", "{", "return", "options", ".", "overrides", "&&", "Object", ".", "prototype", ".", "hasOwnProperty", ".", "call", "(", "options", ".", "overrides", ",", "operator", ")", ";", "}" ]
Checks if an override exists for a given operator. @param {string} operator Operator @returns {boolean} Whether or not an override has been provided for the operator
[ "Checks", "if", "an", "override", "exists", "for", "a", "given", "operator", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L86-L88
train
eslint/eslint
lib/rules/space-unary-ops.js
verifyWordHasSpaces
function verifyWordHasSpaces(node, firstToken, secondToken, word) { if (secondToken.range[0] === firstToken.range[1]) { context.report({ node, messageId: "wordOperator", data: { word }, fix(fixer) { return fixer.insertTextAfter(firstToken, " "); } }); } }
javascript
function verifyWordHasSpaces(node, firstToken, secondToken, word) { if (secondToken.range[0] === firstToken.range[1]) { context.report({ node, messageId: "wordOperator", data: { word }, fix(fixer) { return fixer.insertTextAfter(firstToken, " "); } }); } }
[ "function", "verifyWordHasSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "word", ")", "{", "if", "(", "secondToken", ".", "range", "[", "0", "]", "===", "firstToken", ".", "range", "[", "1", "]", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"wordOperator\"", ",", "data", ":", "{", "word", "}", ",", "fix", "(", "fixer", ")", "{", "return", "fixer", ".", "insertTextAfter", "(", "firstToken", ",", "\" \"", ")", ";", "}", "}", ")", ";", "}", "}" ]
Verify Unary Word Operator has spaces after the word operator @param {ASTnode} node AST node @param {Object} firstToken first token from the AST node @param {Object} secondToken second token from the AST node @param {string} word The word to be used for reporting @returns {void}
[ "Verify", "Unary", "Word", "Operator", "has", "spaces", "after", "the", "word", "operator" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L107-L120
train
eslint/eslint
lib/rules/space-unary-ops.js
verifyWordDoesntHaveSpaces
function verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word) { if (astUtils.canTokensBeAdjacent(firstToken, secondToken)) { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node, messageId: "unexpectedAfterWord", data: { word }, fix(fixer) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } }); } } }
javascript
function verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word) { if (astUtils.canTokensBeAdjacent(firstToken, secondToken)) { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node, messageId: "unexpectedAfterWord", data: { word }, fix(fixer) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } }); } } }
[ "function", "verifyWordDoesntHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "word", ")", "{", "if", "(", "astUtils", ".", "canTokensBeAdjacent", "(", "firstToken", ",", "secondToken", ")", ")", "{", "if", "(", "secondToken", ".", "range", "[", "0", "]", ">", "firstToken", ".", "range", "[", "1", "]", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"unexpectedAfterWord\"", ",", "data", ":", "{", "word", "}", ",", "fix", "(", "fixer", ")", "{", "return", "fixer", ".", "removeRange", "(", "[", "firstToken", ".", "range", "[", "1", "]", ",", "secondToken", ".", "range", "[", "0", "]", "]", ")", ";", "}", "}", ")", ";", "}", "}", "}" ]
Verify Unary Word Operator doesn't have spaces after the word operator @param {ASTnode} node AST node @param {Object} firstToken first token from the AST node @param {Object} secondToken second token from the AST node @param {string} word The word to be used for reporting @returns {void}
[ "Verify", "Unary", "Word", "Operator", "doesn", "t", "have", "spaces", "after", "the", "word", "operator" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L130-L145
train
eslint/eslint
lib/rules/space-unary-ops.js
checkUnaryWordOperatorForSpaces
function checkUnaryWordOperatorForSpaces(node, firstToken, secondToken, word) { if (overrideExistsForOperator(word)) { if (overrideEnforcesSpaces(word)) { verifyWordHasSpaces(node, firstToken, secondToken, word); } else { verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word); } } else if (options.words) { verifyWordHasSpaces(node, firstToken, secondToken, word); } else { verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word); } }
javascript
function checkUnaryWordOperatorForSpaces(node, firstToken, secondToken, word) { if (overrideExistsForOperator(word)) { if (overrideEnforcesSpaces(word)) { verifyWordHasSpaces(node, firstToken, secondToken, word); } else { verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word); } } else if (options.words) { verifyWordHasSpaces(node, firstToken, secondToken, word); } else { verifyWordDoesntHaveSpaces(node, firstToken, secondToken, word); } }
[ "function", "checkUnaryWordOperatorForSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "word", ")", "{", "if", "(", "overrideExistsForOperator", "(", "word", ")", ")", "{", "if", "(", "overrideEnforcesSpaces", "(", "word", ")", ")", "{", "verifyWordHasSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "word", ")", ";", "}", "else", "{", "verifyWordDoesntHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "word", ")", ";", "}", "}", "else", "if", "(", "options", ".", "words", ")", "{", "verifyWordHasSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "word", ")", ";", "}", "else", "{", "verifyWordDoesntHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "word", ")", ";", "}", "}" ]
Check Unary Word Operators for spaces after the word operator @param {ASTnode} node AST node @param {Object} firstToken first token from the AST node @param {Object} secondToken second token from the AST node @param {string} word The word to be used for reporting @returns {void}
[ "Check", "Unary", "Word", "Operators", "for", "spaces", "after", "the", "word", "operator" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L155-L167
train
eslint/eslint
lib/rules/space-unary-ops.js
checkForSpacesAfterYield
function checkForSpacesAfterYield(node) { const tokens = sourceCode.getFirstTokens(node, 3), word = "yield"; if (!node.argument || node.delegate) { return; } checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], word); }
javascript
function checkForSpacesAfterYield(node) { const tokens = sourceCode.getFirstTokens(node, 3), word = "yield"; if (!node.argument || node.delegate) { return; } checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], word); }
[ "function", "checkForSpacesAfterYield", "(", "node", ")", "{", "const", "tokens", "=", "sourceCode", ".", "getFirstTokens", "(", "node", ",", "3", ")", ",", "word", "=", "\"yield\"", ";", "if", "(", "!", "node", ".", "argument", "||", "node", ".", "delegate", ")", "{", "return", ";", "}", "checkUnaryWordOperatorForSpaces", "(", "node", ",", "tokens", "[", "0", "]", ",", "tokens", "[", "1", "]", ",", "word", ")", ";", "}" ]
Verifies YieldExpressions satisfy spacing requirements @param {ASTnode} node AST node @returns {void}
[ "Verifies", "YieldExpressions", "satisfy", "spacing", "requirements" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L174-L183
train
eslint/eslint
lib/rules/space-unary-ops.js
checkForSpacesAfterAwait
function checkForSpacesAfterAwait(node) { const tokens = sourceCode.getFirstTokens(node, 3); checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], "await"); }
javascript
function checkForSpacesAfterAwait(node) { const tokens = sourceCode.getFirstTokens(node, 3); checkUnaryWordOperatorForSpaces(node, tokens[0], tokens[1], "await"); }
[ "function", "checkForSpacesAfterAwait", "(", "node", ")", "{", "const", "tokens", "=", "sourceCode", ".", "getFirstTokens", "(", "node", ",", "3", ")", ";", "checkUnaryWordOperatorForSpaces", "(", "node", ",", "tokens", "[", "0", "]", ",", "tokens", "[", "1", "]", ",", "\"await\"", ")", ";", "}" ]
Verifies AwaitExpressions satisfy spacing requirements @param {ASTNode} node AwaitExpression AST node @returns {void}
[ "Verifies", "AwaitExpressions", "satisfy", "spacing", "requirements" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L190-L194
train
eslint/eslint
lib/rules/space-unary-ops.js
verifyNonWordsHaveSpaces
function verifyNonWordsHaveSpaces(node, firstToken, secondToken) { if (node.prefix) { if (isFirstBangInBangBangExpression(node)) { return; } if (firstToken.range[1] === secondToken.range[0]) { context.report({ node, messageId: "operator", data: { operator: firstToken.value }, fix(fixer) { return fixer.insertTextAfter(firstToken, " "); } }); } } else { if (firstToken.range[1] === secondToken.range[0]) { context.report({ node, messageId: "beforeUnaryExpressions", data: { token: secondToken.value }, fix(fixer) { return fixer.insertTextBefore(secondToken, " "); } }); } } }
javascript
function verifyNonWordsHaveSpaces(node, firstToken, secondToken) { if (node.prefix) { if (isFirstBangInBangBangExpression(node)) { return; } if (firstToken.range[1] === secondToken.range[0]) { context.report({ node, messageId: "operator", data: { operator: firstToken.value }, fix(fixer) { return fixer.insertTextAfter(firstToken, " "); } }); } } else { if (firstToken.range[1] === secondToken.range[0]) { context.report({ node, messageId: "beforeUnaryExpressions", data: { token: secondToken.value }, fix(fixer) { return fixer.insertTextBefore(secondToken, " "); } }); } } }
[ "function", "verifyNonWordsHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ")", "{", "if", "(", "node", ".", "prefix", ")", "{", "if", "(", "isFirstBangInBangBangExpression", "(", "node", ")", ")", "{", "return", ";", "}", "if", "(", "firstToken", ".", "range", "[", "1", "]", "===", "secondToken", ".", "range", "[", "0", "]", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"operator\"", ",", "data", ":", "{", "operator", ":", "firstToken", ".", "value", "}", ",", "fix", "(", "fixer", ")", "{", "return", "fixer", ".", "insertTextAfter", "(", "firstToken", ",", "\" \"", ")", ";", "}", "}", ")", ";", "}", "}", "else", "{", "if", "(", "firstToken", ".", "range", "[", "1", "]", "===", "secondToken", ".", "range", "[", "0", "]", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"beforeUnaryExpressions\"", ",", "data", ":", "{", "token", ":", "secondToken", ".", "value", "}", ",", "fix", "(", "fixer", ")", "{", "return", "fixer", ".", "insertTextBefore", "(", "secondToken", ",", "\" \"", ")", ";", "}", "}", ")", ";", "}", "}", "}" ]
Verifies UnaryExpression, UpdateExpression and NewExpression have spaces before or after the operator @param {ASTnode} node AST node @param {Object} firstToken First token in the expression @param {Object} secondToken Second token in the expression @returns {void}
[ "Verifies", "UnaryExpression", "UpdateExpression", "and", "NewExpression", "have", "spaces", "before", "or", "after", "the", "operator" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L203-L234
train
eslint/eslint
lib/rules/space-unary-ops.js
verifyNonWordsDontHaveSpaces
function verifyNonWordsDontHaveSpaces(node, firstToken, secondToken) { if (node.prefix) { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node, messageId: "unexpectedAfter", data: { operator: firstToken.value }, fix(fixer) { if (astUtils.canTokensBeAdjacent(firstToken, secondToken)) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } return null; } }); } } else { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node, messageId: "unexpectedBefore", data: { operator: secondToken.value }, fix(fixer) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } }); } } }
javascript
function verifyNonWordsDontHaveSpaces(node, firstToken, secondToken) { if (node.prefix) { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node, messageId: "unexpectedAfter", data: { operator: firstToken.value }, fix(fixer) { if (astUtils.canTokensBeAdjacent(firstToken, secondToken)) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } return null; } }); } } else { if (secondToken.range[0] > firstToken.range[1]) { context.report({ node, messageId: "unexpectedBefore", data: { operator: secondToken.value }, fix(fixer) { return fixer.removeRange([firstToken.range[1], secondToken.range[0]]); } }); } } }
[ "function", "verifyNonWordsDontHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ")", "{", "if", "(", "node", ".", "prefix", ")", "{", "if", "(", "secondToken", ".", "range", "[", "0", "]", ">", "firstToken", ".", "range", "[", "1", "]", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"unexpectedAfter\"", ",", "data", ":", "{", "operator", ":", "firstToken", ".", "value", "}", ",", "fix", "(", "fixer", ")", "{", "if", "(", "astUtils", ".", "canTokensBeAdjacent", "(", "firstToken", ",", "secondToken", ")", ")", "{", "return", "fixer", ".", "removeRange", "(", "[", "firstToken", ".", "range", "[", "1", "]", ",", "secondToken", ".", "range", "[", "0", "]", "]", ")", ";", "}", "return", "null", ";", "}", "}", ")", ";", "}", "}", "else", "{", "if", "(", "secondToken", ".", "range", "[", "0", "]", ">", "firstToken", ".", "range", "[", "1", "]", ")", "{", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"unexpectedBefore\"", ",", "data", ":", "{", "operator", ":", "secondToken", ".", "value", "}", ",", "fix", "(", "fixer", ")", "{", "return", "fixer", ".", "removeRange", "(", "[", "firstToken", ".", "range", "[", "1", "]", ",", "secondToken", ".", "range", "[", "0", "]", "]", ")", ";", "}", "}", ")", ";", "}", "}", "}" ]
Verifies UnaryExpression, UpdateExpression and NewExpression don't have spaces before or after the operator @param {ASTnode} node AST node @param {Object} firstToken First token in the expression @param {Object} secondToken Second token in the expression @returns {void}
[ "Verifies", "UnaryExpression", "UpdateExpression", "and", "NewExpression", "don", "t", "have", "spaces", "before", "or", "after", "the", "operator" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L243-L274
train
eslint/eslint
lib/rules/space-unary-ops.js
checkForSpaces
function checkForSpaces(node) { const tokens = node.type === "UpdateExpression" && !node.prefix ? sourceCode.getLastTokens(node, 2) : sourceCode.getFirstTokens(node, 2); const firstToken = tokens[0]; const secondToken = tokens[1]; if ((node.type === "NewExpression" || node.prefix) && firstToken.type === "Keyword") { checkUnaryWordOperatorForSpaces(node, firstToken, secondToken, firstToken.value); return; } const operator = node.prefix ? tokens[0].value : tokens[1].value; if (overrideExistsForOperator(operator)) { if (overrideEnforcesSpaces(operator)) { verifyNonWordsHaveSpaces(node, firstToken, secondToken); } else { verifyNonWordsDontHaveSpaces(node, firstToken, secondToken); } } else if (options.nonwords) { verifyNonWordsHaveSpaces(node, firstToken, secondToken); } else { verifyNonWordsDontHaveSpaces(node, firstToken, secondToken); } }
javascript
function checkForSpaces(node) { const tokens = node.type === "UpdateExpression" && !node.prefix ? sourceCode.getLastTokens(node, 2) : sourceCode.getFirstTokens(node, 2); const firstToken = tokens[0]; const secondToken = tokens[1]; if ((node.type === "NewExpression" || node.prefix) && firstToken.type === "Keyword") { checkUnaryWordOperatorForSpaces(node, firstToken, secondToken, firstToken.value); return; } const operator = node.prefix ? tokens[0].value : tokens[1].value; if (overrideExistsForOperator(operator)) { if (overrideEnforcesSpaces(operator)) { verifyNonWordsHaveSpaces(node, firstToken, secondToken); } else { verifyNonWordsDontHaveSpaces(node, firstToken, secondToken); } } else if (options.nonwords) { verifyNonWordsHaveSpaces(node, firstToken, secondToken); } else { verifyNonWordsDontHaveSpaces(node, firstToken, secondToken); } }
[ "function", "checkForSpaces", "(", "node", ")", "{", "const", "tokens", "=", "node", ".", "type", "===", "\"UpdateExpression\"", "&&", "!", "node", ".", "prefix", "?", "sourceCode", ".", "getLastTokens", "(", "node", ",", "2", ")", ":", "sourceCode", ".", "getFirstTokens", "(", "node", ",", "2", ")", ";", "const", "firstToken", "=", "tokens", "[", "0", "]", ";", "const", "secondToken", "=", "tokens", "[", "1", "]", ";", "if", "(", "(", "node", ".", "type", "===", "\"NewExpression\"", "||", "node", ".", "prefix", ")", "&&", "firstToken", ".", "type", "===", "\"Keyword\"", ")", "{", "checkUnaryWordOperatorForSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ",", "firstToken", ".", "value", ")", ";", "return", ";", "}", "const", "operator", "=", "node", ".", "prefix", "?", "tokens", "[", "0", "]", ".", "value", ":", "tokens", "[", "1", "]", ".", "value", ";", "if", "(", "overrideExistsForOperator", "(", "operator", ")", ")", "{", "if", "(", "overrideEnforcesSpaces", "(", "operator", ")", ")", "{", "verifyNonWordsHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ")", ";", "}", "else", "{", "verifyNonWordsDontHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ")", ";", "}", "}", "else", "if", "(", "options", ".", "nonwords", ")", "{", "verifyNonWordsHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ")", ";", "}", "else", "{", "verifyNonWordsDontHaveSpaces", "(", "node", ",", "firstToken", ",", "secondToken", ")", ";", "}", "}" ]
Verifies UnaryExpression, UpdateExpression and NewExpression satisfy spacing requirements @param {ASTnode} node AST node @returns {void}
[ "Verifies", "UnaryExpression", "UpdateExpression", "and", "NewExpression", "satisfy", "spacing", "requirements" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/space-unary-ops.js#L281-L306
train
eslint/eslint
lib/rules/no-irregular-whitespace.js
removeWhitespaceError
function removeWhitespaceError(node) { const locStart = node.loc.start; const locEnd = node.loc.end; errors = errors.filter(({ loc: errorLoc }) => { if (errorLoc.line >= locStart.line && errorLoc.line <= locEnd.line) { if (errorLoc.column >= locStart.column && (errorLoc.column <= locEnd.column || errorLoc.line < locEnd.line)) { return false; } } return true; }); }
javascript
function removeWhitespaceError(node) { const locStart = node.loc.start; const locEnd = node.loc.end; errors = errors.filter(({ loc: errorLoc }) => { if (errorLoc.line >= locStart.line && errorLoc.line <= locEnd.line) { if (errorLoc.column >= locStart.column && (errorLoc.column <= locEnd.column || errorLoc.line < locEnd.line)) { return false; } } return true; }); }
[ "function", "removeWhitespaceError", "(", "node", ")", "{", "const", "locStart", "=", "node", ".", "loc", ".", "start", ";", "const", "locEnd", "=", "node", ".", "loc", ".", "end", ";", "errors", "=", "errors", ".", "filter", "(", "(", "{", "loc", ":", "errorLoc", "}", ")", "=>", "{", "if", "(", "errorLoc", ".", "line", ">=", "locStart", ".", "line", "&&", "errorLoc", ".", "line", "<=", "locEnd", ".", "line", ")", "{", "if", "(", "errorLoc", ".", "column", ">=", "locStart", ".", "column", "&&", "(", "errorLoc", ".", "column", "<=", "locEnd", ".", "column", "||", "errorLoc", ".", "line", "<", "locEnd", ".", "line", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", ")", ";", "}" ]
Removes errors that occur inside a string node @param {ASTNode} node to check for matching errors. @returns {void} @private
[ "Removes", "errors", "that", "occur", "inside", "a", "string", "node" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-irregular-whitespace.js#L86-L98
train
eslint/eslint
lib/rules/no-irregular-whitespace.js
removeInvalidNodeErrorsInTemplateLiteral
function removeInvalidNodeErrorsInTemplateLiteral(node) { if (typeof node.value.raw === "string") { if (ALL_IRREGULARS.test(node.value.raw)) { removeWhitespaceError(node); } } }
javascript
function removeInvalidNodeErrorsInTemplateLiteral(node) { if (typeof node.value.raw === "string") { if (ALL_IRREGULARS.test(node.value.raw)) { removeWhitespaceError(node); } } }
[ "function", "removeInvalidNodeErrorsInTemplateLiteral", "(", "node", ")", "{", "if", "(", "typeof", "node", ".", "value", ".", "raw", "===", "\"string\"", ")", "{", "if", "(", "ALL_IRREGULARS", ".", "test", "(", "node", ".", "value", ".", "raw", ")", ")", "{", "removeWhitespaceError", "(", "node", ")", ";", "}", "}", "}" ]
Checks template string literal nodes for errors that we are choosing to ignore and calls the relevant methods to remove the errors @param {ASTNode} node to check for matching errors. @returns {void} @private
[ "Checks", "template", "string", "literal", "nodes", "for", "errors", "that", "we", "are", "choosing", "to", "ignore", "and", "calls", "the", "relevant", "methods", "to", "remove", "the", "errors" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-irregular-whitespace.js#L125-L131
train
eslint/eslint
lib/rules/no-irregular-whitespace.js
checkForIrregularWhitespace
function checkForIrregularWhitespace(node) { const sourceLines = sourceCode.lines; sourceLines.forEach((sourceLine, lineIndex) => { const lineNumber = lineIndex + 1; let match; while ((match = IRREGULAR_WHITESPACE.exec(sourceLine)) !== null) { const location = { line: lineNumber, column: match.index }; errors.push({ node, message: "Irregular whitespace not allowed.", loc: location }); } }); }
javascript
function checkForIrregularWhitespace(node) { const sourceLines = sourceCode.lines; sourceLines.forEach((sourceLine, lineIndex) => { const lineNumber = lineIndex + 1; let match; while ((match = IRREGULAR_WHITESPACE.exec(sourceLine)) !== null) { const location = { line: lineNumber, column: match.index }; errors.push({ node, message: "Irregular whitespace not allowed.", loc: location }); } }); }
[ "function", "checkForIrregularWhitespace", "(", "node", ")", "{", "const", "sourceLines", "=", "sourceCode", ".", "lines", ";", "sourceLines", ".", "forEach", "(", "(", "sourceLine", ",", "lineIndex", ")", "=>", "{", "const", "lineNumber", "=", "lineIndex", "+", "1", ";", "let", "match", ";", "while", "(", "(", "match", "=", "IRREGULAR_WHITESPACE", ".", "exec", "(", "sourceLine", ")", ")", "!==", "null", ")", "{", "const", "location", "=", "{", "line", ":", "lineNumber", ",", "column", ":", "match", ".", "index", "}", ";", "errors", ".", "push", "(", "{", "node", ",", "message", ":", "\"Irregular whitespace not allowed.\"", ",", "loc", ":", "location", "}", ")", ";", "}", "}", ")", ";", "}" ]
Checks the program source for irregular whitespace @param {ASTNode} node The program node @returns {void} @private
[ "Checks", "the", "program", "source", "for", "irregular", "whitespace" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-irregular-whitespace.js#L151-L167
train
eslint/eslint
lib/rules/no-irregular-whitespace.js
checkForIrregularLineTerminators
function checkForIrregularLineTerminators(node) { const source = sourceCode.getText(), sourceLines = sourceCode.lines, linebreaks = source.match(LINE_BREAK); let lastLineIndex = -1, match; while ((match = IRREGULAR_LINE_TERMINATORS.exec(source)) !== null) { const lineIndex = linebreaks.indexOf(match[0], lastLineIndex + 1) || 0; const location = { line: lineIndex + 1, column: sourceLines[lineIndex].length }; errors.push({ node, message: "Irregular whitespace not allowed.", loc: location }); lastLineIndex = lineIndex; } }
javascript
function checkForIrregularLineTerminators(node) { const source = sourceCode.getText(), sourceLines = sourceCode.lines, linebreaks = source.match(LINE_BREAK); let lastLineIndex = -1, match; while ((match = IRREGULAR_LINE_TERMINATORS.exec(source)) !== null) { const lineIndex = linebreaks.indexOf(match[0], lastLineIndex + 1) || 0; const location = { line: lineIndex + 1, column: sourceLines[lineIndex].length }; errors.push({ node, message: "Irregular whitespace not allowed.", loc: location }); lastLineIndex = lineIndex; } }
[ "function", "checkForIrregularLineTerminators", "(", "node", ")", "{", "const", "source", "=", "sourceCode", ".", "getText", "(", ")", ",", "sourceLines", "=", "sourceCode", ".", "lines", ",", "linebreaks", "=", "source", ".", "match", "(", "LINE_BREAK", ")", ";", "let", "lastLineIndex", "=", "-", "1", ",", "match", ";", "while", "(", "(", "match", "=", "IRREGULAR_LINE_TERMINATORS", ".", "exec", "(", "source", ")", ")", "!==", "null", ")", "{", "const", "lineIndex", "=", "linebreaks", ".", "indexOf", "(", "match", "[", "0", "]", ",", "lastLineIndex", "+", "1", ")", "||", "0", ";", "const", "location", "=", "{", "line", ":", "lineIndex", "+", "1", ",", "column", ":", "sourceLines", "[", "lineIndex", "]", ".", "length", "}", ";", "errors", ".", "push", "(", "{", "node", ",", "message", ":", "\"Irregular whitespace not allowed.\"", ",", "loc", ":", "location", "}", ")", ";", "lastLineIndex", "=", "lineIndex", ";", "}", "}" ]
Checks the program source for irregular line terminators @param {ASTNode} node The program node @returns {void} @private
[ "Checks", "the", "program", "source", "for", "irregular", "line", "terminators" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-irregular-whitespace.js#L175-L192
train
eslint/eslint
lib/rules/indent-legacy.js
getNodeIndent
function getNodeIndent(node, byLastLine) { const token = byLastLine ? sourceCode.getLastToken(node) : sourceCode.getFirstToken(node); const srcCharsBeforeNode = sourceCode.getText(token, token.loc.start.column).split(""); const indentChars = srcCharsBeforeNode.slice(0, srcCharsBeforeNode.findIndex(char => char !== " " && char !== "\t")); const spaces = indentChars.filter(char => char === " ").length; const tabs = indentChars.filter(char => char === "\t").length; return { space: spaces, tab: tabs, goodChar: indentType === "space" ? spaces : tabs, badChar: indentType === "space" ? tabs : spaces }; }
javascript
function getNodeIndent(node, byLastLine) { const token = byLastLine ? sourceCode.getLastToken(node) : sourceCode.getFirstToken(node); const srcCharsBeforeNode = sourceCode.getText(token, token.loc.start.column).split(""); const indentChars = srcCharsBeforeNode.slice(0, srcCharsBeforeNode.findIndex(char => char !== " " && char !== "\t")); const spaces = indentChars.filter(char => char === " ").length; const tabs = indentChars.filter(char => char === "\t").length; return { space: spaces, tab: tabs, goodChar: indentType === "space" ? spaces : tabs, badChar: indentType === "space" ? tabs : spaces }; }
[ "function", "getNodeIndent", "(", "node", ",", "byLastLine", ")", "{", "const", "token", "=", "byLastLine", "?", "sourceCode", ".", "getLastToken", "(", "node", ")", ":", "sourceCode", ".", "getFirstToken", "(", "node", ")", ";", "const", "srcCharsBeforeNode", "=", "sourceCode", ".", "getText", "(", "token", ",", "token", ".", "loc", ".", "start", ".", "column", ")", ".", "split", "(", "\"\"", ")", ";", "const", "indentChars", "=", "srcCharsBeforeNode", ".", "slice", "(", "0", ",", "srcCharsBeforeNode", ".", "findIndex", "(", "char", "=>", "char", "!==", "\" \"", "&&", "char", "!==", "\"\\t\"", ")", ")", ";", "\\t", "const", "spaces", "=", "indentChars", ".", "filter", "(", "char", "=>", "char", "===", "\" \"", ")", ".", "length", ";", "const", "tabs", "=", "indentChars", ".", "filter", "(", "char", "=>", "char", "===", "\"\\t\"", ")", ".", "\\t", ";", "}" ]
Get the actual indent of node @param {ASTNode|Token} node Node to examine @param {boolean} [byLastLine=false] get indent of node's last line @returns {Object} The node's indent. Contains keys `space` and `tab`, representing the indent of each character. Also contains keys `goodChar` and `badChar`, where `goodChar` is the amount of the user's desired indentation character, and `badChar` is the amount of the other indentation character.
[ "Get", "the", "actual", "indent", "of", "node" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L340-L353
train
eslint/eslint
lib/rules/indent-legacy.js
checkNodeIndent
function checkNodeIndent(node, neededIndent) { const actualIndent = getNodeIndent(node, false); if ( node.type !== "ArrayExpression" && node.type !== "ObjectExpression" && (actualIndent.goodChar !== neededIndent || actualIndent.badChar !== 0) && isNodeFirstInLine(node) ) { report(node, neededIndent, actualIndent.space, actualIndent.tab); } if (node.type === "IfStatement" && node.alternate) { const elseToken = sourceCode.getTokenBefore(node.alternate); checkNodeIndent(elseToken, neededIndent); if (!isNodeFirstInLine(node.alternate)) { checkNodeIndent(node.alternate, neededIndent); } } if (node.type === "TryStatement" && node.handler) { const catchToken = sourceCode.getFirstToken(node.handler); checkNodeIndent(catchToken, neededIndent); } if (node.type === "TryStatement" && node.finalizer) { const finallyToken = sourceCode.getTokenBefore(node.finalizer); checkNodeIndent(finallyToken, neededIndent); } if (node.type === "DoWhileStatement") { const whileToken = sourceCode.getTokenAfter(node.body); checkNodeIndent(whileToken, neededIndent); } }
javascript
function checkNodeIndent(node, neededIndent) { const actualIndent = getNodeIndent(node, false); if ( node.type !== "ArrayExpression" && node.type !== "ObjectExpression" && (actualIndent.goodChar !== neededIndent || actualIndent.badChar !== 0) && isNodeFirstInLine(node) ) { report(node, neededIndent, actualIndent.space, actualIndent.tab); } if (node.type === "IfStatement" && node.alternate) { const elseToken = sourceCode.getTokenBefore(node.alternate); checkNodeIndent(elseToken, neededIndent); if (!isNodeFirstInLine(node.alternate)) { checkNodeIndent(node.alternate, neededIndent); } } if (node.type === "TryStatement" && node.handler) { const catchToken = sourceCode.getFirstToken(node.handler); checkNodeIndent(catchToken, neededIndent); } if (node.type === "TryStatement" && node.finalizer) { const finallyToken = sourceCode.getTokenBefore(node.finalizer); checkNodeIndent(finallyToken, neededIndent); } if (node.type === "DoWhileStatement") { const whileToken = sourceCode.getTokenAfter(node.body); checkNodeIndent(whileToken, neededIndent); } }
[ "function", "checkNodeIndent", "(", "node", ",", "neededIndent", ")", "{", "const", "actualIndent", "=", "getNodeIndent", "(", "node", ",", "false", ")", ";", "if", "(", "node", ".", "type", "!==", "\"ArrayExpression\"", "&&", "node", ".", "type", "!==", "\"ObjectExpression\"", "&&", "(", "actualIndent", ".", "goodChar", "!==", "neededIndent", "||", "actualIndent", ".", "badChar", "!==", "0", ")", "&&", "isNodeFirstInLine", "(", "node", ")", ")", "{", "report", "(", "node", ",", "neededIndent", ",", "actualIndent", ".", "space", ",", "actualIndent", ".", "tab", ")", ";", "}", "if", "(", "node", ".", "type", "===", "\"IfStatement\"", "&&", "node", ".", "alternate", ")", "{", "const", "elseToken", "=", "sourceCode", ".", "getTokenBefore", "(", "node", ".", "alternate", ")", ";", "checkNodeIndent", "(", "elseToken", ",", "neededIndent", ")", ";", "if", "(", "!", "isNodeFirstInLine", "(", "node", ".", "alternate", ")", ")", "{", "checkNodeIndent", "(", "node", ".", "alternate", ",", "neededIndent", ")", ";", "}", "}", "if", "(", "node", ".", "type", "===", "\"TryStatement\"", "&&", "node", ".", "handler", ")", "{", "const", "catchToken", "=", "sourceCode", ".", "getFirstToken", "(", "node", ".", "handler", ")", ";", "checkNodeIndent", "(", "catchToken", ",", "neededIndent", ")", ";", "}", "if", "(", "node", ".", "type", "===", "\"TryStatement\"", "&&", "node", ".", "finalizer", ")", "{", "const", "finallyToken", "=", "sourceCode", ".", "getTokenBefore", "(", "node", ".", "finalizer", ")", ";", "checkNodeIndent", "(", "finallyToken", ",", "neededIndent", ")", ";", "}", "if", "(", "node", ".", "type", "===", "\"DoWhileStatement\"", ")", "{", "const", "whileToken", "=", "sourceCode", ".", "getTokenAfter", "(", "node", ".", "body", ")", ";", "checkNodeIndent", "(", "whileToken", ",", "neededIndent", ")", ";", "}", "}" ]
Check indent for node @param {ASTNode} node Node to check @param {int} neededIndent needed indent @returns {void}
[ "Check", "indent", "for", "node" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L375-L414
train
eslint/eslint
lib/rules/indent-legacy.js
checkLastNodeLineIndent
function checkLastNodeLineIndent(node, lastLineIndent) { const lastToken = sourceCode.getLastToken(node); const endIndent = getNodeIndent(lastToken, true); if ((endIndent.goodChar !== lastLineIndent || endIndent.badChar !== 0) && isNodeFirstInLine(node, true)) { report( node, lastLineIndent, endIndent.space, endIndent.tab, { line: lastToken.loc.start.line, column: lastToken.loc.start.column }, true ); } }
javascript
function checkLastNodeLineIndent(node, lastLineIndent) { const lastToken = sourceCode.getLastToken(node); const endIndent = getNodeIndent(lastToken, true); if ((endIndent.goodChar !== lastLineIndent || endIndent.badChar !== 0) && isNodeFirstInLine(node, true)) { report( node, lastLineIndent, endIndent.space, endIndent.tab, { line: lastToken.loc.start.line, column: lastToken.loc.start.column }, true ); } }
[ "function", "checkLastNodeLineIndent", "(", "node", ",", "lastLineIndent", ")", "{", "const", "lastToken", "=", "sourceCode", ".", "getLastToken", "(", "node", ")", ";", "const", "endIndent", "=", "getNodeIndent", "(", "lastToken", ",", "true", ")", ";", "if", "(", "(", "endIndent", ".", "goodChar", "!==", "lastLineIndent", "||", "endIndent", ".", "badChar", "!==", "0", ")", "&&", "isNodeFirstInLine", "(", "node", ",", "true", ")", ")", "{", "report", "(", "node", ",", "lastLineIndent", ",", "endIndent", ".", "space", ",", "endIndent", ".", "tab", ",", "{", "line", ":", "lastToken", ".", "loc", ".", "start", ".", "line", ",", "column", ":", "lastToken", ".", "loc", ".", "start", ".", "column", "}", ",", "true", ")", ";", "}", "}" ]
Check last node line indent this detects, that block closed correctly @param {ASTNode} node Node to examine @param {int} lastLineIndent needed indent @returns {void}
[ "Check", "last", "node", "line", "indent", "this", "detects", "that", "block", "closed", "correctly" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L432-L446
train
eslint/eslint
lib/rules/indent-legacy.js
checkLastReturnStatementLineIndent
function checkLastReturnStatementLineIndent(node, firstLineIndent) { /* * in case if return statement ends with ');' we have traverse back to ')' * otherwise we'll measure indent for ';' and replace ')' */ const lastToken = sourceCode.getLastToken(node, astUtils.isClosingParenToken); const textBeforeClosingParenthesis = sourceCode.getText(lastToken, lastToken.loc.start.column).slice(0, -1); if (textBeforeClosingParenthesis.trim()) { // There are tokens before the closing paren, don't report this case return; } const endIndent = getNodeIndent(lastToken, true); if (endIndent.goodChar !== firstLineIndent) { report( node, firstLineIndent, endIndent.space, endIndent.tab, { line: lastToken.loc.start.line, column: lastToken.loc.start.column }, true ); } }
javascript
function checkLastReturnStatementLineIndent(node, firstLineIndent) { /* * in case if return statement ends with ');' we have traverse back to ')' * otherwise we'll measure indent for ';' and replace ')' */ const lastToken = sourceCode.getLastToken(node, astUtils.isClosingParenToken); const textBeforeClosingParenthesis = sourceCode.getText(lastToken, lastToken.loc.start.column).slice(0, -1); if (textBeforeClosingParenthesis.trim()) { // There are tokens before the closing paren, don't report this case return; } const endIndent = getNodeIndent(lastToken, true); if (endIndent.goodChar !== firstLineIndent) { report( node, firstLineIndent, endIndent.space, endIndent.tab, { line: lastToken.loc.start.line, column: lastToken.loc.start.column }, true ); } }
[ "function", "checkLastReturnStatementLineIndent", "(", "node", ",", "firstLineIndent", ")", "{", "const", "lastToken", "=", "sourceCode", ".", "getLastToken", "(", "node", ",", "astUtils", ".", "isClosingParenToken", ")", ";", "const", "textBeforeClosingParenthesis", "=", "sourceCode", ".", "getText", "(", "lastToken", ",", "lastToken", ".", "loc", ".", "start", ".", "column", ")", ".", "slice", "(", "0", ",", "-", "1", ")", ";", "if", "(", "textBeforeClosingParenthesis", ".", "trim", "(", ")", ")", "{", "return", ";", "}", "const", "endIndent", "=", "getNodeIndent", "(", "lastToken", ",", "true", ")", ";", "if", "(", "endIndent", ".", "goodChar", "!==", "firstLineIndent", ")", "{", "report", "(", "node", ",", "firstLineIndent", ",", "endIndent", ".", "space", ",", "endIndent", ".", "tab", ",", "{", "line", ":", "lastToken", ".", "loc", ".", "start", ".", "line", ",", "column", ":", "lastToken", ".", "loc", ".", "start", ".", "column", "}", ",", "true", ")", ";", "}", "}" ]
Check last node line indent this detects, that block closed correctly This function for more complicated return statement case, where closing parenthesis may be followed by ';' @param {ASTNode} node Node to examine @param {int} firstLineIndent first line needed indent @returns {void}
[ "Check", "last", "node", "line", "indent", "this", "detects", "that", "block", "closed", "correctly", "This", "function", "for", "more", "complicated", "return", "statement", "case", "where", "closing", "parenthesis", "may", "be", "followed", "by", ";" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L455-L482
train
eslint/eslint
lib/rules/indent-legacy.js
checkFirstNodeLineIndent
function checkFirstNodeLineIndent(node, firstLineIndent) { const startIndent = getNodeIndent(node, false); if ((startIndent.goodChar !== firstLineIndent || startIndent.badChar !== 0) && isNodeFirstInLine(node)) { report( node, firstLineIndent, startIndent.space, startIndent.tab, { line: node.loc.start.line, column: node.loc.start.column } ); } }
javascript
function checkFirstNodeLineIndent(node, firstLineIndent) { const startIndent = getNodeIndent(node, false); if ((startIndent.goodChar !== firstLineIndent || startIndent.badChar !== 0) && isNodeFirstInLine(node)) { report( node, firstLineIndent, startIndent.space, startIndent.tab, { line: node.loc.start.line, column: node.loc.start.column } ); } }
[ "function", "checkFirstNodeLineIndent", "(", "node", ",", "firstLineIndent", ")", "{", "const", "startIndent", "=", "getNodeIndent", "(", "node", ",", "false", ")", ";", "if", "(", "(", "startIndent", ".", "goodChar", "!==", "firstLineIndent", "||", "startIndent", ".", "badChar", "!==", "0", ")", "&&", "isNodeFirstInLine", "(", "node", ")", ")", "{", "report", "(", "node", ",", "firstLineIndent", ",", "startIndent", ".", "space", ",", "startIndent", ".", "tab", ",", "{", "line", ":", "node", ".", "loc", ".", "start", ".", "line", ",", "column", ":", "node", ".", "loc", ".", "start", ".", "column", "}", ")", ";", "}", "}" ]
Check first node line indent is correct @param {ASTNode} node Node to examine @param {int} firstLineIndent needed indent @returns {void}
[ "Check", "first", "node", "line", "indent", "is", "correct" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L490-L502
train
eslint/eslint
lib/rules/indent-legacy.js
getParentNodeByType
function getParentNodeByType(node, type, stopAtList) { let parent = node.parent; const stopAtSet = new Set(stopAtList || ["Program"]); while (parent.type !== type && !stopAtSet.has(parent.type) && parent.type !== "Program") { parent = parent.parent; } return parent.type === type ? parent : null; }
javascript
function getParentNodeByType(node, type, stopAtList) { let parent = node.parent; const stopAtSet = new Set(stopAtList || ["Program"]); while (parent.type !== type && !stopAtSet.has(parent.type) && parent.type !== "Program") { parent = parent.parent; } return parent.type === type ? parent : null; }
[ "function", "getParentNodeByType", "(", "node", ",", "type", ",", "stopAtList", ")", "{", "let", "parent", "=", "node", ".", "parent", ";", "const", "stopAtSet", "=", "new", "Set", "(", "stopAtList", "||", "[", "\"Program\"", "]", ")", ";", "while", "(", "parent", ".", "type", "!==", "type", "&&", "!", "stopAtSet", ".", "has", "(", "parent", ".", "type", ")", "&&", "parent", ".", "type", "!==", "\"Program\"", ")", "{", "parent", "=", "parent", ".", "parent", ";", "}", "return", "parent", ".", "type", "===", "type", "?", "parent", ":", "null", ";", "}" ]
Returns a parent node of given node based on a specified type if not present then return null @param {ASTNode} node node to examine @param {string} type type that is being looked for @param {string} stopAtList end points for the evaluating code @returns {ASTNode|void} if found then node otherwise null
[ "Returns", "a", "parent", "node", "of", "given", "node", "based", "on", "a", "specified", "type", "if", "not", "present", "then", "return", "null" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L512-L521
train
eslint/eslint
lib/rules/indent-legacy.js
isNodeInVarOnTop
function isNodeInVarOnTop(node, varNode) { return varNode && varNode.parent.loc.start.line === node.loc.start.line && varNode.parent.declarations.length > 1; }
javascript
function isNodeInVarOnTop(node, varNode) { return varNode && varNode.parent.loc.start.line === node.loc.start.line && varNode.parent.declarations.length > 1; }
[ "function", "isNodeInVarOnTop", "(", "node", ",", "varNode", ")", "{", "return", "varNode", "&&", "varNode", ".", "parent", ".", "loc", ".", "start", ".", "line", "===", "node", ".", "loc", ".", "start", ".", "line", "&&", "varNode", ".", "parent", ".", "declarations", ".", "length", ">", "1", ";", "}" ]
Check to see if the node is part of the multi-line variable declaration. Also if its on the same line as the varNode @param {ASTNode} node node to check @param {ASTNode} varNode variable declaration node to check against @returns {boolean} True if all the above condition satisfy
[ "Check", "to", "see", "if", "the", "node", "is", "part", "of", "the", "multi", "-", "line", "variable", "declaration", ".", "Also", "if", "its", "on", "the", "same", "line", "as", "the", "varNode" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L540-L544
train
eslint/eslint
lib/rules/indent-legacy.js
isArgBeforeCalleeNodeMultiline
function isArgBeforeCalleeNodeMultiline(node) { const parent = node.parent; if (parent.arguments.length >= 2 && parent.arguments[1] === node) { return parent.arguments[0].loc.end.line > parent.arguments[0].loc.start.line; } return false; }
javascript
function isArgBeforeCalleeNodeMultiline(node) { const parent = node.parent; if (parent.arguments.length >= 2 && parent.arguments[1] === node) { return parent.arguments[0].loc.end.line > parent.arguments[0].loc.start.line; } return false; }
[ "function", "isArgBeforeCalleeNodeMultiline", "(", "node", ")", "{", "const", "parent", "=", "node", ".", "parent", ";", "if", "(", "parent", ".", "arguments", ".", "length", ">=", "2", "&&", "parent", ".", "arguments", "[", "1", "]", "===", "node", ")", "{", "return", "parent", ".", "arguments", "[", "0", "]", ".", "loc", ".", "end", ".", "line", ">", "parent", ".", "arguments", "[", "0", "]", ".", "loc", ".", "start", ".", "line", ";", "}", "return", "false", ";", "}" ]
Check to see if the argument before the callee node is multi-line and there should only be 1 argument before the callee node @param {ASTNode} node node to check @returns {boolean} True if arguments are multi-line
[ "Check", "to", "see", "if", "the", "argument", "before", "the", "callee", "node", "is", "multi", "-", "line", "and", "there", "should", "only", "be", "1", "argument", "before", "the", "callee", "node" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L552-L560
train
eslint/eslint
lib/rules/indent-legacy.js
filterOutSameLineVars
function filterOutSameLineVars(node) { return node.declarations.reduce((finalCollection, elem) => { const lastElem = finalCollection[finalCollection.length - 1]; if ((elem.loc.start.line !== node.loc.start.line && !lastElem) || (lastElem && lastElem.loc.start.line !== elem.loc.start.line)) { finalCollection.push(elem); } return finalCollection; }, []); }
javascript
function filterOutSameLineVars(node) { return node.declarations.reduce((finalCollection, elem) => { const lastElem = finalCollection[finalCollection.length - 1]; if ((elem.loc.start.line !== node.loc.start.line && !lastElem) || (lastElem && lastElem.loc.start.line !== elem.loc.start.line)) { finalCollection.push(elem); } return finalCollection; }, []); }
[ "function", "filterOutSameLineVars", "(", "node", ")", "{", "return", "node", ".", "declarations", ".", "reduce", "(", "(", "finalCollection", ",", "elem", ")", "=>", "{", "const", "lastElem", "=", "finalCollection", "[", "finalCollection", ".", "length", "-", "1", "]", ";", "if", "(", "(", "elem", ".", "loc", ".", "start", ".", "line", "!==", "node", ".", "loc", ".", "start", ".", "line", "&&", "!", "lastElem", ")", "||", "(", "lastElem", "&&", "lastElem", ".", "loc", ".", "start", ".", "line", "!==", "elem", ".", "loc", ".", "start", ".", "line", ")", ")", "{", "finalCollection", ".", "push", "(", "elem", ")", ";", "}", "return", "finalCollection", ";", "}", ",", "[", "]", ")", ";", "}" ]
Filter out the elements which are on the same line of each other or the node. basically have only 1 elements from each line except the variable declaration line. @param {ASTNode} node Variable declaration node @returns {ASTNode[]} Filtered elements
[ "Filter", "out", "the", "elements", "which", "are", "on", "the", "same", "line", "of", "each", "other", "or", "the", "node", ".", "basically", "have", "only", "1", "elements", "from", "each", "line", "except", "the", "variable", "declaration", "line", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/indent-legacy.js#L889-L900
train
eslint/eslint
lib/rules/prefer-template.js
getTopConcatBinaryExpression
function getTopConcatBinaryExpression(node) { let currentNode = node; while (isConcatenation(currentNode.parent)) { currentNode = currentNode.parent; } return currentNode; }
javascript
function getTopConcatBinaryExpression(node) { let currentNode = node; while (isConcatenation(currentNode.parent)) { currentNode = currentNode.parent; } return currentNode; }
[ "function", "getTopConcatBinaryExpression", "(", "node", ")", "{", "let", "currentNode", "=", "node", ";", "while", "(", "isConcatenation", "(", "currentNode", ".", "parent", ")", ")", "{", "currentNode", "=", "currentNode", ".", "parent", ";", "}", "return", "currentNode", ";", "}" ]
Gets the top binary expression node for concatenation in parents of a given node. @param {ASTNode} node - A node to get. @returns {ASTNode} the top binary expression node in parents of a given node.
[ "Gets", "the", "top", "binary", "expression", "node", "for", "concatenation", "in", "parents", "of", "a", "given", "node", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L32-L39
train
eslint/eslint
lib/rules/prefer-template.js
isOctalEscapeSequence
function isOctalEscapeSequence(node) { // No need to check TemplateLiterals – would throw error with octal escape const isStringLiteral = node.type === "Literal" && typeof node.value === "string"; if (!isStringLiteral) { return false; } const match = node.raw.match(/^([^\\]|\\[^0-7])*\\([0-7]{1,3})/u); if (match) { // \0 is actually not considered an octal if (match[2] !== "0" || typeof match[3] !== "undefined") { return true; } } return false; }
javascript
function isOctalEscapeSequence(node) { // No need to check TemplateLiterals – would throw error with octal escape const isStringLiteral = node.type === "Literal" && typeof node.value === "string"; if (!isStringLiteral) { return false; } const match = node.raw.match(/^([^\\]|\\[^0-7])*\\([0-7]{1,3})/u); if (match) { // \0 is actually not considered an octal if (match[2] !== "0" || typeof match[3] !== "undefined") { return true; } } return false; }
[ "function", "isOctalEscapeSequence", "(", "node", ")", "{", "const", "isStringLiteral", "=", "node", ".", "type", "===", "\"Literal\"", "&&", "typeof", "node", ".", "value", "===", "\"string\"", ";", "if", "(", "!", "isStringLiteral", ")", "{", "return", "false", ";", "}", "const", "match", "=", "node", ".", "raw", ".", "match", "(", "/", "^([^\\\\]|\\\\[^0-7])*\\\\([0-7]{1,3})", "/", "u", ")", ";", "if", "(", "match", ")", "{", "if", "(", "match", "[", "2", "]", "!==", "\"0\"", "||", "typeof", "match", "[", "3", "]", "!==", "\"undefined\"", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Determines whether a given node is a octal escape sequence @param {ASTNode} node A node to check @returns {boolean} `true` if the node is an octal escape sequence
[ "Determines", "whether", "a", "given", "node", "is", "a", "octal", "escape", "sequence" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L46-L65
train
eslint/eslint
lib/rules/prefer-template.js
hasOctalEscapeSequence
function hasOctalEscapeSequence(node) { if (isConcatenation(node)) { return hasOctalEscapeSequence(node.left) || hasOctalEscapeSequence(node.right); } return isOctalEscapeSequence(node); }
javascript
function hasOctalEscapeSequence(node) { if (isConcatenation(node)) { return hasOctalEscapeSequence(node.left) || hasOctalEscapeSequence(node.right); } return isOctalEscapeSequence(node); }
[ "function", "hasOctalEscapeSequence", "(", "node", ")", "{", "if", "(", "isConcatenation", "(", "node", ")", ")", "{", "return", "hasOctalEscapeSequence", "(", "node", ".", "left", ")", "||", "hasOctalEscapeSequence", "(", "node", ".", "right", ")", ";", "}", "return", "isOctalEscapeSequence", "(", "node", ")", ";", "}" ]
Checks whether or not a node contains a octal escape sequence @param {ASTNode} node A node to check @returns {boolean} `true` if the node contains an octal escape sequence
[ "Checks", "whether", "or", "not", "a", "node", "contains", "a", "octal", "escape", "sequence" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L72-L78
train
eslint/eslint
lib/rules/prefer-template.js
hasStringLiteral
function hasStringLiteral(node) { if (isConcatenation(node)) { // `left` is deeper than `right` normally. return hasStringLiteral(node.right) || hasStringLiteral(node.left); } return astUtils.isStringLiteral(node); }
javascript
function hasStringLiteral(node) { if (isConcatenation(node)) { // `left` is deeper than `right` normally. return hasStringLiteral(node.right) || hasStringLiteral(node.left); } return astUtils.isStringLiteral(node); }
[ "function", "hasStringLiteral", "(", "node", ")", "{", "if", "(", "isConcatenation", "(", "node", ")", ")", "{", "return", "hasStringLiteral", "(", "node", ".", "right", ")", "||", "hasStringLiteral", "(", "node", ".", "left", ")", ";", "}", "return", "astUtils", ".", "isStringLiteral", "(", "node", ")", ";", "}" ]
Checks whether or not a given binary expression has string literals. @param {ASTNode} node - A node to check. @returns {boolean} `true` if the node has string literals.
[ "Checks", "whether", "or", "not", "a", "given", "binary", "expression", "has", "string", "literals", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L85-L92
train
eslint/eslint
lib/rules/prefer-template.js
hasNonStringLiteral
function hasNonStringLiteral(node) { if (isConcatenation(node)) { // `left` is deeper than `right` normally. return hasNonStringLiteral(node.right) || hasNonStringLiteral(node.left); } return !astUtils.isStringLiteral(node); }
javascript
function hasNonStringLiteral(node) { if (isConcatenation(node)) { // `left` is deeper than `right` normally. return hasNonStringLiteral(node.right) || hasNonStringLiteral(node.left); } return !astUtils.isStringLiteral(node); }
[ "function", "hasNonStringLiteral", "(", "node", ")", "{", "if", "(", "isConcatenation", "(", "node", ")", ")", "{", "return", "hasNonStringLiteral", "(", "node", ".", "right", ")", "||", "hasNonStringLiteral", "(", "node", ".", "left", ")", ";", "}", "return", "!", "astUtils", ".", "isStringLiteral", "(", "node", ")", ";", "}" ]
Checks whether or not a given binary expression has non string literals. @param {ASTNode} node - A node to check. @returns {boolean} `true` if the node has non string literals.
[ "Checks", "whether", "or", "not", "a", "given", "binary", "expression", "has", "non", "string", "literals", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L99-L106
train
eslint/eslint
lib/rules/prefer-template.js
getTextBetween
function getTextBetween(node1, node2) { const allTokens = [node1].concat(sourceCode.getTokensBetween(node1, node2)).concat(node2); const sourceText = sourceCode.getText(); return allTokens.slice(0, -1).reduce((accumulator, token, index) => accumulator + sourceText.slice(token.range[1], allTokens[index + 1].range[0]), ""); }
javascript
function getTextBetween(node1, node2) { const allTokens = [node1].concat(sourceCode.getTokensBetween(node1, node2)).concat(node2); const sourceText = sourceCode.getText(); return allTokens.slice(0, -1).reduce((accumulator, token, index) => accumulator + sourceText.slice(token.range[1], allTokens[index + 1].range[0]), ""); }
[ "function", "getTextBetween", "(", "node1", ",", "node2", ")", "{", "const", "allTokens", "=", "[", "node1", "]", ".", "concat", "(", "sourceCode", ".", "getTokensBetween", "(", "node1", ",", "node2", ")", ")", ".", "concat", "(", "node2", ")", ";", "const", "sourceText", "=", "sourceCode", ".", "getText", "(", ")", ";", "return", "allTokens", ".", "slice", "(", "0", ",", "-", "1", ")", ".", "reduce", "(", "(", "accumulator", ",", "token", ",", "index", ")", "=>", "accumulator", "+", "sourceText", ".", "slice", "(", "token", ".", "range", "[", "1", "]", ",", "allTokens", "[", "index", "+", "1", "]", ".", "range", "[", "0", "]", ")", ",", "\"\"", ")", ";", "}" ]
Gets the non-token text between two nodes, ignoring any other tokens that appear between the two tokens. @param {ASTNode} node1 The first node @param {ASTNode} node2 The second node @returns {string} The text between the nodes, excluding other tokens
[ "Gets", "the", "non", "-", "token", "text", "between", "two", "nodes", "ignoring", "any", "other", "tokens", "that", "appear", "between", "the", "two", "tokens", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L167-L172
train
eslint/eslint
lib/rules/prefer-template.js
getTemplateLiteral
function getTemplateLiteral(currentNode, textBeforeNode, textAfterNode) { if (currentNode.type === "Literal" && typeof currentNode.value === "string") { /* * If the current node is a string literal, escape any instances of ${ or ` to prevent them from being interpreted * as a template placeholder. However, if the code already contains a backslash before the ${ or ` * for some reason, don't add another backslash, because that would change the meaning of the code (it would cause * an actual backslash character to appear before the dollar sign). */ return `\`${currentNode.raw.slice(1, -1).replace(/\\*(\$\{|`)/gu, matched => { if (matched.lastIndexOf("\\") % 2) { return `\\${matched}`; } return matched; // Unescape any quotes that appear in the original Literal that no longer need to be escaped. }).replace(new RegExp(`\\\\${currentNode.raw[0]}`, "gu"), currentNode.raw[0])}\``; } if (currentNode.type === "TemplateLiteral") { return sourceCode.getText(currentNode); } if (isConcatenation(currentNode) && hasStringLiteral(currentNode) && hasNonStringLiteral(currentNode)) { const plusSign = sourceCode.getFirstTokenBetween(currentNode.left, currentNode.right, token => token.value === "+"); const textBeforePlus = getTextBetween(currentNode.left, plusSign); const textAfterPlus = getTextBetween(plusSign, currentNode.right); const leftEndsWithCurly = endsWithTemplateCurly(currentNode.left); const rightStartsWithCurly = startsWithTemplateCurly(currentNode.right); if (leftEndsWithCurly) { // If the left side of the expression ends with a template curly, add the extra text to the end of the curly bracket. // `foo${bar}` /* comment */ + 'baz' --> `foo${bar /* comment */ }${baz}` return getTemplateLiteral(currentNode.left, textBeforeNode, textBeforePlus + textAfterPlus).slice(0, -1) + getTemplateLiteral(currentNode.right, null, textAfterNode).slice(1); } if (rightStartsWithCurly) { // Otherwise, if the right side of the expression starts with a template curly, add the text there. // 'foo' /* comment */ + `${bar}baz` --> `foo${ /* comment */ bar}baz` return getTemplateLiteral(currentNode.left, textBeforeNode, null).slice(0, -1) + getTemplateLiteral(currentNode.right, textBeforePlus + textAfterPlus, textAfterNode).slice(1); } /* * Otherwise, these nodes should not be combined into a template curly, since there is nowhere to put * the text between them. */ return `${getTemplateLiteral(currentNode.left, textBeforeNode, null)}${textBeforePlus}+${textAfterPlus}${getTemplateLiteral(currentNode.right, textAfterNode, null)}`; } return `\`\${${textBeforeNode || ""}${sourceCode.getText(currentNode)}${textAfterNode || ""}}\``; }
javascript
function getTemplateLiteral(currentNode, textBeforeNode, textAfterNode) { if (currentNode.type === "Literal" && typeof currentNode.value === "string") { /* * If the current node is a string literal, escape any instances of ${ or ` to prevent them from being interpreted * as a template placeholder. However, if the code already contains a backslash before the ${ or ` * for some reason, don't add another backslash, because that would change the meaning of the code (it would cause * an actual backslash character to appear before the dollar sign). */ return `\`${currentNode.raw.slice(1, -1).replace(/\\*(\$\{|`)/gu, matched => { if (matched.lastIndexOf("\\") % 2) { return `\\${matched}`; } return matched; // Unescape any quotes that appear in the original Literal that no longer need to be escaped. }).replace(new RegExp(`\\\\${currentNode.raw[0]}`, "gu"), currentNode.raw[0])}\``; } if (currentNode.type === "TemplateLiteral") { return sourceCode.getText(currentNode); } if (isConcatenation(currentNode) && hasStringLiteral(currentNode) && hasNonStringLiteral(currentNode)) { const plusSign = sourceCode.getFirstTokenBetween(currentNode.left, currentNode.right, token => token.value === "+"); const textBeforePlus = getTextBetween(currentNode.left, plusSign); const textAfterPlus = getTextBetween(plusSign, currentNode.right); const leftEndsWithCurly = endsWithTemplateCurly(currentNode.left); const rightStartsWithCurly = startsWithTemplateCurly(currentNode.right); if (leftEndsWithCurly) { // If the left side of the expression ends with a template curly, add the extra text to the end of the curly bracket. // `foo${bar}` /* comment */ + 'baz' --> `foo${bar /* comment */ }${baz}` return getTemplateLiteral(currentNode.left, textBeforeNode, textBeforePlus + textAfterPlus).slice(0, -1) + getTemplateLiteral(currentNode.right, null, textAfterNode).slice(1); } if (rightStartsWithCurly) { // Otherwise, if the right side of the expression starts with a template curly, add the text there. // 'foo' /* comment */ + `${bar}baz` --> `foo${ /* comment */ bar}baz` return getTemplateLiteral(currentNode.left, textBeforeNode, null).slice(0, -1) + getTemplateLiteral(currentNode.right, textBeforePlus + textAfterPlus, textAfterNode).slice(1); } /* * Otherwise, these nodes should not be combined into a template curly, since there is nowhere to put * the text between them. */ return `${getTemplateLiteral(currentNode.left, textBeforeNode, null)}${textBeforePlus}+${textAfterPlus}${getTemplateLiteral(currentNode.right, textAfterNode, null)}`; } return `\`\${${textBeforeNode || ""}${sourceCode.getText(currentNode)}${textAfterNode || ""}}\``; }
[ "function", "getTemplateLiteral", "(", "currentNode", ",", "textBeforeNode", ",", "textAfterNode", ")", "{", "if", "(", "currentNode", ".", "type", "===", "\"Literal\"", "&&", "typeof", "currentNode", ".", "value", "===", "\"string\"", ")", "{", "return", "`", "\\`", "${", "currentNode", ".", "raw", ".", "slice", "(", "1", ",", "-", "1", ")", ".", "replace", "(", "/", "\\\\*(\\$\\{|`)", "/", "gu", ",", "matched", "=>", "{", "if", "(", "matched", ".", "lastIndexOf", "(", "\"\\\\\"", ")", "%", "\\\\", ")", "2", "{", "return", "`", "\\\\", "${", "matched", "}", "`", ";", "}", "}", ")", ".", "return", "matched", ";", "replace", "}", "(", "new", "RegExp", "(", "`", "\\\\", "\\\\", "${", "currentNode", ".", "raw", "[", "0", "]", "}", "`", ",", "\"gu\"", ")", ",", "currentNode", ".", "raw", "[", "0", "]", ")", "`", ";", "}", "\\`", "if", "(", "currentNode", ".", "type", "===", "\"TemplateLiteral\"", ")", "{", "return", "sourceCode", ".", "getText", "(", "currentNode", ")", ";", "}", "if", "(", "isConcatenation", "(", "currentNode", ")", "&&", "hasStringLiteral", "(", "currentNode", ")", "&&", "hasNonStringLiteral", "(", "currentNode", ")", ")", "{", "const", "plusSign", "=", "sourceCode", ".", "getFirstTokenBetween", "(", "currentNode", ".", "left", ",", "currentNode", ".", "right", ",", "token", "=>", "token", ".", "value", "===", "\"+\"", ")", ";", "const", "textBeforePlus", "=", "getTextBetween", "(", "currentNode", ".", "left", ",", "plusSign", ")", ";", "const", "textAfterPlus", "=", "getTextBetween", "(", "plusSign", ",", "currentNode", ".", "right", ")", ";", "const", "leftEndsWithCurly", "=", "endsWithTemplateCurly", "(", "currentNode", ".", "left", ")", ";", "const", "rightStartsWithCurly", "=", "startsWithTemplateCurly", "(", "currentNode", ".", "right", ")", ";", "if", "(", "leftEndsWithCurly", ")", "{", "return", "getTemplateLiteral", "(", "currentNode", ".", "left", ",", "textBeforeNode", ",", "textBeforePlus", "+", "textAfterPlus", ")", ".", "slice", "(", "0", ",", "-", "1", ")", "+", "getTemplateLiteral", "(", "currentNode", ".", "right", ",", "null", ",", "textAfterNode", ")", ".", "slice", "(", "1", ")", ";", "}", "if", "(", "rightStartsWithCurly", ")", "{", "return", "getTemplateLiteral", "(", "currentNode", ".", "left", ",", "textBeforeNode", ",", "null", ")", ".", "slice", "(", "0", ",", "-", "1", ")", "+", "getTemplateLiteral", "(", "currentNode", ".", "right", ",", "textBeforePlus", "+", "textAfterPlus", ",", "textAfterNode", ")", ".", "slice", "(", "1", ")", ";", "}", "return", "`", "${", "getTemplateLiteral", "(", "currentNode", ".", "left", ",", "textBeforeNode", ",", "null", ")", "}", "${", "textBeforePlus", "}", "${", "textAfterPlus", "}", "${", "getTemplateLiteral", "(", "currentNode", ".", "right", ",", "textAfterNode", ",", "null", ")", "}", "`", ";", "}", "}" ]
Returns a template literal form of the given node. @param {ASTNode} currentNode A node that should be converted to a template literal @param {string} textBeforeNode Text that should appear before the node @param {string} textAfterNode Text that should appear after the node @returns {string} A string form of this node, represented as a template literal
[ "Returns", "a", "template", "literal", "form", "of", "the", "given", "node", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L181-L234
train
eslint/eslint
lib/rules/prefer-template.js
fixNonStringBinaryExpression
function fixNonStringBinaryExpression(fixer, node) { const topBinaryExpr = getTopConcatBinaryExpression(node.parent); if (hasOctalEscapeSequence(topBinaryExpr)) { return null; } return fixer.replaceText(topBinaryExpr, getTemplateLiteral(topBinaryExpr, null, null)); }
javascript
function fixNonStringBinaryExpression(fixer, node) { const topBinaryExpr = getTopConcatBinaryExpression(node.parent); if (hasOctalEscapeSequence(topBinaryExpr)) { return null; } return fixer.replaceText(topBinaryExpr, getTemplateLiteral(topBinaryExpr, null, null)); }
[ "function", "fixNonStringBinaryExpression", "(", "fixer", ",", "node", ")", "{", "const", "topBinaryExpr", "=", "getTopConcatBinaryExpression", "(", "node", ".", "parent", ")", ";", "if", "(", "hasOctalEscapeSequence", "(", "topBinaryExpr", ")", ")", "{", "return", "null", ";", "}", "return", "fixer", ".", "replaceText", "(", "topBinaryExpr", ",", "getTemplateLiteral", "(", "topBinaryExpr", ",", "null", ",", "null", ")", ")", ";", "}" ]
Returns a fixer object that converts a non-string binary expression to a template literal @param {SourceCodeFixer} fixer The fixer object @param {ASTNode} node A node that should be converted to a template literal @returns {Object} A fix for this binary expression
[ "Returns", "a", "fixer", "object", "that", "converts", "a", "non", "-", "string", "binary", "expression", "to", "a", "template", "literal" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L242-L250
train
eslint/eslint
lib/rules/prefer-template.js
checkForStringConcat
function checkForStringConcat(node) { if (!astUtils.isStringLiteral(node) || !isConcatenation(node.parent)) { return; } const topBinaryExpr = getTopConcatBinaryExpression(node.parent); // Checks whether or not this node had been checked already. if (done[topBinaryExpr.range[0]]) { return; } done[topBinaryExpr.range[0]] = true; if (hasNonStringLiteral(topBinaryExpr)) { context.report({ node: topBinaryExpr, message: "Unexpected string concatenation.", fix: fixer => fixNonStringBinaryExpression(fixer, node) }); } }
javascript
function checkForStringConcat(node) { if (!astUtils.isStringLiteral(node) || !isConcatenation(node.parent)) { return; } const topBinaryExpr = getTopConcatBinaryExpression(node.parent); // Checks whether or not this node had been checked already. if (done[topBinaryExpr.range[0]]) { return; } done[topBinaryExpr.range[0]] = true; if (hasNonStringLiteral(topBinaryExpr)) { context.report({ node: topBinaryExpr, message: "Unexpected string concatenation.", fix: fixer => fixNonStringBinaryExpression(fixer, node) }); } }
[ "function", "checkForStringConcat", "(", "node", ")", "{", "if", "(", "!", "astUtils", ".", "isStringLiteral", "(", "node", ")", "||", "!", "isConcatenation", "(", "node", ".", "parent", ")", ")", "{", "return", ";", "}", "const", "topBinaryExpr", "=", "getTopConcatBinaryExpression", "(", "node", ".", "parent", ")", ";", "if", "(", "done", "[", "topBinaryExpr", ".", "range", "[", "0", "]", "]", ")", "{", "return", ";", "}", "done", "[", "topBinaryExpr", ".", "range", "[", "0", "]", "]", "=", "true", ";", "if", "(", "hasNonStringLiteral", "(", "topBinaryExpr", ")", ")", "{", "context", ".", "report", "(", "{", "node", ":", "topBinaryExpr", ",", "message", ":", "\"Unexpected string concatenation.\"", ",", "fix", ":", "fixer", "=>", "fixNonStringBinaryExpression", "(", "fixer", ",", "node", ")", "}", ")", ";", "}", "}" ]
Reports if a given node is string concatenation with non string literals. @param {ASTNode} node - A node to check. @returns {void}
[ "Reports", "if", "a", "given", "node", "is", "string", "concatenation", "with", "non", "string", "literals", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-template.js#L258-L278
train
eslint/eslint
lib/rules/no-return-await.js
reportUnnecessaryAwait
function reportUnnecessaryAwait(node) { context.report({ node: context.getSourceCode().getFirstToken(node), loc: node.loc, message }); }
javascript
function reportUnnecessaryAwait(node) { context.report({ node: context.getSourceCode().getFirstToken(node), loc: node.loc, message }); }
[ "function", "reportUnnecessaryAwait", "(", "node", ")", "{", "context", ".", "report", "(", "{", "node", ":", "context", ".", "getSourceCode", "(", ")", ".", "getFirstToken", "(", "node", ")", ",", "loc", ":", "node", ".", "loc", ",", "message", "}", ")", ";", "}" ]
Reports a found unnecessary `await` expression. @param {ASTNode} node The node representing the `await` expression to report @returns {void}
[ "Reports", "a", "found", "unnecessary", "await", "expression", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-return-await.js#L41-L47
train
eslint/eslint
lib/rules/no-self-compare.js
hasSameTokens
function hasSameTokens(nodeA, nodeB) { const tokensA = sourceCode.getTokens(nodeA); const tokensB = sourceCode.getTokens(nodeB); return tokensA.length === tokensB.length && tokensA.every((token, index) => token.type === tokensB[index].type && token.value === tokensB[index].value); }
javascript
function hasSameTokens(nodeA, nodeB) { const tokensA = sourceCode.getTokens(nodeA); const tokensB = sourceCode.getTokens(nodeB); return tokensA.length === tokensB.length && tokensA.every((token, index) => token.type === tokensB[index].type && token.value === tokensB[index].value); }
[ "function", "hasSameTokens", "(", "nodeA", ",", "nodeB", ")", "{", "const", "tokensA", "=", "sourceCode", ".", "getTokens", "(", "nodeA", ")", ";", "const", "tokensB", "=", "sourceCode", ".", "getTokens", "(", "nodeB", ")", ";", "return", "tokensA", ".", "length", "===", "tokensB", ".", "length", "&&", "tokensA", ".", "every", "(", "(", "token", ",", "index", ")", "=>", "token", ".", "type", "===", "tokensB", "[", "index", "]", ".", "type", "&&", "token", ".", "value", "===", "tokensB", "[", "index", "]", ".", "value", ")", ";", "}" ]
Determines whether two nodes are composed of the same tokens. @param {ASTNode} nodeA The first node @param {ASTNode} nodeB The second node @returns {boolean} true if the nodes have identical token representations
[ "Determines", "whether", "two", "nodes", "are", "composed", "of", "the", "same", "tokens", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-self-compare.js#L36-L42
train
eslint/eslint
lib/rules/no-constant-condition.js
isConstant
function isConstant(node, inBooleanPosition) { switch (node.type) { case "Literal": case "ArrowFunctionExpression": case "FunctionExpression": case "ObjectExpression": case "ArrayExpression": return true; case "UnaryExpression": if (node.operator === "void") { return true; } return (node.operator === "typeof" && inBooleanPosition) || isConstant(node.argument, true); case "BinaryExpression": return isConstant(node.left, false) && isConstant(node.right, false) && node.operator !== "in"; case "LogicalExpression": { const isLeftConstant = isConstant(node.left, inBooleanPosition); const isRightConstant = isConstant(node.right, inBooleanPosition); const isLeftShortCircuit = (isLeftConstant && isLogicalIdentity(node.left, node.operator)); const isRightShortCircuit = (isRightConstant && isLogicalIdentity(node.right, node.operator)); return (isLeftConstant && isRightConstant) || ( // in the case of an "OR", we need to know if the right constant value is truthy node.operator === "||" && isRightConstant && node.right.value && ( !node.parent || node.parent.type !== "BinaryExpression" || !(EQUALITY_OPERATORS.includes(node.parent.operator) || RELATIONAL_OPERATORS.includes(node.parent.operator)) ) ) || isLeftShortCircuit || isRightShortCircuit; } case "AssignmentExpression": return (node.operator === "=") && isConstant(node.right, inBooleanPosition); case "SequenceExpression": return isConstant(node.expressions[node.expressions.length - 1], inBooleanPosition); // no default } return false; }
javascript
function isConstant(node, inBooleanPosition) { switch (node.type) { case "Literal": case "ArrowFunctionExpression": case "FunctionExpression": case "ObjectExpression": case "ArrayExpression": return true; case "UnaryExpression": if (node.operator === "void") { return true; } return (node.operator === "typeof" && inBooleanPosition) || isConstant(node.argument, true); case "BinaryExpression": return isConstant(node.left, false) && isConstant(node.right, false) && node.operator !== "in"; case "LogicalExpression": { const isLeftConstant = isConstant(node.left, inBooleanPosition); const isRightConstant = isConstant(node.right, inBooleanPosition); const isLeftShortCircuit = (isLeftConstant && isLogicalIdentity(node.left, node.operator)); const isRightShortCircuit = (isRightConstant && isLogicalIdentity(node.right, node.operator)); return (isLeftConstant && isRightConstant) || ( // in the case of an "OR", we need to know if the right constant value is truthy node.operator === "||" && isRightConstant && node.right.value && ( !node.parent || node.parent.type !== "BinaryExpression" || !(EQUALITY_OPERATORS.includes(node.parent.operator) || RELATIONAL_OPERATORS.includes(node.parent.operator)) ) ) || isLeftShortCircuit || isRightShortCircuit; } case "AssignmentExpression": return (node.operator === "=") && isConstant(node.right, inBooleanPosition); case "SequenceExpression": return isConstant(node.expressions[node.expressions.length - 1], inBooleanPosition); // no default } return false; }
[ "function", "isConstant", "(", "node", ",", "inBooleanPosition", ")", "{", "switch", "(", "node", ".", "type", ")", "{", "case", "\"Literal\"", ":", "case", "\"ArrowFunctionExpression\"", ":", "case", "\"FunctionExpression\"", ":", "case", "\"ObjectExpression\"", ":", "case", "\"ArrayExpression\"", ":", "return", "true", ";", "case", "\"UnaryExpression\"", ":", "if", "(", "node", ".", "operator", "===", "\"void\"", ")", "{", "return", "true", ";", "}", "return", "(", "node", ".", "operator", "===", "\"typeof\"", "&&", "inBooleanPosition", ")", "||", "isConstant", "(", "node", ".", "argument", ",", "true", ")", ";", "case", "\"BinaryExpression\"", ":", "return", "isConstant", "(", "node", ".", "left", ",", "false", ")", "&&", "isConstant", "(", "node", ".", "right", ",", "false", ")", "&&", "node", ".", "operator", "!==", "\"in\"", ";", "case", "\"LogicalExpression\"", ":", "{", "const", "isLeftConstant", "=", "isConstant", "(", "node", ".", "left", ",", "inBooleanPosition", ")", ";", "const", "isRightConstant", "=", "isConstant", "(", "node", ".", "right", ",", "inBooleanPosition", ")", ";", "const", "isLeftShortCircuit", "=", "(", "isLeftConstant", "&&", "isLogicalIdentity", "(", "node", ".", "left", ",", "node", ".", "operator", ")", ")", ";", "const", "isRightShortCircuit", "=", "(", "isRightConstant", "&&", "isLogicalIdentity", "(", "node", ".", "right", ",", "node", ".", "operator", ")", ")", ";", "return", "(", "isLeftConstant", "&&", "isRightConstant", ")", "||", "(", "node", ".", "operator", "===", "\"||\"", "&&", "isRightConstant", "&&", "node", ".", "right", ".", "value", "&&", "(", "!", "node", ".", "parent", "||", "node", ".", "parent", ".", "type", "!==", "\"BinaryExpression\"", "||", "!", "(", "EQUALITY_OPERATORS", ".", "includes", "(", "node", ".", "parent", ".", "operator", ")", "||", "RELATIONAL_OPERATORS", ".", "includes", "(", "node", ".", "parent", ".", "operator", ")", ")", ")", ")", "||", "isLeftShortCircuit", "||", "isRightShortCircuit", ";", "}", "case", "\"AssignmentExpression\"", ":", "return", "(", "node", ".", "operator", "===", "\"=\"", ")", "&&", "isConstant", "(", "node", ".", "right", ",", "inBooleanPosition", ")", ";", "case", "\"SequenceExpression\"", ":", "return", "isConstant", "(", "node", ".", "expressions", "[", "node", ".", "expressions", ".", "length", "-", "1", "]", ",", "inBooleanPosition", ")", ";", "}", "return", "false", ";", "}" ]
Checks if a node has a constant truthiness value. @param {ASTNode} node The AST node to check. @param {boolean} inBooleanPosition `false` if checking branch of a condition. `true` in all other cases @returns {Bool} true when node's truthiness is constant @private
[ "Checks", "if", "a", "node", "has", "a", "constant", "truthiness", "value", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-constant-condition.js#L92-L146
train
eslint/eslint
lib/rules/no-constant-condition.js
trackConstantConditionLoop
function trackConstantConditionLoop(node) { if (node.test && isConstant(node.test, true)) { loopsInCurrentScope.add(node); } }
javascript
function trackConstantConditionLoop(node) { if (node.test && isConstant(node.test, true)) { loopsInCurrentScope.add(node); } }
[ "function", "trackConstantConditionLoop", "(", "node", ")", "{", "if", "(", "node", ".", "test", "&&", "isConstant", "(", "node", ".", "test", ",", "true", ")", ")", "{", "loopsInCurrentScope", ".", "add", "(", "node", ")", ";", "}", "}" ]
Tracks when the given node contains a constant condition. @param {ASTNode} node The AST node to check. @returns {void} @private
[ "Tracks", "when", "the", "given", "node", "contains", "a", "constant", "condition", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-constant-condition.js#L154-L158
train
eslint/eslint
lib/rules/no-constant-condition.js
checkConstantConditionLoopInSet
function checkConstantConditionLoopInSet(node) { if (loopsInCurrentScope.has(node)) { loopsInCurrentScope.delete(node); context.report({ node: node.test, messageId: "unexpected" }); } }
javascript
function checkConstantConditionLoopInSet(node) { if (loopsInCurrentScope.has(node)) { loopsInCurrentScope.delete(node); context.report({ node: node.test, messageId: "unexpected" }); } }
[ "function", "checkConstantConditionLoopInSet", "(", "node", ")", "{", "if", "(", "loopsInCurrentScope", ".", "has", "(", "node", ")", ")", "{", "loopsInCurrentScope", ".", "delete", "(", "node", ")", ";", "context", ".", "report", "(", "{", "node", ":", "node", ".", "test", ",", "messageId", ":", "\"unexpected\"", "}", ")", ";", "}", "}" ]
Reports when the set contains the given constant condition node @param {ASTNode} node The AST node to check. @returns {void} @private
[ "Reports", "when", "the", "set", "contains", "the", "given", "constant", "condition", "node" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-constant-condition.js#L166-L171
train
eslint/eslint
lib/rules/no-constant-condition.js
reportIfConstant
function reportIfConstant(node) { if (node.test && isConstant(node.test, true)) { context.report({ node: node.test, messageId: "unexpected" }); } }
javascript
function reportIfConstant(node) { if (node.test && isConstant(node.test, true)) { context.report({ node: node.test, messageId: "unexpected" }); } }
[ "function", "reportIfConstant", "(", "node", ")", "{", "if", "(", "node", ".", "test", "&&", "isConstant", "(", "node", ".", "test", ",", "true", ")", ")", "{", "context", ".", "report", "(", "{", "node", ":", "node", ".", "test", ",", "messageId", ":", "\"unexpected\"", "}", ")", ";", "}", "}" ]
Reports when the given node contains a constant condition. @param {ASTNode} node The AST node to check. @returns {void} @private
[ "Reports", "when", "the", "given", "node", "contains", "a", "constant", "condition", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-constant-condition.js#L179-L183
train
eslint/eslint
lib/rules/generator-star-spacing.js
optionToDefinition
function optionToDefinition(option, defaults) { if (!option) { return defaults; } return typeof option === "string" ? optionDefinitions[option] : Object.assign({}, defaults, option); }
javascript
function optionToDefinition(option, defaults) { if (!option) { return defaults; } return typeof option === "string" ? optionDefinitions[option] : Object.assign({}, defaults, option); }
[ "function", "optionToDefinition", "(", "option", ",", "defaults", ")", "{", "if", "(", "!", "option", ")", "{", "return", "defaults", ";", "}", "return", "typeof", "option", "===", "\"string\"", "?", "optionDefinitions", "[", "option", "]", ":", "Object", ".", "assign", "(", "{", "}", ",", "defaults", ",", "option", ")", ";", "}" ]
Returns resolved option definitions based on an option and defaults @param {any} option - The option object or string value @param {Object} defaults - The defaults to use if options are not present @returns {Object} the resolved object definition
[ "Returns", "resolved", "option", "definitions", "based", "on", "an", "option", "and", "defaults" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/generator-star-spacing.js#L86-L94
train
eslint/eslint
lib/rules/generator-star-spacing.js
getStarToken
function getStarToken(node) { return sourceCode.getFirstToken( (node.parent.method || node.parent.type === "MethodDefinition") ? node.parent : node, isStarToken ); }
javascript
function getStarToken(node) { return sourceCode.getFirstToken( (node.parent.method || node.parent.type === "MethodDefinition") ? node.parent : node, isStarToken ); }
[ "function", "getStarToken", "(", "node", ")", "{", "return", "sourceCode", ".", "getFirstToken", "(", "(", "node", ".", "parent", ".", "method", "||", "node", ".", "parent", ".", "type", "===", "\"MethodDefinition\"", ")", "?", "node", ".", "parent", ":", "node", ",", "isStarToken", ")", ";", "}" ]
Gets the generator star token of the given function node. @param {ASTNode} node - The function node to get. @returns {Token} Found star token.
[ "Gets", "the", "generator", "star", "token", "of", "the", "given", "function", "node", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/generator-star-spacing.js#L124-L129
train
eslint/eslint
lib/rules/generator-star-spacing.js
checkFunction
function checkFunction(node) { if (!node.generator) { return; } const starToken = getStarToken(node); const prevToken = sourceCode.getTokenBefore(starToken); const nextToken = sourceCode.getTokenAfter(starToken); let kind = "named"; if (node.parent.type === "MethodDefinition" || (node.parent.type === "Property" && node.parent.method)) { kind = "method"; } else if (!node.id) { kind = "anonymous"; } // Only check before when preceded by `function`|`static` keyword if (!(kind === "method" && starToken === sourceCode.getFirstToken(node.parent))) { checkSpacing(kind, "before", prevToken, starToken); } checkSpacing(kind, "after", starToken, nextToken); }
javascript
function checkFunction(node) { if (!node.generator) { return; } const starToken = getStarToken(node); const prevToken = sourceCode.getTokenBefore(starToken); const nextToken = sourceCode.getTokenAfter(starToken); let kind = "named"; if (node.parent.type === "MethodDefinition" || (node.parent.type === "Property" && node.parent.method)) { kind = "method"; } else if (!node.id) { kind = "anonymous"; } // Only check before when preceded by `function`|`static` keyword if (!(kind === "method" && starToken === sourceCode.getFirstToken(node.parent))) { checkSpacing(kind, "before", prevToken, starToken); } checkSpacing(kind, "after", starToken, nextToken); }
[ "function", "checkFunction", "(", "node", ")", "{", "if", "(", "!", "node", ".", "generator", ")", "{", "return", ";", "}", "const", "starToken", "=", "getStarToken", "(", "node", ")", ";", "const", "prevToken", "=", "sourceCode", ".", "getTokenBefore", "(", "starToken", ")", ";", "const", "nextToken", "=", "sourceCode", ".", "getTokenAfter", "(", "starToken", ")", ";", "let", "kind", "=", "\"named\"", ";", "if", "(", "node", ".", "parent", ".", "type", "===", "\"MethodDefinition\"", "||", "(", "node", ".", "parent", ".", "type", "===", "\"Property\"", "&&", "node", ".", "parent", ".", "method", ")", ")", "{", "kind", "=", "\"method\"", ";", "}", "else", "if", "(", "!", "node", ".", "id", ")", "{", "kind", "=", "\"anonymous\"", ";", "}", "if", "(", "!", "(", "kind", "===", "\"method\"", "&&", "starToken", "===", "sourceCode", ".", "getFirstToken", "(", "node", ".", "parent", ")", ")", ")", "{", "checkSpacing", "(", "kind", ",", "\"before\"", ",", "prevToken", ",", "starToken", ")", ";", "}", "checkSpacing", "(", "kind", ",", "\"after\"", ",", "starToken", ",", "nextToken", ")", ";", "}" ]
Enforces the spacing around the star if node is a generator function. @param {ASTNode} node A function expression or declaration node. @returns {void}
[ "Enforces", "the", "spacing", "around", "the", "star", "if", "node", "is", "a", "generator", "function", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/generator-star-spacing.js#L180-L203
train
eslint/eslint
lib/rules/switch-colon-spacing.js
getColonToken
function getColonToken(node) { if (node.test) { return sourceCode.getTokenAfter(node.test, astUtils.isColonToken); } return sourceCode.getFirstToken(node, 1); }
javascript
function getColonToken(node) { if (node.test) { return sourceCode.getTokenAfter(node.test, astUtils.isColonToken); } return sourceCode.getFirstToken(node, 1); }
[ "function", "getColonToken", "(", "node", ")", "{", "if", "(", "node", ".", "test", ")", "{", "return", "sourceCode", ".", "getTokenAfter", "(", "node", ".", "test", ",", "astUtils", ".", "isColonToken", ")", ";", "}", "return", "sourceCode", ".", "getFirstToken", "(", "node", ",", "1", ")", ";", "}" ]
true by default Get the colon token of the given SwitchCase node. @param {ASTNode} node The SwitchCase node to get. @returns {Token} The colon token of the node.
[ "true", "by", "default", "Get", "the", "colon", "token", "of", "the", "given", "SwitchCase", "node", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/switch-colon-spacing.js#L59-L64
train
eslint/eslint
lib/rules/switch-colon-spacing.js
isValidSpacing
function isValidSpacing(left, right, expected) { return ( astUtils.isClosingBraceToken(right) || !astUtils.isTokenOnSameLine(left, right) || sourceCode.isSpaceBetweenTokens(left, right) === expected ); }
javascript
function isValidSpacing(left, right, expected) { return ( astUtils.isClosingBraceToken(right) || !astUtils.isTokenOnSameLine(left, right) || sourceCode.isSpaceBetweenTokens(left, right) === expected ); }
[ "function", "isValidSpacing", "(", "left", ",", "right", ",", "expected", ")", "{", "return", "(", "astUtils", ".", "isClosingBraceToken", "(", "right", ")", "||", "!", "astUtils", ".", "isTokenOnSameLine", "(", "left", ",", "right", ")", "||", "sourceCode", ".", "isSpaceBetweenTokens", "(", "left", ",", "right", ")", "===", "expected", ")", ";", "}" ]
Check whether the spacing between the given 2 tokens is valid or not. @param {Token} left The left token to check. @param {Token} right The right token to check. @param {boolean} expected The expected spacing to check. `true` if there should be a space. @returns {boolean} `true` if the spacing between the tokens is valid.
[ "Check", "whether", "the", "spacing", "between", "the", "given", "2", "tokens", "is", "valid", "or", "not", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/switch-colon-spacing.js#L73-L79
train
eslint/eslint
lib/rules/switch-colon-spacing.js
commentsExistBetween
function commentsExistBetween(left, right) { return sourceCode.getFirstTokenBetween( left, right, { includeComments: true, filter: astUtils.isCommentToken } ) !== null; }
javascript
function commentsExistBetween(left, right) { return sourceCode.getFirstTokenBetween( left, right, { includeComments: true, filter: astUtils.isCommentToken } ) !== null; }
[ "function", "commentsExistBetween", "(", "left", ",", "right", ")", "{", "return", "sourceCode", ".", "getFirstTokenBetween", "(", "left", ",", "right", ",", "{", "includeComments", ":", "true", ",", "filter", ":", "astUtils", ".", "isCommentToken", "}", ")", "!==", "null", ";", "}" ]
Check whether comments exist between the given 2 tokens. @param {Token} left The left token to check. @param {Token} right The right token to check. @returns {boolean} `true` if comments exist between the given 2 tokens.
[ "Check", "whether", "comments", "exist", "between", "the", "given", "2", "tokens", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/switch-colon-spacing.js#L87-L96
train
eslint/eslint
lib/rules/switch-colon-spacing.js
fix
function fix(fixer, left, right, spacing) { if (commentsExistBetween(left, right)) { return null; } if (spacing) { return fixer.insertTextAfter(left, " "); } return fixer.removeRange([left.range[1], right.range[0]]); }
javascript
function fix(fixer, left, right, spacing) { if (commentsExistBetween(left, right)) { return null; } if (spacing) { return fixer.insertTextAfter(left, " "); } return fixer.removeRange([left.range[1], right.range[0]]); }
[ "function", "fix", "(", "fixer", ",", "left", ",", "right", ",", "spacing", ")", "{", "if", "(", "commentsExistBetween", "(", "left", ",", "right", ")", ")", "{", "return", "null", ";", "}", "if", "(", "spacing", ")", "{", "return", "fixer", ".", "insertTextAfter", "(", "left", ",", "\" \"", ")", ";", "}", "return", "fixer", ".", "removeRange", "(", "[", "left", ".", "range", "[", "1", "]", ",", "right", ".", "range", "[", "0", "]", "]", ")", ";", "}" ]
Fix the spacing between the given 2 tokens. @param {RuleFixer} fixer The fixer to fix. @param {Token} left The left token of fix range. @param {Token} right The right token of fix range. @param {boolean} spacing The spacing style. `true` if there should be a space. @returns {Fix|null} The fix object.
[ "Fix", "the", "spacing", "between", "the", "given", "2", "tokens", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/switch-colon-spacing.js#L106-L114
train
eslint/eslint
lib/rules/callback-return.js
containsOnlyIdentifiers
function containsOnlyIdentifiers(node) { if (node.type === "Identifier") { return true; } if (node.type === "MemberExpression") { if (node.object.type === "Identifier") { return true; } if (node.object.type === "MemberExpression") { return containsOnlyIdentifiers(node.object); } } return false; }
javascript
function containsOnlyIdentifiers(node) { if (node.type === "Identifier") { return true; } if (node.type === "MemberExpression") { if (node.object.type === "Identifier") { return true; } if (node.object.type === "MemberExpression") { return containsOnlyIdentifiers(node.object); } } return false; }
[ "function", "containsOnlyIdentifiers", "(", "node", ")", "{", "if", "(", "node", ".", "type", "===", "\"Identifier\"", ")", "{", "return", "true", ";", "}", "if", "(", "node", ".", "type", "===", "\"MemberExpression\"", ")", "{", "if", "(", "node", ".", "object", ".", "type", "===", "\"Identifier\"", ")", "{", "return", "true", ";", "}", "if", "(", "node", ".", "object", ".", "type", "===", "\"MemberExpression\"", ")", "{", "return", "containsOnlyIdentifiers", "(", "node", ".", "object", ")", ";", "}", "}", "return", "false", ";", "}" ]
Check to see if a node contains only identifers @param {ASTNode} node The node to check @returns {boolean} Whether or not the node contains only identifers
[ "Check", "to", "see", "if", "a", "node", "contains", "only", "identifers" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/callback-return.js#L62-L77
train
eslint/eslint
lib/rules/callback-return.js
isCallback
function isCallback(node) { return containsOnlyIdentifiers(node.callee) && callbacks.indexOf(sourceCode.getText(node.callee)) > -1; }
javascript
function isCallback(node) { return containsOnlyIdentifiers(node.callee) && callbacks.indexOf(sourceCode.getText(node.callee)) > -1; }
[ "function", "isCallback", "(", "node", ")", "{", "return", "containsOnlyIdentifiers", "(", "node", ".", "callee", ")", "&&", "callbacks", ".", "indexOf", "(", "sourceCode", ".", "getText", "(", "node", ".", "callee", ")", ")", ">", "-", "1", ";", "}" ]
Check to see if a CallExpression is in our callback list. @param {ASTNode} node The node to check against our callback names list. @returns {boolean} Whether or not this function matches our callback name.
[ "Check", "to", "see", "if", "a", "CallExpression", "is", "in", "our", "callback", "list", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/callback-return.js#L84-L86
train
eslint/eslint
lib/rules/callback-return.js
isCallbackExpression
function isCallbackExpression(node, parentNode) { // ensure the parent node exists and is an expression if (!parentNode || parentNode.type !== "ExpressionStatement") { return false; } // cb() if (parentNode.expression === node) { return true; } // special case for cb && cb() and similar if (parentNode.expression.type === "BinaryExpression" || parentNode.expression.type === "LogicalExpression") { if (parentNode.expression.right === node) { return true; } } return false; }
javascript
function isCallbackExpression(node, parentNode) { // ensure the parent node exists and is an expression if (!parentNode || parentNode.type !== "ExpressionStatement") { return false; } // cb() if (parentNode.expression === node) { return true; } // special case for cb && cb() and similar if (parentNode.expression.type === "BinaryExpression" || parentNode.expression.type === "LogicalExpression") { if (parentNode.expression.right === node) { return true; } } return false; }
[ "function", "isCallbackExpression", "(", "node", ",", "parentNode", ")", "{", "if", "(", "!", "parentNode", "||", "parentNode", ".", "type", "!==", "\"ExpressionStatement\"", ")", "{", "return", "false", ";", "}", "if", "(", "parentNode", ".", "expression", "===", "node", ")", "{", "return", "true", ";", "}", "if", "(", "parentNode", ".", "expression", ".", "type", "===", "\"BinaryExpression\"", "||", "parentNode", ".", "expression", ".", "type", "===", "\"LogicalExpression\"", ")", "{", "if", "(", "parentNode", ".", "expression", ".", "right", "===", "node", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Determines whether or not the callback is part of a callback expression. @param {ASTNode} node The callback node @param {ASTNode} parentNode The expression node @returns {boolean} Whether or not this is part of a callback expression
[ "Determines", "whether", "or", "not", "the", "callback", "is", "part", "of", "a", "callback", "expression", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/callback-return.js#L94-L114
train
eslint/eslint
lib/rules/no-invalid-this.js
enterFunction
function enterFunction(node) { // `this` can be invalid only under strict mode. stack.push({ init: !context.getScope().isStrict, node, valid: true }); }
javascript
function enterFunction(node) { // `this` can be invalid only under strict mode. stack.push({ init: !context.getScope().isStrict, node, valid: true }); }
[ "function", "enterFunction", "(", "node", ")", "{", "stack", ".", "push", "(", "{", "init", ":", "!", "context", ".", "getScope", "(", ")", ".", "isStrict", ",", "node", ",", "valid", ":", "true", "}", ")", ";", "}" ]
Pushs new checking context into the stack. The checking context is not initialized yet. Because most functions don't have `this` keyword. When `this` keyword was found, the checking context is initialized. @param {ASTNode} node - A function node that was entered. @returns {void}
[ "Pushs", "new", "checking", "context", "into", "the", "stack", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-invalid-this.js#L68-L76
train
eslint/eslint
lib/rules/object-curly-newline.js
areLineBreaksRequired
function areLineBreaksRequired(node, options, first, last) { let objectProperties; if (node.type === "ObjectExpression" || node.type === "ObjectPattern") { objectProperties = node.properties; } else { // is ImportDeclaration or ExportNamedDeclaration objectProperties = node.specifiers .filter(s => s.type === "ImportSpecifier" || s.type === "ExportSpecifier"); } return objectProperties.length >= options.minProperties || ( options.multiline && objectProperties.length > 0 && first.loc.start.line !== last.loc.end.line ); }
javascript
function areLineBreaksRequired(node, options, first, last) { let objectProperties; if (node.type === "ObjectExpression" || node.type === "ObjectPattern") { objectProperties = node.properties; } else { // is ImportDeclaration or ExportNamedDeclaration objectProperties = node.specifiers .filter(s => s.type === "ImportSpecifier" || s.type === "ExportSpecifier"); } return objectProperties.length >= options.minProperties || ( options.multiline && objectProperties.length > 0 && first.loc.start.line !== last.loc.end.line ); }
[ "function", "areLineBreaksRequired", "(", "node", ",", "options", ",", "first", ",", "last", ")", "{", "let", "objectProperties", ";", "if", "(", "node", ".", "type", "===", "\"ObjectExpression\"", "||", "node", ".", "type", "===", "\"ObjectPattern\"", ")", "{", "objectProperties", "=", "node", ".", "properties", ";", "}", "else", "{", "objectProperties", "=", "node", ".", "specifiers", ".", "filter", "(", "s", "=>", "s", ".", "type", "===", "\"ImportSpecifier\"", "||", "s", ".", "type", "===", "\"ExportSpecifier\"", ")", ";", "}", "return", "objectProperties", ".", "length", ">=", "options", ".", "minProperties", "||", "(", "options", ".", "multiline", "&&", "objectProperties", ".", "length", ">", "0", "&&", "first", ".", "loc", ".", "start", ".", "line", "!==", "last", ".", "loc", ".", "end", ".", "line", ")", ";", "}" ]
Determines if ObjectExpression, ObjectPattern, ImportDeclaration or ExportNamedDeclaration node needs to be checked for missing line breaks @param {ASTNode} node - Node under inspection @param {Object} options - option specific to node type @param {Token} first - First object property @param {Token} last - Last object property @returns {boolean} `true` if node needs to be checked for missing line breaks
[ "Determines", "if", "ObjectExpression", "ObjectPattern", "ImportDeclaration", "or", "ExportNamedDeclaration", "node", "needs", "to", "be", "checked", "for", "missing", "line", "breaks" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/object-curly-newline.js#L111-L129
train
eslint/eslint
lib/cli-engine.js
calculateStatsPerFile
function calculateStatsPerFile(messages) { return messages.reduce((stat, message) => { if (message.fatal || message.severity === 2) { stat.errorCount++; if (message.fix) { stat.fixableErrorCount++; } } else { stat.warningCount++; if (message.fix) { stat.fixableWarningCount++; } } return stat; }, { errorCount: 0, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 }); }
javascript
function calculateStatsPerFile(messages) { return messages.reduce((stat, message) => { if (message.fatal || message.severity === 2) { stat.errorCount++; if (message.fix) { stat.fixableErrorCount++; } } else { stat.warningCount++; if (message.fix) { stat.fixableWarningCount++; } } return stat; }, { errorCount: 0, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 }); }
[ "function", "calculateStatsPerFile", "(", "messages", ")", "{", "return", "messages", ".", "reduce", "(", "(", "stat", ",", "message", ")", "=>", "{", "if", "(", "message", ".", "fatal", "||", "message", ".", "severity", "===", "2", ")", "{", "stat", ".", "errorCount", "++", ";", "if", "(", "message", ".", "fix", ")", "{", "stat", ".", "fixableErrorCount", "++", ";", "}", "}", "else", "{", "stat", ".", "warningCount", "++", ";", "if", "(", "message", ".", "fix", ")", "{", "stat", ".", "fixableWarningCount", "++", ";", "}", "}", "return", "stat", ";", "}", ",", "{", "errorCount", ":", "0", ",", "warningCount", ":", "0", ",", "fixableErrorCount", ":", "0", ",", "fixableWarningCount", ":", "0", "}", ")", ";", "}" ]
It will calculate the error and warning count for collection of messages per file @param {Object[]} messages - Collection of messages @returns {Object} Contains the stats @private
[ "It", "will", "calculate", "the", "error", "and", "warning", "count", "for", "collection", "of", "messages", "per", "file" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/cli-engine.js#L112-L132
train
eslint/eslint
lib/cli-engine.js
calculateStatsPerRun
function calculateStatsPerRun(results) { return results.reduce((stat, result) => { stat.errorCount += result.errorCount; stat.warningCount += result.warningCount; stat.fixableErrorCount += result.fixableErrorCount; stat.fixableWarningCount += result.fixableWarningCount; return stat; }, { errorCount: 0, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 }); }
javascript
function calculateStatsPerRun(results) { return results.reduce((stat, result) => { stat.errorCount += result.errorCount; stat.warningCount += result.warningCount; stat.fixableErrorCount += result.fixableErrorCount; stat.fixableWarningCount += result.fixableWarningCount; return stat; }, { errorCount: 0, warningCount: 0, fixableErrorCount: 0, fixableWarningCount: 0 }); }
[ "function", "calculateStatsPerRun", "(", "results", ")", "{", "return", "results", ".", "reduce", "(", "(", "stat", ",", "result", ")", "=>", "{", "stat", ".", "errorCount", "+=", "result", ".", "errorCount", ";", "stat", ".", "warningCount", "+=", "result", ".", "warningCount", ";", "stat", ".", "fixableErrorCount", "+=", "result", ".", "fixableErrorCount", ";", "stat", ".", "fixableWarningCount", "+=", "result", ".", "fixableWarningCount", ";", "return", "stat", ";", "}", ",", "{", "errorCount", ":", "0", ",", "warningCount", ":", "0", ",", "fixableErrorCount", ":", "0", ",", "fixableWarningCount", ":", "0", "}", ")", ";", "}" ]
It will calculate the error and warning count for collection of results from all files @param {Object[]} results - Collection of messages from all the files @returns {Object} Contains the stats @private
[ "It", "will", "calculate", "the", "error", "and", "warning", "count", "for", "collection", "of", "results", "from", "all", "files" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/cli-engine.js#L140-L153
train
eslint/eslint
lib/cli-engine.js
processFile
function processFile(filename, configHelper, options, linter) { const text = fs.readFileSync(path.resolve(filename), "utf8"); return processText( text, configHelper, filename, options.fix, options.allowInlineConfig, options.reportUnusedDisableDirectives, linter ); }
javascript
function processFile(filename, configHelper, options, linter) { const text = fs.readFileSync(path.resolve(filename), "utf8"); return processText( text, configHelper, filename, options.fix, options.allowInlineConfig, options.reportUnusedDisableDirectives, linter ); }
[ "function", "processFile", "(", "filename", ",", "configHelper", ",", "options", ",", "linter", ")", "{", "const", "text", "=", "fs", ".", "readFileSync", "(", "path", ".", "resolve", "(", "filename", ")", ",", "\"utf8\"", ")", ";", "return", "processText", "(", "text", ",", "configHelper", ",", "filename", ",", "options", ".", "fix", ",", "options", ".", "allowInlineConfig", ",", "options", ".", "reportUnusedDisableDirectives", ",", "linter", ")", ";", "}" ]
Processes an individual file using ESLint. Files used here are known to exist, so no need to check that here. @param {string} filename The filename of the file being checked. @param {Object} configHelper The configuration options for ESLint. @param {Object} options The CLIEngine options object. @param {Linter} linter Linter context @returns {{rules: LintResult, config: Object}} The results for linting on this text and the fully-resolved config for it. @private
[ "Processes", "an", "individual", "file", "using", "ESLint", ".", "Files", "used", "here", "are", "known", "to", "exist", "so", "no", "need", "to", "check", "that", "here", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/cli-engine.js#L243-L256
train
eslint/eslint
lib/rules/max-lines-per-function.js
isIIFE
function isIIFE(node) { return node.type === "FunctionExpression" && node.parent && node.parent.type === "CallExpression" && node.parent.callee === node; }
javascript
function isIIFE(node) { return node.type === "FunctionExpression" && node.parent && node.parent.type === "CallExpression" && node.parent.callee === node; }
[ "function", "isIIFE", "(", "node", ")", "{", "return", "node", ".", "type", "===", "\"FunctionExpression\"", "&&", "node", ".", "parent", "&&", "node", ".", "parent", ".", "type", "===", "\"CallExpression\"", "&&", "node", ".", "parent", ".", "callee", "===", "node", ";", "}" ]
Identifies is a node is a FunctionExpression which is part of an IIFE @param {ASTNode} node Node to test @returns {boolean} True if it's an IIFE
[ "Identifies", "is", "a", "node", "is", "a", "FunctionExpression", "which", "is", "part", "of", "an", "IIFE" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/max-lines-per-function.js#L137-L139
train
eslint/eslint
lib/rules/max-lines-per-function.js
isEmbedded
function isEmbedded(node) { if (!node.parent) { return false; } if (node !== node.parent.value) { return false; } if (node.parent.type === "MethodDefinition") { return true; } if (node.parent.type === "Property") { return node.parent.method === true || node.parent.kind === "get" || node.parent.kind === "set"; } return false; }
javascript
function isEmbedded(node) { if (!node.parent) { return false; } if (node !== node.parent.value) { return false; } if (node.parent.type === "MethodDefinition") { return true; } if (node.parent.type === "Property") { return node.parent.method === true || node.parent.kind === "get" || node.parent.kind === "set"; } return false; }
[ "function", "isEmbedded", "(", "node", ")", "{", "if", "(", "!", "node", ".", "parent", ")", "{", "return", "false", ";", "}", "if", "(", "node", "!==", "node", ".", "parent", ".", "value", ")", "{", "return", "false", ";", "}", "if", "(", "node", ".", "parent", ".", "type", "===", "\"MethodDefinition\"", ")", "{", "return", "true", ";", "}", "if", "(", "node", ".", "parent", ".", "type", "===", "\"Property\"", ")", "{", "return", "node", ".", "parent", ".", "method", "===", "true", "||", "node", ".", "parent", ".", "kind", "===", "\"get\"", "||", "node", ".", "parent", ".", "kind", "===", "\"set\"", ";", "}", "return", "false", ";", "}" ]
Identifies is a node is a FunctionExpression which is embedded within a MethodDefinition or Property @param {ASTNode} node Node to test @returns {boolean} True if it's a FunctionExpression embedded within a MethodDefinition or Property
[ "Identifies", "is", "a", "node", "is", "a", "FunctionExpression", "which", "is", "embedded", "within", "a", "MethodDefinition", "or", "Property" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/max-lines-per-function.js#L146-L160
train
eslint/eslint
lib/rules/max-lines-per-function.js
processFunction
function processFunction(funcNode) { const node = isEmbedded(funcNode) ? funcNode.parent : funcNode; if (!IIFEs && isIIFE(node)) { return; } let lineCount = 0; for (let i = node.loc.start.line - 1; i < node.loc.end.line; ++i) { const line = lines[i]; if (skipComments) { if (commentLineNumbers.has(i + 1) && isFullLineComment(line, i + 1, commentLineNumbers.get(i + 1))) { continue; } } if (skipBlankLines) { if (line.match(/^\s*$/u)) { continue; } } lineCount++; } if (lineCount > maxLines) { const name = astUtils.getFunctionNameWithKind(funcNode); context.report({ node, messageId: "exceed", data: { name, lineCount, maxLines } }); } }
javascript
function processFunction(funcNode) { const node = isEmbedded(funcNode) ? funcNode.parent : funcNode; if (!IIFEs && isIIFE(node)) { return; } let lineCount = 0; for (let i = node.loc.start.line - 1; i < node.loc.end.line; ++i) { const line = lines[i]; if (skipComments) { if (commentLineNumbers.has(i + 1) && isFullLineComment(line, i + 1, commentLineNumbers.get(i + 1))) { continue; } } if (skipBlankLines) { if (line.match(/^\s*$/u)) { continue; } } lineCount++; } if (lineCount > maxLines) { const name = astUtils.getFunctionNameWithKind(funcNode); context.report({ node, messageId: "exceed", data: { name, lineCount, maxLines } }); } }
[ "function", "processFunction", "(", "funcNode", ")", "{", "const", "node", "=", "isEmbedded", "(", "funcNode", ")", "?", "funcNode", ".", "parent", ":", "funcNode", ";", "if", "(", "!", "IIFEs", "&&", "isIIFE", "(", "node", ")", ")", "{", "return", ";", "}", "let", "lineCount", "=", "0", ";", "for", "(", "let", "i", "=", "node", ".", "loc", ".", "start", ".", "line", "-", "1", ";", "i", "<", "node", ".", "loc", ".", "end", ".", "line", ";", "++", "i", ")", "{", "const", "line", "=", "lines", "[", "i", "]", ";", "if", "(", "skipComments", ")", "{", "if", "(", "commentLineNumbers", ".", "has", "(", "i", "+", "1", ")", "&&", "isFullLineComment", "(", "line", ",", "i", "+", "1", ",", "commentLineNumbers", ".", "get", "(", "i", "+", "1", ")", ")", ")", "{", "continue", ";", "}", "}", "if", "(", "skipBlankLines", ")", "{", "if", "(", "line", ".", "match", "(", "/", "^\\s*$", "/", "u", ")", ")", "{", "continue", ";", "}", "}", "lineCount", "++", ";", "}", "if", "(", "lineCount", ">", "maxLines", ")", "{", "const", "name", "=", "astUtils", ".", "getFunctionNameWithKind", "(", "funcNode", ")", ";", "context", ".", "report", "(", "{", "node", ",", "messageId", ":", "\"exceed\"", ",", "data", ":", "{", "name", ",", "lineCount", ",", "maxLines", "}", "}", ")", ";", "}", "}" ]
Count the lines in the function @param {ASTNode} funcNode Function AST node @returns {void} @private
[ "Count", "the", "lines", "in", "the", "function" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/max-lines-per-function.js#L168-L203
train
eslint/eslint
lib/rules/no-useless-constructor.js
isValidIdentifierPair
function isValidIdentifierPair(ctorParam, superArg) { return ( ctorParam.type === "Identifier" && superArg.type === "Identifier" && ctorParam.name === superArg.name ); }
javascript
function isValidIdentifierPair(ctorParam, superArg) { return ( ctorParam.type === "Identifier" && superArg.type === "Identifier" && ctorParam.name === superArg.name ); }
[ "function", "isValidIdentifierPair", "(", "ctorParam", ",", "superArg", ")", "{", "return", "(", "ctorParam", ".", "type", "===", "\"Identifier\"", "&&", "superArg", ".", "type", "===", "\"Identifier\"", "&&", "ctorParam", ".", "name", "===", "superArg", ".", "name", ")", ";", "}" ]
Checks whether given 2 nodes are identifiers which have the same name or not. @param {ASTNode} ctorParam - A node to check. @param {ASTNode} superArg - A node to check. @returns {boolean} `true` if the nodes are identifiers which have the same name.
[ "Checks", "whether", "given", "2", "nodes", "are", "identifiers", "which", "have", "the", "same", "name", "or", "not", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-useless-constructor.js#L61-L67
train
eslint/eslint
lib/rules/no-useless-constructor.js
isRedundantSuperCall
function isRedundantSuperCall(body, ctorParams) { return ( isSingleSuperCall(body) && ctorParams.every(isSimple) && ( isSpreadArguments(body[0].expression.arguments) || isPassingThrough(ctorParams, body[0].expression.arguments) ) ); }
javascript
function isRedundantSuperCall(body, ctorParams) { return ( isSingleSuperCall(body) && ctorParams.every(isSimple) && ( isSpreadArguments(body[0].expression.arguments) || isPassingThrough(ctorParams, body[0].expression.arguments) ) ); }
[ "function", "isRedundantSuperCall", "(", "body", ",", "ctorParams", ")", "{", "return", "(", "isSingleSuperCall", "(", "body", ")", "&&", "ctorParams", ".", "every", "(", "isSimple", ")", "&&", "(", "isSpreadArguments", "(", "body", "[", "0", "]", ".", "expression", ".", "arguments", ")", "||", "isPassingThrough", "(", "ctorParams", ",", "body", "[", "0", "]", ".", "expression", ".", "arguments", ")", ")", ")", ";", "}" ]
Checks whether the constructor body is a redundant super call. @param {Array} body - constructor body content. @param {Array} ctorParams - The params to check against super call. @returns {boolean} true if the construtor body is redundant
[ "Checks", "whether", "the", "constructor", "body", "is", "a", "redundant", "super", "call", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-useless-constructor.js#L128-L137
train
eslint/eslint
lib/rules/no-useless-constructor.js
checkForConstructor
function checkForConstructor(node) { if (node.kind !== "constructor") { return; } const body = node.value.body.body; const ctorParams = node.value.params; const superClass = node.parent.parent.superClass; if (superClass ? isRedundantSuperCall(body, ctorParams) : (body.length === 0)) { context.report({ node, message: "Useless constructor." }); } }
javascript
function checkForConstructor(node) { if (node.kind !== "constructor") { return; } const body = node.value.body.body; const ctorParams = node.value.params; const superClass = node.parent.parent.superClass; if (superClass ? isRedundantSuperCall(body, ctorParams) : (body.length === 0)) { context.report({ node, message: "Useless constructor." }); } }
[ "function", "checkForConstructor", "(", "node", ")", "{", "if", "(", "node", ".", "kind", "!==", "\"constructor\"", ")", "{", "return", ";", "}", "const", "body", "=", "node", ".", "value", ".", "body", ".", "body", ";", "const", "ctorParams", "=", "node", ".", "value", ".", "params", ";", "const", "superClass", "=", "node", ".", "parent", ".", "parent", ".", "superClass", ";", "if", "(", "superClass", "?", "isRedundantSuperCall", "(", "body", ",", "ctorParams", ")", ":", "(", "body", ".", "length", "===", "0", ")", ")", "{", "context", ".", "report", "(", "{", "node", ",", "message", ":", "\"Useless constructor.\"", "}", ")", ";", "}", "}" ]
Checks whether a node is a redundant constructor @param {ASTNode} node - node to check @returns {void}
[ "Checks", "whether", "a", "node", "is", "a", "redundant", "constructor" ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-useless-constructor.js#L164-L179
train
eslint/eslint
lib/rules/no-mixed-spaces-and-tabs.js
beforeLoc
function beforeLoc(loc, line, column) { if (line < loc.start.line) { return true; } return line === loc.start.line && column < loc.start.column; }
javascript
function beforeLoc(loc, line, column) { if (line < loc.start.line) { return true; } return line === loc.start.line && column < loc.start.column; }
[ "function", "beforeLoc", "(", "loc", ",", "line", ",", "column", ")", "{", "if", "(", "line", "<", "loc", ".", "start", ".", "line", ")", "{", "return", "true", ";", "}", "return", "line", "===", "loc", ".", "start", ".", "line", "&&", "column", "<", "loc", ".", "start", ".", "column", ";", "}" ]
Determines if a given line and column are before a location. @param {Location} loc The location object from an AST node. @param {int} line The line to check. @param {int} column The column to check. @returns {boolean} True if the line and column are before the location, false if not. @private
[ "Determines", "if", "a", "given", "line", "and", "column", "are", "before", "a", "location", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-mixed-spaces-and-tabs.js#L52-L57
train
eslint/eslint
lib/rules/no-mixed-spaces-and-tabs.js
afterLoc
function afterLoc(loc, line, column) { if (line > loc.end.line) { return true; } return line === loc.end.line && column > loc.end.column; }
javascript
function afterLoc(loc, line, column) { if (line > loc.end.line) { return true; } return line === loc.end.line && column > loc.end.column; }
[ "function", "afterLoc", "(", "loc", ",", "line", ",", "column", ")", "{", "if", "(", "line", ">", "loc", ".", "end", ".", "line", ")", "{", "return", "true", ";", "}", "return", "line", "===", "loc", ".", "end", ".", "line", "&&", "column", ">", "loc", ".", "end", ".", "column", ";", "}" ]
Determines if a given line and column are after a location. @param {Location} loc The location object from an AST node. @param {int} line The line to check. @param {int} column The column to check. @returns {boolean} True if the line and column are after the location, false if not. @private
[ "Determines", "if", "a", "given", "line", "and", "column", "are", "after", "a", "location", "." ]
bc0819c94aad14f7fad3cbc2338ea15658b0f272
https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-mixed-spaces-and-tabs.js#L67-L72
train