id
int32 0
58k
| 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
sequence | docstring
stringlengths 4
11.8k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 86
226
|
---|---|---|---|---|---|---|---|---|---|---|---|
2,800 | eslint/eslint | lib/rules/prefer-arrow-callback.js | checkMetaProperty | function checkMetaProperty(node, metaName, propertyName) {
return node.meta.name === metaName && node.property.name === propertyName;
} | javascript | function checkMetaProperty(node, metaName, propertyName) {
return node.meta.name === metaName && node.property.name === propertyName;
} | [
"function",
"checkMetaProperty",
"(",
"node",
",",
"metaName",
",",
"propertyName",
")",
"{",
"return",
"node",
".",
"meta",
".",
"name",
"===",
"metaName",
"&&",
"node",
".",
"property",
".",
"name",
"===",
"propertyName",
";",
"}"
] | Checks whether or not a given MetaProperty node equals to a given value.
@param {ASTNode} node - A MetaProperty node to check.
@param {string} metaName - The name of `MetaProperty.meta`.
@param {string} propertyName - The name of `MetaProperty.property`.
@returns {boolean} `true` if the node is the specific value. | [
"Checks",
"whether",
"or",
"not",
"a",
"given",
"MetaProperty",
"node",
"equals",
"to",
"a",
"given",
"value",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-arrow-callback.js#L28-L30 |
2,801 | eslint/eslint | lib/rules/prefer-arrow-callback.js | getVariableOfArguments | function getVariableOfArguments(scope) {
const variables = scope.variables;
for (let i = 0; i < variables.length; ++i) {
const variable = variables[i];
if (variable.name === "arguments") {
/*
* If there was a parameter which is named "arguments", the
* implicit "arguments" is not defined.
* So does fast return with null.
*/
return (variable.identifiers.length === 0) ? variable : null;
}
}
/* istanbul ignore next */
return null;
} | javascript | function getVariableOfArguments(scope) {
const variables = scope.variables;
for (let i = 0; i < variables.length; ++i) {
const variable = variables[i];
if (variable.name === "arguments") {
/*
* If there was a parameter which is named "arguments", the
* implicit "arguments" is not defined.
* So does fast return with null.
*/
return (variable.identifiers.length === 0) ? variable : null;
}
}
/* istanbul ignore next */
return null;
} | [
"function",
"getVariableOfArguments",
"(",
"scope",
")",
"{",
"const",
"variables",
"=",
"scope",
".",
"variables",
";",
"for",
"(",
"let",
"i",
"=",
"0",
";",
"i",
"<",
"variables",
".",
"length",
";",
"++",
"i",
")",
"{",
"const",
"variable",
"=",
"variables",
"[",
"i",
"]",
";",
"if",
"(",
"variable",
".",
"name",
"===",
"\"arguments\"",
")",
"{",
"/*\n * If there was a parameter which is named \"arguments\", the\n * implicit \"arguments\" is not defined.\n * So does fast return with null.\n */",
"return",
"(",
"variable",
".",
"identifiers",
".",
"length",
"===",
"0",
")",
"?",
"variable",
":",
"null",
";",
"}",
"}",
"/* istanbul ignore next */",
"return",
"null",
";",
"}"
] | Gets the variable object of `arguments` which is defined implicitly.
@param {eslint-scope.Scope} scope - A scope to get.
@returns {eslint-scope.Variable} The found variable object. | [
"Gets",
"the",
"variable",
"object",
"of",
"arguments",
"which",
"is",
"defined",
"implicitly",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/prefer-arrow-callback.js#L37-L56 |
2,802 | eslint/eslint | lib/rules/curly.js | isOneLiner | function isOneLiner(node) {
const first = sourceCode.getFirstToken(node),
last = sourceCode.getLastToken(node);
return first.loc.start.line === last.loc.end.line;
} | javascript | function isOneLiner(node) {
const first = sourceCode.getFirstToken(node),
last = sourceCode.getLastToken(node);
return first.loc.start.line === last.loc.end.line;
} | [
"function",
"isOneLiner",
"(",
"node",
")",
"{",
"const",
"first",
"=",
"sourceCode",
".",
"getFirstToken",
"(",
"node",
")",
",",
"last",
"=",
"sourceCode",
".",
"getLastToken",
"(",
"node",
")",
";",
"return",
"first",
".",
"loc",
".",
"start",
".",
"line",
"===",
"last",
".",
"loc",
".",
"end",
".",
"line",
";",
"}"
] | Determines if a given node is a one-liner.
@param {ASTNode} node The node to check.
@returns {boolean} True if the node is a one-liner.
@private | [
"Determines",
"if",
"a",
"given",
"node",
"is",
"a",
"one",
"-",
"liner",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/curly.js#L99-L104 |
2,803 | eslint/eslint | lib/rules/curly.js | getElseKeyword | function getElseKeyword(node) {
return node.alternate && sourceCode.getFirstTokenBetween(node.consequent, node.alternate, isElseKeywordToken);
} | javascript | function getElseKeyword(node) {
return node.alternate && sourceCode.getFirstTokenBetween(node.consequent, node.alternate, isElseKeywordToken);
} | [
"function",
"getElseKeyword",
"(",
"node",
")",
"{",
"return",
"node",
".",
"alternate",
"&&",
"sourceCode",
".",
"getFirstTokenBetween",
"(",
"node",
".",
"consequent",
",",
"node",
".",
"alternate",
",",
"isElseKeywordToken",
")",
";",
"}"
] | Gets the `else` keyword token of a given `IfStatement` node.
@param {ASTNode} node - A `IfStatement` node to get.
@returns {Token} The `else` keyword token. | [
"Gets",
"the",
"else",
"keyword",
"token",
"of",
"a",
"given",
"IfStatement",
"node",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/curly.js#L121-L123 |
2,804 | eslint/eslint | lib/rules/curly.js | needsSemicolon | function needsSemicolon(closingBracket) {
const tokenBefore = sourceCode.getTokenBefore(closingBracket);
const tokenAfter = sourceCode.getTokenAfter(closingBracket);
const lastBlockNode = sourceCode.getNodeByRangeIndex(tokenBefore.range[0]);
if (astUtils.isSemicolonToken(tokenBefore)) {
// If the last statement already has a semicolon, don't add another one.
return false;
}
if (!tokenAfter) {
// If there are no statements after this block, there is no need to add a semicolon.
return false;
}
if (lastBlockNode.type === "BlockStatement" && lastBlockNode.parent.type !== "FunctionExpression" && lastBlockNode.parent.type !== "ArrowFunctionExpression") {
/*
* If the last node surrounded by curly brackets is a BlockStatement (other than a FunctionExpression or an ArrowFunctionExpression),
* don't insert a semicolon. Otherwise, the semicolon would be parsed as a separate statement, which would cause
* a SyntaxError if it was followed by `else`.
*/
return false;
}
if (tokenBefore.loc.end.line === tokenAfter.loc.start.line) {
// If the next token is on the same line, insert a semicolon.
return true;
}
if (/^[([/`+-]/u.test(tokenAfter.value)) {
// If the next token starts with a character that would disrupt ASI, insert a semicolon.
return true;
}
if (tokenBefore.type === "Punctuator" && (tokenBefore.value === "++" || tokenBefore.value === "--")) {
// If the last token is ++ or --, insert a semicolon to avoid disrupting ASI.
return true;
}
// Otherwise, do not insert a semicolon.
return false;
} | javascript | function needsSemicolon(closingBracket) {
const tokenBefore = sourceCode.getTokenBefore(closingBracket);
const tokenAfter = sourceCode.getTokenAfter(closingBracket);
const lastBlockNode = sourceCode.getNodeByRangeIndex(tokenBefore.range[0]);
if (astUtils.isSemicolonToken(tokenBefore)) {
// If the last statement already has a semicolon, don't add another one.
return false;
}
if (!tokenAfter) {
// If there are no statements after this block, there is no need to add a semicolon.
return false;
}
if (lastBlockNode.type === "BlockStatement" && lastBlockNode.parent.type !== "FunctionExpression" && lastBlockNode.parent.type !== "ArrowFunctionExpression") {
/*
* If the last node surrounded by curly brackets is a BlockStatement (other than a FunctionExpression or an ArrowFunctionExpression),
* don't insert a semicolon. Otherwise, the semicolon would be parsed as a separate statement, which would cause
* a SyntaxError if it was followed by `else`.
*/
return false;
}
if (tokenBefore.loc.end.line === tokenAfter.loc.start.line) {
// If the next token is on the same line, insert a semicolon.
return true;
}
if (/^[([/`+-]/u.test(tokenAfter.value)) {
// If the next token starts with a character that would disrupt ASI, insert a semicolon.
return true;
}
if (tokenBefore.type === "Punctuator" && (tokenBefore.value === "++" || tokenBefore.value === "--")) {
// If the last token is ++ or --, insert a semicolon to avoid disrupting ASI.
return true;
}
// Otherwise, do not insert a semicolon.
return false;
} | [
"function",
"needsSemicolon",
"(",
"closingBracket",
")",
"{",
"const",
"tokenBefore",
"=",
"sourceCode",
".",
"getTokenBefore",
"(",
"closingBracket",
")",
";",
"const",
"tokenAfter",
"=",
"sourceCode",
".",
"getTokenAfter",
"(",
"closingBracket",
")",
";",
"const",
"lastBlockNode",
"=",
"sourceCode",
".",
"getNodeByRangeIndex",
"(",
"tokenBefore",
".",
"range",
"[",
"0",
"]",
")",
";",
"if",
"(",
"astUtils",
".",
"isSemicolonToken",
"(",
"tokenBefore",
")",
")",
"{",
"// If the last statement already has a semicolon, don't add another one.",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"tokenAfter",
")",
"{",
"// If there are no statements after this block, there is no need to add a semicolon.",
"return",
"false",
";",
"}",
"if",
"(",
"lastBlockNode",
".",
"type",
"===",
"\"BlockStatement\"",
"&&",
"lastBlockNode",
".",
"parent",
".",
"type",
"!==",
"\"FunctionExpression\"",
"&&",
"lastBlockNode",
".",
"parent",
".",
"type",
"!==",
"\"ArrowFunctionExpression\"",
")",
"{",
"/*\n * If the last node surrounded by curly brackets is a BlockStatement (other than a FunctionExpression or an ArrowFunctionExpression),\n * don't insert a semicolon. Otherwise, the semicolon would be parsed as a separate statement, which would cause\n * a SyntaxError if it was followed by `else`.\n */",
"return",
"false",
";",
"}",
"if",
"(",
"tokenBefore",
".",
"loc",
".",
"end",
".",
"line",
"===",
"tokenAfter",
".",
"loc",
".",
"start",
".",
"line",
")",
"{",
"// If the next token is on the same line, insert a semicolon.",
"return",
"true",
";",
"}",
"if",
"(",
"/",
"^[([/`+-]",
"/",
"u",
".",
"test",
"(",
"tokenAfter",
".",
"value",
")",
")",
"{",
"// If the next token starts with a character that would disrupt ASI, insert a semicolon.",
"return",
"true",
";",
"}",
"if",
"(",
"tokenBefore",
".",
"type",
"===",
"\"Punctuator\"",
"&&",
"(",
"tokenBefore",
".",
"value",
"===",
"\"++\"",
"||",
"tokenBefore",
".",
"value",
"===",
"\"--\"",
")",
")",
"{",
"// If the last token is ++ or --, insert a semicolon to avoid disrupting ASI.",
"return",
"true",
";",
"}",
"// Otherwise, do not insert a semicolon.",
"return",
"false",
";",
"}"
] | Determines if a semicolon needs to be inserted after removing a set of curly brackets, in order to avoid a SyntaxError.
@param {Token} closingBracket The } token
@returns {boolean} `true` if a semicolon needs to be inserted after the last statement in the block. | [
"Determines",
"if",
"a",
"semicolon",
"needs",
"to",
"be",
"inserted",
"after",
"removing",
"a",
"set",
"of",
"curly",
"brackets",
"in",
"order",
"to",
"avoid",
"a",
"SyntaxError",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/curly.js#L161-L208 |
2,805 | eslint/eslint | lib/rules/curly.js | prepareCheck | function prepareCheck(node, body, name, opts) {
const hasBlock = (body.type === "BlockStatement");
let expected = null;
if (node.type === "IfStatement" && node.consequent === body && requiresBraceOfConsequent(node)) {
expected = true;
} else if (multiOnly) {
if (hasBlock && body.body.length === 1) {
expected = false;
}
} else if (multiLine) {
if (!isCollapsedOneLiner(body)) {
expected = true;
}
} else if (multiOrNest) {
if (hasBlock && body.body.length === 1 && isOneLiner(body.body[0])) {
const leadingComments = sourceCode.getCommentsBefore(body.body[0]);
expected = leadingComments.length > 0;
} else if (!isOneLiner(body)) {
expected = true;
}
} else {
expected = true;
}
return {
actual: hasBlock,
expected,
check() {
if (this.expected !== null && this.expected !== this.actual) {
if (this.expected) {
context.report({
node,
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
messageId: opts && opts.condition ? "missingCurlyAfterCondition" : "missingCurlyAfter",
data: {
name
},
fix: fixer => fixer.replaceText(body, `{${sourceCode.getText(body)}}`)
});
} else {
context.report({
node,
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
messageId: opts && opts.condition ? "unexpectedCurlyAfterCondition" : "unexpectedCurlyAfter",
data: {
name
},
fix(fixer) {
/*
* `do while` expressions sometimes need a space to be inserted after `do`.
* e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)`
*/
const needsPrecedingSpace = node.type === "DoWhileStatement" &&
sourceCode.getTokenBefore(body).range[1] === body.range[0] &&
!astUtils.canTokensBeAdjacent("do", sourceCode.getFirstToken(body, { skip: 1 }));
const openingBracket = sourceCode.getFirstToken(body);
const closingBracket = sourceCode.getLastToken(body);
const lastTokenInBlock = sourceCode.getTokenBefore(closingBracket);
if (needsSemicolon(closingBracket)) {
/*
* If removing braces would cause a SyntaxError due to multiple statements on the same line (or
* change the semantics of the code due to ASI), don't perform a fix.
*/
return null;
}
const resultingBodyText = sourceCode.getText().slice(openingBracket.range[1], lastTokenInBlock.range[0]) +
sourceCode.getText(lastTokenInBlock) +
sourceCode.getText().slice(lastTokenInBlock.range[1], closingBracket.range[0]);
return fixer.replaceText(body, (needsPrecedingSpace ? " " : "") + resultingBodyText);
}
});
}
}
}
};
} | javascript | function prepareCheck(node, body, name, opts) {
const hasBlock = (body.type === "BlockStatement");
let expected = null;
if (node.type === "IfStatement" && node.consequent === body && requiresBraceOfConsequent(node)) {
expected = true;
} else if (multiOnly) {
if (hasBlock && body.body.length === 1) {
expected = false;
}
} else if (multiLine) {
if (!isCollapsedOneLiner(body)) {
expected = true;
}
} else if (multiOrNest) {
if (hasBlock && body.body.length === 1 && isOneLiner(body.body[0])) {
const leadingComments = sourceCode.getCommentsBefore(body.body[0]);
expected = leadingComments.length > 0;
} else if (!isOneLiner(body)) {
expected = true;
}
} else {
expected = true;
}
return {
actual: hasBlock,
expected,
check() {
if (this.expected !== null && this.expected !== this.actual) {
if (this.expected) {
context.report({
node,
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
messageId: opts && opts.condition ? "missingCurlyAfterCondition" : "missingCurlyAfter",
data: {
name
},
fix: fixer => fixer.replaceText(body, `{${sourceCode.getText(body)}}`)
});
} else {
context.report({
node,
loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
messageId: opts && opts.condition ? "unexpectedCurlyAfterCondition" : "unexpectedCurlyAfter",
data: {
name
},
fix(fixer) {
/*
* `do while` expressions sometimes need a space to be inserted after `do`.
* e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)`
*/
const needsPrecedingSpace = node.type === "DoWhileStatement" &&
sourceCode.getTokenBefore(body).range[1] === body.range[0] &&
!astUtils.canTokensBeAdjacent("do", sourceCode.getFirstToken(body, { skip: 1 }));
const openingBracket = sourceCode.getFirstToken(body);
const closingBracket = sourceCode.getLastToken(body);
const lastTokenInBlock = sourceCode.getTokenBefore(closingBracket);
if (needsSemicolon(closingBracket)) {
/*
* If removing braces would cause a SyntaxError due to multiple statements on the same line (or
* change the semantics of the code due to ASI), don't perform a fix.
*/
return null;
}
const resultingBodyText = sourceCode.getText().slice(openingBracket.range[1], lastTokenInBlock.range[0]) +
sourceCode.getText(lastTokenInBlock) +
sourceCode.getText().slice(lastTokenInBlock.range[1], closingBracket.range[0]);
return fixer.replaceText(body, (needsPrecedingSpace ? " " : "") + resultingBodyText);
}
});
}
}
}
};
} | [
"function",
"prepareCheck",
"(",
"node",
",",
"body",
",",
"name",
",",
"opts",
")",
"{",
"const",
"hasBlock",
"=",
"(",
"body",
".",
"type",
"===",
"\"BlockStatement\"",
")",
";",
"let",
"expected",
"=",
"null",
";",
"if",
"(",
"node",
".",
"type",
"===",
"\"IfStatement\"",
"&&",
"node",
".",
"consequent",
"===",
"body",
"&&",
"requiresBraceOfConsequent",
"(",
"node",
")",
")",
"{",
"expected",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"multiOnly",
")",
"{",
"if",
"(",
"hasBlock",
"&&",
"body",
".",
"body",
".",
"length",
"===",
"1",
")",
"{",
"expected",
"=",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"multiLine",
")",
"{",
"if",
"(",
"!",
"isCollapsedOneLiner",
"(",
"body",
")",
")",
"{",
"expected",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"multiOrNest",
")",
"{",
"if",
"(",
"hasBlock",
"&&",
"body",
".",
"body",
".",
"length",
"===",
"1",
"&&",
"isOneLiner",
"(",
"body",
".",
"body",
"[",
"0",
"]",
")",
")",
"{",
"const",
"leadingComments",
"=",
"sourceCode",
".",
"getCommentsBefore",
"(",
"body",
".",
"body",
"[",
"0",
"]",
")",
";",
"expected",
"=",
"leadingComments",
".",
"length",
">",
"0",
";",
"}",
"else",
"if",
"(",
"!",
"isOneLiner",
"(",
"body",
")",
")",
"{",
"expected",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"expected",
"=",
"true",
";",
"}",
"return",
"{",
"actual",
":",
"hasBlock",
",",
"expected",
",",
"check",
"(",
")",
"{",
"if",
"(",
"this",
".",
"expected",
"!==",
"null",
"&&",
"this",
".",
"expected",
"!==",
"this",
".",
"actual",
")",
"{",
"if",
"(",
"this",
".",
"expected",
")",
"{",
"context",
".",
"report",
"(",
"{",
"node",
",",
"loc",
":",
"(",
"name",
"!==",
"\"else\"",
"?",
"node",
":",
"getElseKeyword",
"(",
"node",
")",
")",
".",
"loc",
".",
"start",
",",
"messageId",
":",
"opts",
"&&",
"opts",
".",
"condition",
"?",
"\"missingCurlyAfterCondition\"",
":",
"\"missingCurlyAfter\"",
",",
"data",
":",
"{",
"name",
"}",
",",
"fix",
":",
"fixer",
"=>",
"fixer",
".",
"replaceText",
"(",
"body",
",",
"`",
"${",
"sourceCode",
".",
"getText",
"(",
"body",
")",
"}",
"`",
")",
"}",
")",
";",
"}",
"else",
"{",
"context",
".",
"report",
"(",
"{",
"node",
",",
"loc",
":",
"(",
"name",
"!==",
"\"else\"",
"?",
"node",
":",
"getElseKeyword",
"(",
"node",
")",
")",
".",
"loc",
".",
"start",
",",
"messageId",
":",
"opts",
"&&",
"opts",
".",
"condition",
"?",
"\"unexpectedCurlyAfterCondition\"",
":",
"\"unexpectedCurlyAfter\"",
",",
"data",
":",
"{",
"name",
"}",
",",
"fix",
"(",
"fixer",
")",
"{",
"/*\n * `do while` expressions sometimes need a space to be inserted after `do`.\n * e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)`\n */",
"const",
"needsPrecedingSpace",
"=",
"node",
".",
"type",
"===",
"\"DoWhileStatement\"",
"&&",
"sourceCode",
".",
"getTokenBefore",
"(",
"body",
")",
".",
"range",
"[",
"1",
"]",
"===",
"body",
".",
"range",
"[",
"0",
"]",
"&&",
"!",
"astUtils",
".",
"canTokensBeAdjacent",
"(",
"\"do\"",
",",
"sourceCode",
".",
"getFirstToken",
"(",
"body",
",",
"{",
"skip",
":",
"1",
"}",
")",
")",
";",
"const",
"openingBracket",
"=",
"sourceCode",
".",
"getFirstToken",
"(",
"body",
")",
";",
"const",
"closingBracket",
"=",
"sourceCode",
".",
"getLastToken",
"(",
"body",
")",
";",
"const",
"lastTokenInBlock",
"=",
"sourceCode",
".",
"getTokenBefore",
"(",
"closingBracket",
")",
";",
"if",
"(",
"needsSemicolon",
"(",
"closingBracket",
")",
")",
"{",
"/*\n * If removing braces would cause a SyntaxError due to multiple statements on the same line (or\n * change the semantics of the code due to ASI), don't perform a fix.\n */",
"return",
"null",
";",
"}",
"const",
"resultingBodyText",
"=",
"sourceCode",
".",
"getText",
"(",
")",
".",
"slice",
"(",
"openingBracket",
".",
"range",
"[",
"1",
"]",
",",
"lastTokenInBlock",
".",
"range",
"[",
"0",
"]",
")",
"+",
"sourceCode",
".",
"getText",
"(",
"lastTokenInBlock",
")",
"+",
"sourceCode",
".",
"getText",
"(",
")",
".",
"slice",
"(",
"lastTokenInBlock",
".",
"range",
"[",
"1",
"]",
",",
"closingBracket",
".",
"range",
"[",
"0",
"]",
")",
";",
"return",
"fixer",
".",
"replaceText",
"(",
"body",
",",
"(",
"needsPrecedingSpace",
"?",
"\" \"",
":",
"\"\"",
")",
"+",
"resultingBodyText",
")",
";",
"}",
"}",
")",
";",
"}",
"}",
"}",
"}",
";",
"}"
] | Prepares to check the body of a node to see if it's a block statement.
@param {ASTNode} node The node to report if there's a problem.
@param {ASTNode} body The body node to check for blocks.
@param {string} name The name to report if there's a problem.
@param {{ condition: boolean }} opts Options to pass to the report functions
@returns {Object} a prepared check object, with "actual", "expected", "check" properties.
"actual" will be `true` or `false` whether the body is already a block statement.
"expected" will be `true` or `false` if the body should be a block statement or not, or
`null` if it doesn't matter, depending on the rule options. It can be modified to change
the final behavior of "check".
"check" will be a function reporting appropriate problems depending on the other
properties. | [
"Prepares",
"to",
"check",
"the",
"body",
"of",
"a",
"node",
"to",
"see",
"if",
"it",
"s",
"a",
"block",
"statement",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/curly.js#L224-L307 |
2,806 | eslint/eslint | lib/rules/curly.js | prepareIfChecks | function prepareIfChecks(node) {
const preparedChecks = [];
for (let currentNode = node; currentNode; currentNode = currentNode.alternate) {
preparedChecks.push(prepareCheck(currentNode, currentNode.consequent, "if", { condition: true }));
if (currentNode.alternate && currentNode.alternate.type !== "IfStatement") {
preparedChecks.push(prepareCheck(currentNode, currentNode.alternate, "else"));
break;
}
}
if (consistent) {
/*
* If any node should have or already have braces, make sure they
* all have braces.
* If all nodes shouldn't have braces, make sure they don't.
*/
const expected = preparedChecks.some(preparedCheck => {
if (preparedCheck.expected !== null) {
return preparedCheck.expected;
}
return preparedCheck.actual;
});
preparedChecks.forEach(preparedCheck => {
preparedCheck.expected = expected;
});
}
return preparedChecks;
} | javascript | function prepareIfChecks(node) {
const preparedChecks = [];
for (let currentNode = node; currentNode; currentNode = currentNode.alternate) {
preparedChecks.push(prepareCheck(currentNode, currentNode.consequent, "if", { condition: true }));
if (currentNode.alternate && currentNode.alternate.type !== "IfStatement") {
preparedChecks.push(prepareCheck(currentNode, currentNode.alternate, "else"));
break;
}
}
if (consistent) {
/*
* If any node should have or already have braces, make sure they
* all have braces.
* If all nodes shouldn't have braces, make sure they don't.
*/
const expected = preparedChecks.some(preparedCheck => {
if (preparedCheck.expected !== null) {
return preparedCheck.expected;
}
return preparedCheck.actual;
});
preparedChecks.forEach(preparedCheck => {
preparedCheck.expected = expected;
});
}
return preparedChecks;
} | [
"function",
"prepareIfChecks",
"(",
"node",
")",
"{",
"const",
"preparedChecks",
"=",
"[",
"]",
";",
"for",
"(",
"let",
"currentNode",
"=",
"node",
";",
"currentNode",
";",
"currentNode",
"=",
"currentNode",
".",
"alternate",
")",
"{",
"preparedChecks",
".",
"push",
"(",
"prepareCheck",
"(",
"currentNode",
",",
"currentNode",
".",
"consequent",
",",
"\"if\"",
",",
"{",
"condition",
":",
"true",
"}",
")",
")",
";",
"if",
"(",
"currentNode",
".",
"alternate",
"&&",
"currentNode",
".",
"alternate",
".",
"type",
"!==",
"\"IfStatement\"",
")",
"{",
"preparedChecks",
".",
"push",
"(",
"prepareCheck",
"(",
"currentNode",
",",
"currentNode",
".",
"alternate",
",",
"\"else\"",
")",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"consistent",
")",
"{",
"/*\n * If any node should have or already have braces, make sure they\n * all have braces.\n * If all nodes shouldn't have braces, make sure they don't.\n */",
"const",
"expected",
"=",
"preparedChecks",
".",
"some",
"(",
"preparedCheck",
"=>",
"{",
"if",
"(",
"preparedCheck",
".",
"expected",
"!==",
"null",
")",
"{",
"return",
"preparedCheck",
".",
"expected",
";",
"}",
"return",
"preparedCheck",
".",
"actual",
";",
"}",
")",
";",
"preparedChecks",
".",
"forEach",
"(",
"preparedCheck",
"=>",
"{",
"preparedCheck",
".",
"expected",
"=",
"expected",
";",
"}",
")",
";",
"}",
"return",
"preparedChecks",
";",
"}"
] | Prepares to check the bodies of a "if", "else if" and "else" chain.
@param {ASTNode} node The first IfStatement node of the chain.
@returns {Object[]} prepared checks for each body of the chain. See `prepareCheck` for more
information. | [
"Prepares",
"to",
"check",
"the",
"bodies",
"of",
"a",
"if",
"else",
"if",
"and",
"else",
"chain",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/curly.js#L315-L346 |
2,807 | eslint/eslint | lib/rules/lines-around-comment.js | getCommentLineNums | function getCommentLineNums(comments) {
const lines = [];
comments.forEach(token => {
const start = token.loc.start.line;
const end = token.loc.end.line;
lines.push(start, end);
});
return lines;
} | javascript | function getCommentLineNums(comments) {
const lines = [];
comments.forEach(token => {
const start = token.loc.start.line;
const end = token.loc.end.line;
lines.push(start, end);
});
return lines;
} | [
"function",
"getCommentLineNums",
"(",
"comments",
")",
"{",
"const",
"lines",
"=",
"[",
"]",
";",
"comments",
".",
"forEach",
"(",
"token",
"=>",
"{",
"const",
"start",
"=",
"token",
".",
"loc",
".",
"start",
".",
"line",
";",
"const",
"end",
"=",
"token",
".",
"loc",
".",
"end",
".",
"line",
";",
"lines",
".",
"push",
"(",
"start",
",",
"end",
")",
";",
"}",
")",
";",
"return",
"lines",
";",
"}"
] | Return an array with with any line numbers that contain comments.
@param {Array} comments An array of comment tokens.
@returns {Array} An array of line numbers. | [
"Return",
"an",
"array",
"with",
"with",
"any",
"line",
"numbers",
"that",
"contain",
"comments",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/lines-around-comment.js#L37-L47 |
2,808 | eslint/eslint | lib/rules/lines-around-comment.js | codeAroundComment | function codeAroundComment(token) {
let currentToken = token;
do {
currentToken = sourceCode.getTokenBefore(currentToken, { includeComments: true });
} while (currentToken && astUtils.isCommentToken(currentToken));
if (currentToken && astUtils.isTokenOnSameLine(currentToken, token)) {
return true;
}
currentToken = token;
do {
currentToken = sourceCode.getTokenAfter(currentToken, { includeComments: true });
} while (currentToken && astUtils.isCommentToken(currentToken));
if (currentToken && astUtils.isTokenOnSameLine(token, currentToken)) {
return true;
}
return false;
} | javascript | function codeAroundComment(token) {
let currentToken = token;
do {
currentToken = sourceCode.getTokenBefore(currentToken, { includeComments: true });
} while (currentToken && astUtils.isCommentToken(currentToken));
if (currentToken && astUtils.isTokenOnSameLine(currentToken, token)) {
return true;
}
currentToken = token;
do {
currentToken = sourceCode.getTokenAfter(currentToken, { includeComments: true });
} while (currentToken && astUtils.isCommentToken(currentToken));
if (currentToken && astUtils.isTokenOnSameLine(token, currentToken)) {
return true;
}
return false;
} | [
"function",
"codeAroundComment",
"(",
"token",
")",
"{",
"let",
"currentToken",
"=",
"token",
";",
"do",
"{",
"currentToken",
"=",
"sourceCode",
".",
"getTokenBefore",
"(",
"currentToken",
",",
"{",
"includeComments",
":",
"true",
"}",
")",
";",
"}",
"while",
"(",
"currentToken",
"&&",
"astUtils",
".",
"isCommentToken",
"(",
"currentToken",
")",
")",
";",
"if",
"(",
"currentToken",
"&&",
"astUtils",
".",
"isTokenOnSameLine",
"(",
"currentToken",
",",
"token",
")",
")",
"{",
"return",
"true",
";",
"}",
"currentToken",
"=",
"token",
";",
"do",
"{",
"currentToken",
"=",
"sourceCode",
".",
"getTokenAfter",
"(",
"currentToken",
",",
"{",
"includeComments",
":",
"true",
"}",
")",
";",
"}",
"while",
"(",
"currentToken",
"&&",
"astUtils",
".",
"isCommentToken",
"(",
"currentToken",
")",
")",
";",
"if",
"(",
"currentToken",
"&&",
"astUtils",
".",
"isTokenOnSameLine",
"(",
"token",
",",
"currentToken",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns whether or not comments are on lines starting with or ending with code
@param {token} token The comment token to check.
@returns {boolean} True if the comment is not alone. | [
"Returns",
"whether",
"or",
"not",
"comments",
"are",
"on",
"lines",
"starting",
"with",
"or",
"ending",
"with",
"code"
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/lines-around-comment.js#L152-L173 |
2,809 | eslint/eslint | lib/rules/lines-around-comment.js | isParentNodeType | function isParentNodeType(parent, nodeType) {
return parent.type === nodeType ||
(parent.body && parent.body.type === nodeType) ||
(parent.consequent && parent.consequent.type === nodeType);
} | javascript | function isParentNodeType(parent, nodeType) {
return parent.type === nodeType ||
(parent.body && parent.body.type === nodeType) ||
(parent.consequent && parent.consequent.type === nodeType);
} | [
"function",
"isParentNodeType",
"(",
"parent",
",",
"nodeType",
")",
"{",
"return",
"parent",
".",
"type",
"===",
"nodeType",
"||",
"(",
"parent",
".",
"body",
"&&",
"parent",
".",
"body",
".",
"type",
"===",
"nodeType",
")",
"||",
"(",
"parent",
".",
"consequent",
"&&",
"parent",
".",
"consequent",
".",
"type",
"===",
"nodeType",
")",
";",
"}"
] | Returns whether or not comments are inside a node type or not.
@param {ASTNode} parent The Comment parent node.
@param {string} nodeType The parent type to check against.
@returns {boolean} True if the comment is inside nodeType. | [
"Returns",
"whether",
"or",
"not",
"comments",
"are",
"inside",
"a",
"node",
"type",
"or",
"not",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/lines-around-comment.js#L181-L185 |
2,810 | eslint/eslint | lib/rules/lines-around-comment.js | isCommentAtParentStart | function isCommentAtParentStart(token, nodeType) {
const parent = getParentNodeOfToken(token);
return parent && isParentNodeType(parent, nodeType) &&
token.loc.start.line - parent.loc.start.line === 1;
} | javascript | function isCommentAtParentStart(token, nodeType) {
const parent = getParentNodeOfToken(token);
return parent && isParentNodeType(parent, nodeType) &&
token.loc.start.line - parent.loc.start.line === 1;
} | [
"function",
"isCommentAtParentStart",
"(",
"token",
",",
"nodeType",
")",
"{",
"const",
"parent",
"=",
"getParentNodeOfToken",
"(",
"token",
")",
";",
"return",
"parent",
"&&",
"isParentNodeType",
"(",
"parent",
",",
"nodeType",
")",
"&&",
"token",
".",
"loc",
".",
"start",
".",
"line",
"-",
"parent",
".",
"loc",
".",
"start",
".",
"line",
"===",
"1",
";",
"}"
] | Returns whether or not comments are at the parent start or not.
@param {token} token The Comment token.
@param {string} nodeType The parent type to check against.
@returns {boolean} True if the comment is at parent start. | [
"Returns",
"whether",
"or",
"not",
"comments",
"are",
"at",
"the",
"parent",
"start",
"or",
"not",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/lines-around-comment.js#L202-L207 |
2,811 | eslint/eslint | lib/rules/lines-around-comment.js | isCommentAtParentEnd | function isCommentAtParentEnd(token, nodeType) {
const parent = getParentNodeOfToken(token);
return parent && isParentNodeType(parent, nodeType) &&
parent.loc.end.line - token.loc.end.line === 1;
} | javascript | function isCommentAtParentEnd(token, nodeType) {
const parent = getParentNodeOfToken(token);
return parent && isParentNodeType(parent, nodeType) &&
parent.loc.end.line - token.loc.end.line === 1;
} | [
"function",
"isCommentAtParentEnd",
"(",
"token",
",",
"nodeType",
")",
"{",
"const",
"parent",
"=",
"getParentNodeOfToken",
"(",
"token",
")",
";",
"return",
"parent",
"&&",
"isParentNodeType",
"(",
"parent",
",",
"nodeType",
")",
"&&",
"parent",
".",
"loc",
".",
"end",
".",
"line",
"-",
"token",
".",
"loc",
".",
"end",
".",
"line",
"===",
"1",
";",
"}"
] | Returns whether or not comments are at the parent end or not.
@param {token} token The Comment token.
@param {string} nodeType The parent type to check against.
@returns {boolean} True if the comment is at parent end. | [
"Returns",
"whether",
"or",
"not",
"comments",
"are",
"at",
"the",
"parent",
"end",
"or",
"not",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/lines-around-comment.js#L215-L220 |
2,812 | eslint/eslint | lib/rules/lines-around-comment.js | isCommentAtBlockEnd | function isCommentAtBlockEnd(token) {
return isCommentAtParentEnd(token, "ClassBody") || isCommentAtParentEnd(token, "BlockStatement") || isCommentAtParentEnd(token, "SwitchCase") || isCommentAtParentEnd(token, "SwitchStatement");
} | javascript | function isCommentAtBlockEnd(token) {
return isCommentAtParentEnd(token, "ClassBody") || isCommentAtParentEnd(token, "BlockStatement") || isCommentAtParentEnd(token, "SwitchCase") || isCommentAtParentEnd(token, "SwitchStatement");
} | [
"function",
"isCommentAtBlockEnd",
"(",
"token",
")",
"{",
"return",
"isCommentAtParentEnd",
"(",
"token",
",",
"\"ClassBody\"",
")",
"||",
"isCommentAtParentEnd",
"(",
"token",
",",
"\"BlockStatement\"",
")",
"||",
"isCommentAtParentEnd",
"(",
"token",
",",
"\"SwitchCase\"",
")",
"||",
"isCommentAtParentEnd",
"(",
"token",
",",
"\"SwitchStatement\"",
")",
";",
"}"
] | Returns whether or not comments are at the block end or not.
@param {token} token The Comment token.
@returns {boolean} True if the comment is at block end. | [
"Returns",
"whether",
"or",
"not",
"comments",
"are",
"at",
"the",
"block",
"end",
"or",
"not",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/lines-around-comment.js#L236-L238 |
2,813 | eslint/eslint | lib/rules/no-extra-semi.js | report | function report(nodeOrToken) {
context.report({
node: nodeOrToken,
messageId: "unexpected",
fix(fixer) {
/*
* Expand the replacement range to include the surrounding
* tokens to avoid conflicting with semi.
* https://github.com/eslint/eslint/issues/7928
*/
return new FixTracker(fixer, context.getSourceCode())
.retainSurroundingTokens(nodeOrToken)
.remove(nodeOrToken);
}
});
} | javascript | function report(nodeOrToken) {
context.report({
node: nodeOrToken,
messageId: "unexpected",
fix(fixer) {
/*
* Expand the replacement range to include the surrounding
* tokens to avoid conflicting with semi.
* https://github.com/eslint/eslint/issues/7928
*/
return new FixTracker(fixer, context.getSourceCode())
.retainSurroundingTokens(nodeOrToken)
.remove(nodeOrToken);
}
});
} | [
"function",
"report",
"(",
"nodeOrToken",
")",
"{",
"context",
".",
"report",
"(",
"{",
"node",
":",
"nodeOrToken",
",",
"messageId",
":",
"\"unexpected\"",
",",
"fix",
"(",
"fixer",
")",
"{",
"/*\n * Expand the replacement range to include the surrounding\n * tokens to avoid conflicting with semi.\n * https://github.com/eslint/eslint/issues/7928\n */",
"return",
"new",
"FixTracker",
"(",
"fixer",
",",
"context",
".",
"getSourceCode",
"(",
")",
")",
".",
"retainSurroundingTokens",
"(",
"nodeOrToken",
")",
".",
"remove",
"(",
"nodeOrToken",
")",
";",
"}",
"}",
")",
";",
"}"
] | Reports an unnecessary semicolon error.
@param {Node|Token} nodeOrToken - A node or a token to be reported.
@returns {void} | [
"Reports",
"an",
"unnecessary",
"semicolon",
"error",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-extra-semi.js#L46-L62 |
2,814 | eslint/eslint | lib/rules/no-extra-semi.js | checkForPartOfClassBody | function checkForPartOfClassBody(firstToken) {
for (let token = firstToken;
token.type === "Punctuator" && !astUtils.isClosingBraceToken(token);
token = sourceCode.getTokenAfter(token)
) {
if (astUtils.isSemicolonToken(token)) {
report(token);
}
}
} | javascript | function checkForPartOfClassBody(firstToken) {
for (let token = firstToken;
token.type === "Punctuator" && !astUtils.isClosingBraceToken(token);
token = sourceCode.getTokenAfter(token)
) {
if (astUtils.isSemicolonToken(token)) {
report(token);
}
}
} | [
"function",
"checkForPartOfClassBody",
"(",
"firstToken",
")",
"{",
"for",
"(",
"let",
"token",
"=",
"firstToken",
";",
"token",
".",
"type",
"===",
"\"Punctuator\"",
"&&",
"!",
"astUtils",
".",
"isClosingBraceToken",
"(",
"token",
")",
";",
"token",
"=",
"sourceCode",
".",
"getTokenAfter",
"(",
"token",
")",
")",
"{",
"if",
"(",
"astUtils",
".",
"isSemicolonToken",
"(",
"token",
")",
")",
"{",
"report",
"(",
"token",
")",
";",
"}",
"}",
"}"
] | Checks for a part of a class body.
This checks tokens from a specified token to a next MethodDefinition or the end of class body.
@param {Token} firstToken - The first token to check.
@returns {void} | [
"Checks",
"for",
"a",
"part",
"of",
"a",
"class",
"body",
".",
"This",
"checks",
"tokens",
"from",
"a",
"specified",
"token",
"to",
"a",
"next",
"MethodDefinition",
"or",
"the",
"end",
"of",
"class",
"body",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/no-extra-semi.js#L71-L80 |
2,815 | eslint/eslint | lib/rules/sort-imports.js | usedMemberSyntax | function usedMemberSyntax(node) {
if (node.specifiers.length === 0) {
return "none";
}
if (node.specifiers[0].type === "ImportNamespaceSpecifier") {
return "all";
}
if (node.specifiers.length === 1) {
return "single";
}
return "multiple";
} | javascript | function usedMemberSyntax(node) {
if (node.specifiers.length === 0) {
return "none";
}
if (node.specifiers[0].type === "ImportNamespaceSpecifier") {
return "all";
}
if (node.specifiers.length === 1) {
return "single";
}
return "multiple";
} | [
"function",
"usedMemberSyntax",
"(",
"node",
")",
"{",
"if",
"(",
"node",
".",
"specifiers",
".",
"length",
"===",
"0",
")",
"{",
"return",
"\"none\"",
";",
"}",
"if",
"(",
"node",
".",
"specifiers",
"[",
"0",
"]",
".",
"type",
"===",
"\"ImportNamespaceSpecifier\"",
")",
"{",
"return",
"\"all\"",
";",
"}",
"if",
"(",
"node",
".",
"specifiers",
".",
"length",
"===",
"1",
")",
"{",
"return",
"\"single\"",
";",
"}",
"return",
"\"multiple\"",
";",
"}"
] | Gets the used member syntax style.
import "my-module.js" --> none
import * as myModule from "my-module.js" --> all
import {myMember} from "my-module.js" --> single
import {foo, bar} from "my-module.js" --> multiple
@param {ASTNode} node - the ImportDeclaration node.
@returns {string} used member parameter style, ["all", "multiple", "single"] | [
"Gets",
"the",
"used",
"member",
"syntax",
"style",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/sort-imports.js#L77-L89 |
2,816 | eslint/eslint | lib/rules/newline-after-var.js | isLastNode | function isLastNode(node) {
const token = sourceCode.getTokenAfter(node);
return !token || (token.type === "Punctuator" && token.value === "}");
} | javascript | function isLastNode(node) {
const token = sourceCode.getTokenAfter(node);
return !token || (token.type === "Punctuator" && token.value === "}");
} | [
"function",
"isLastNode",
"(",
"node",
")",
"{",
"const",
"token",
"=",
"sourceCode",
".",
"getTokenAfter",
"(",
"node",
")",
";",
"return",
"!",
"token",
"||",
"(",
"token",
".",
"type",
"===",
"\"Punctuator\"",
"&&",
"token",
".",
"value",
"===",
"\"}\"",
")",
";",
"}"
] | Determine if provided node is the last of their parent block.
@private
@param {ASTNode} node - node to test
@returns {boolean} True if `node` is last of their parent block. | [
"Determine",
"if",
"provided",
"node",
"is",
"the",
"last",
"of",
"their",
"parent",
"block",
"."
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/newline-after-var.js#L130-L134 |
2,817 | eslint/eslint | lib/rules/newline-after-var.js | getLastCommentLineOfBlock | function getLastCommentLineOfBlock(commentStartLine) {
const currentCommentEnd = commentEndLine[commentStartLine];
return commentEndLine[currentCommentEnd + 1] ? getLastCommentLineOfBlock(currentCommentEnd + 1) : currentCommentEnd;
} | javascript | function getLastCommentLineOfBlock(commentStartLine) {
const currentCommentEnd = commentEndLine[commentStartLine];
return commentEndLine[currentCommentEnd + 1] ? getLastCommentLineOfBlock(currentCommentEnd + 1) : currentCommentEnd;
} | [
"function",
"getLastCommentLineOfBlock",
"(",
"commentStartLine",
")",
"{",
"const",
"currentCommentEnd",
"=",
"commentEndLine",
"[",
"commentStartLine",
"]",
";",
"return",
"commentEndLine",
"[",
"currentCommentEnd",
"+",
"1",
"]",
"?",
"getLastCommentLineOfBlock",
"(",
"currentCommentEnd",
"+",
"1",
")",
":",
"currentCommentEnd",
";",
"}"
] | Gets the last line of a group of consecutive comments
@param {number} commentStartLine The starting line of the group
@returns {number} The number of the last comment line of the group | [
"Gets",
"the",
"last",
"line",
"of",
"a",
"group",
"of",
"consecutive",
"comments"
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/newline-after-var.js#L141-L145 |
2,818 | eslint/eslint | lib/rules/newline-after-var.js | checkForBlankLine | function checkForBlankLine(node) {
/*
* lastToken is the last token on the node's line. It will usually also be the last token of the node, but it will
* sometimes be second-last if there is a semicolon on a different line.
*/
const lastToken = getLastToken(node),
/*
* If lastToken is the last token of the node, nextToken should be the token after the node. Otherwise, nextToken
* is the last token of the node.
*/
nextToken = lastToken === sourceCode.getLastToken(node) ? sourceCode.getTokenAfter(node) : sourceCode.getLastToken(node),
nextLineNum = lastToken.loc.end.line + 1;
// Ignore if there is no following statement
if (!nextToken) {
return;
}
// Ignore if parent of node is a for variant
if (isForTypeSpecifier(node.parent.type)) {
return;
}
// Ignore if parent of node is an export specifier
if (isExportSpecifier(node.parent.type)) {
return;
}
/*
* Some coding styles use multiple `var` statements, so do nothing if
* the next token is a `var` statement.
*/
if (nextToken.type === "Keyword" && isVar(nextToken.value)) {
return;
}
// Ignore if it is last statement in a block
if (isLastNode(node)) {
return;
}
// Next statement is not a `var`...
const noNextLineToken = nextToken.loc.start.line > nextLineNum;
const hasNextLineComment = (typeof commentEndLine[nextLineNum] !== "undefined");
if (mode === "never" && noNextLineToken && !hasNextLineComment) {
context.report({
node,
messageId: "unexpected",
data: { identifier: node.name },
fix(fixer) {
const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);
return fixer.replaceTextRange([lastToken.range[1], nextToken.range[0]], `${linesBetween.slice(0, -1).join("")}\n${linesBetween[linesBetween.length - 1]}`);
}
});
}
// Token on the next line, or comment without blank line
if (
mode === "always" && (
!noNextLineToken ||
hasNextLineComment && !hasBlankLineAfterComment(nextToken, nextLineNum)
)
) {
context.report({
node,
messageId: "expected",
data: { identifier: node.name },
fix(fixer) {
if ((noNextLineToken ? getLastCommentLineOfBlock(nextLineNum) : lastToken.loc.end.line) === nextToken.loc.start.line) {
return fixer.insertTextBefore(nextToken, "\n\n");
}
return fixer.insertTextBeforeRange([nextToken.range[0] - nextToken.loc.start.column, nextToken.range[1]], "\n");
}
});
}
} | javascript | function checkForBlankLine(node) {
/*
* lastToken is the last token on the node's line. It will usually also be the last token of the node, but it will
* sometimes be second-last if there is a semicolon on a different line.
*/
const lastToken = getLastToken(node),
/*
* If lastToken is the last token of the node, nextToken should be the token after the node. Otherwise, nextToken
* is the last token of the node.
*/
nextToken = lastToken === sourceCode.getLastToken(node) ? sourceCode.getTokenAfter(node) : sourceCode.getLastToken(node),
nextLineNum = lastToken.loc.end.line + 1;
// Ignore if there is no following statement
if (!nextToken) {
return;
}
// Ignore if parent of node is a for variant
if (isForTypeSpecifier(node.parent.type)) {
return;
}
// Ignore if parent of node is an export specifier
if (isExportSpecifier(node.parent.type)) {
return;
}
/*
* Some coding styles use multiple `var` statements, so do nothing if
* the next token is a `var` statement.
*/
if (nextToken.type === "Keyword" && isVar(nextToken.value)) {
return;
}
// Ignore if it is last statement in a block
if (isLastNode(node)) {
return;
}
// Next statement is not a `var`...
const noNextLineToken = nextToken.loc.start.line > nextLineNum;
const hasNextLineComment = (typeof commentEndLine[nextLineNum] !== "undefined");
if (mode === "never" && noNextLineToken && !hasNextLineComment) {
context.report({
node,
messageId: "unexpected",
data: { identifier: node.name },
fix(fixer) {
const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);
return fixer.replaceTextRange([lastToken.range[1], nextToken.range[0]], `${linesBetween.slice(0, -1).join("")}\n${linesBetween[linesBetween.length - 1]}`);
}
});
}
// Token on the next line, or comment without blank line
if (
mode === "always" && (
!noNextLineToken ||
hasNextLineComment && !hasBlankLineAfterComment(nextToken, nextLineNum)
)
) {
context.report({
node,
messageId: "expected",
data: { identifier: node.name },
fix(fixer) {
if ((noNextLineToken ? getLastCommentLineOfBlock(nextLineNum) : lastToken.loc.end.line) === nextToken.loc.start.line) {
return fixer.insertTextBefore(nextToken, "\n\n");
}
return fixer.insertTextBeforeRange([nextToken.range[0] - nextToken.loc.start.column, nextToken.range[1]], "\n");
}
});
}
} | [
"function",
"checkForBlankLine",
"(",
"node",
")",
"{",
"/*\n * lastToken is the last token on the node's line. It will usually also be the last token of the node, but it will\n * sometimes be second-last if there is a semicolon on a different line.\n */",
"const",
"lastToken",
"=",
"getLastToken",
"(",
"node",
")",
",",
"/*\n * If lastToken is the last token of the node, nextToken should be the token after the node. Otherwise, nextToken\n * is the last token of the node.\n */",
"nextToken",
"=",
"lastToken",
"===",
"sourceCode",
".",
"getLastToken",
"(",
"node",
")",
"?",
"sourceCode",
".",
"getTokenAfter",
"(",
"node",
")",
":",
"sourceCode",
".",
"getLastToken",
"(",
"node",
")",
",",
"nextLineNum",
"=",
"lastToken",
".",
"loc",
".",
"end",
".",
"line",
"+",
"1",
";",
"// Ignore if there is no following statement",
"if",
"(",
"!",
"nextToken",
")",
"{",
"return",
";",
"}",
"// Ignore if parent of node is a for variant",
"if",
"(",
"isForTypeSpecifier",
"(",
"node",
".",
"parent",
".",
"type",
")",
")",
"{",
"return",
";",
"}",
"// Ignore if parent of node is an export specifier",
"if",
"(",
"isExportSpecifier",
"(",
"node",
".",
"parent",
".",
"type",
")",
")",
"{",
"return",
";",
"}",
"/*\n * Some coding styles use multiple `var` statements, so do nothing if\n * the next token is a `var` statement.\n */",
"if",
"(",
"nextToken",
".",
"type",
"===",
"\"Keyword\"",
"&&",
"isVar",
"(",
"nextToken",
".",
"value",
")",
")",
"{",
"return",
";",
"}",
"// Ignore if it is last statement in a block",
"if",
"(",
"isLastNode",
"(",
"node",
")",
")",
"{",
"return",
";",
"}",
"// Next statement is not a `var`...",
"const",
"noNextLineToken",
"=",
"nextToken",
".",
"loc",
".",
"start",
".",
"line",
">",
"nextLineNum",
";",
"const",
"hasNextLineComment",
"=",
"(",
"typeof",
"commentEndLine",
"[",
"nextLineNum",
"]",
"!==",
"\"undefined\"",
")",
";",
"if",
"(",
"mode",
"===",
"\"never\"",
"&&",
"noNextLineToken",
"&&",
"!",
"hasNextLineComment",
")",
"{",
"context",
".",
"report",
"(",
"{",
"node",
",",
"messageId",
":",
"\"unexpected\"",
",",
"data",
":",
"{",
"identifier",
":",
"node",
".",
"name",
"}",
",",
"fix",
"(",
"fixer",
")",
"{",
"const",
"linesBetween",
"=",
"sourceCode",
".",
"getText",
"(",
")",
".",
"slice",
"(",
"lastToken",
".",
"range",
"[",
"1",
"]",
",",
"nextToken",
".",
"range",
"[",
"0",
"]",
")",
".",
"split",
"(",
"astUtils",
".",
"LINEBREAK_MATCHER",
")",
";",
"return",
"fixer",
".",
"replaceTextRange",
"(",
"[",
"lastToken",
".",
"range",
"[",
"1",
"]",
",",
"nextToken",
".",
"range",
"[",
"0",
"]",
"]",
",",
"`",
"${",
"linesBetween",
".",
"slice",
"(",
"0",
",",
"-",
"1",
")",
".",
"join",
"(",
"\"\"",
")",
"}",
"\\n",
"${",
"linesBetween",
"[",
"linesBetween",
".",
"length",
"-",
"1",
"]",
"}",
"`",
")",
";",
"}",
"}",
")",
";",
"}",
"// Token on the next line, or comment without blank line",
"if",
"(",
"mode",
"===",
"\"always\"",
"&&",
"(",
"!",
"noNextLineToken",
"||",
"hasNextLineComment",
"&&",
"!",
"hasBlankLineAfterComment",
"(",
"nextToken",
",",
"nextLineNum",
")",
")",
")",
"{",
"context",
".",
"report",
"(",
"{",
"node",
",",
"messageId",
":",
"\"expected\"",
",",
"data",
":",
"{",
"identifier",
":",
"node",
".",
"name",
"}",
",",
"fix",
"(",
"fixer",
")",
"{",
"if",
"(",
"(",
"noNextLineToken",
"?",
"getLastCommentLineOfBlock",
"(",
"nextLineNum",
")",
":",
"lastToken",
".",
"loc",
".",
"end",
".",
"line",
")",
"===",
"nextToken",
".",
"loc",
".",
"start",
".",
"line",
")",
"{",
"return",
"fixer",
".",
"insertTextBefore",
"(",
"nextToken",
",",
"\"\\n\\n\"",
")",
";",
"}",
"return",
"fixer",
".",
"insertTextBeforeRange",
"(",
"[",
"nextToken",
".",
"range",
"[",
"0",
"]",
"-",
"nextToken",
".",
"loc",
".",
"start",
".",
"column",
",",
"nextToken",
".",
"range",
"[",
"1",
"]",
"]",
",",
"\"\\n\"",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | Checks that a blank line exists after a variable declaration when mode is
set to "always", or checks that there is no blank line when mode is set
to "never"
@private
@param {ASTNode} node - `VariableDeclaration` node to test
@returns {void} | [
"Checks",
"that",
"a",
"blank",
"line",
"exists",
"after",
"a",
"variable",
"declaration",
"when",
"mode",
"is",
"set",
"to",
"always",
"or",
"checks",
"that",
"there",
"is",
"no",
"blank",
"line",
"when",
"mode",
"is",
"set",
"to",
"never"
] | bc0819c94aad14f7fad3cbc2338ea15658b0f272 | https://github.com/eslint/eslint/blob/bc0819c94aad14f7fad3cbc2338ea15658b0f272/lib/rules/newline-after-var.js#L165-L245 |
2,819 | 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 |
2,820 | 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 |
2,821 | 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 |
2,822 | 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 |
2,823 | 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",
";",
"// 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",
")",
";",
"}",
"}",
"}"
] | 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 |
2,824 | 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 |
2,825 | 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 |
2,826 | 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 |
2,827 | 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 |
2,828 | 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",
";",
"/*\n * Besides checking for the condition being in the loop, we want to\n * check the function that this modifier is belonging to is called\n * in the loop.\n * FIXME: This should probably be extracted to a function.\n */",
"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 |
2,829 | 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 |
2,830 | 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 |
2,831 | 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 |
2,832 | 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",
")",
"{",
"// 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",
";",
"}",
"/*\n * If it's inside of a group, OK if either operand is modified.\n * So stores the group this reference belongs to.\n */",
"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",
";",
"}"
] | 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 |
2,833 | 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",
")",
"{",
"// 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",
")",
";",
"}",
"/*\n * Reports the conditions which are not belonging to groups.\n * Others will be reported after all variables are done.\n */",
"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 |
2,834 | 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 |
2,835 | 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 |
2,836 | 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 |
2,837 | 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 |
2,838 | 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 |
2,839 | 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\"",
")",
"// Strip the .js extension",
".",
"map",
"(",
"ruleFileName",
"=>",
"ruleFileName",
".",
"replace",
"(",
"/",
"\\.js$",
"/",
"u",
",",
"\"\"",
")",
")",
"/*\n * Sort by length descending. This ensures that rule names which are substrings of other rule names are not\n * matched incorrectly. For example, the string \"no-undefined\" should get matched with the `no-undefined` rule,\n * instead of getting matched with the `no-undef` rule followed by the string \"ined\".\n */",
".",
"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 |
2,840 | 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 |
2,841 | 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 |
2,842 | 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 |
2,843 | 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 |
2,844 | 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 |
2,845 | 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 |
2,846 | 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\"",
")",
",",
"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",
":",
"{",
"}",
"}",
")",
";",
"}"
] | 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 |
2,847 | 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\"",
")",
";",
"// original format",
"const",
"idNewAtBeginningOfTitleRegExp",
"=",
"new",
"RegExp",
"(",
"`",
"${",
"id",
"}",
"`",
",",
"\"u\"",
")",
";",
"// new format is same as rules index",
"/*\n * 1. Added support for new format.\n * 2. Will remove support for old format after all docs files have new format.\n * 3. Will remove this check when the main heading is automatically generated from rule metadata.\n */",
"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 |
2,848 | 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 |
2,849 | 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 |
2,850 | 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",
")",
";",
"// 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",
",",
"\" \"",
")",
";",
"}",
"}",
")",
";",
"}",
"}"
] | 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 |
2,851 | 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 |
2,852 | 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 |
2,853 | 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 |
2,854 | 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 |
2,855 | 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 |
2,856 | 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 |
2,857 | 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 |
2,858 | 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 |
2,859 | 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 |
2,860 | 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 |
2,861 | 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 |
2,862 | 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 |
2,863 | 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 |
2,864 | 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 |
2,865 | 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 |
2,866 | 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 |
2,867 | 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 |
2,868 | 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 |
2,869 | 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 |
2,870 | 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 |
2,871 | 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 |
2,872 | 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\"",
")",
")",
";",
"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",
"}",
";",
"}"
] | 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 |
2,873 | 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 |
2,874 | 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 |
2,875 | 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",
")",
"{",
"/*\n * in case if return statement ends with ');' we have traverse back to ')'\n * otherwise we'll measure indent for ';' and replace ')'\n */",
"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",
")",
";",
"}",
"}"
] | 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 |
2,876 | 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 |
2,877 | 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 |
2,878 | 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 |
2,879 | 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 |
2,880 | 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 |
2,881 | 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 |
2,882 | 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",
")",
"{",
"// 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",
";",
"}"
] | 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 |
2,883 | 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 |
2,884 | 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",
")",
")",
"{",
"// `left` is deeper than `right` normally.",
"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 |
2,885 | 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",
")",
")",
"{",
"// `left` is deeper than `right` normally.",
"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 |
2,886 | 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 |
2,887 | 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\"",
")",
"{",
"/*\n * If the current node is a string literal, escape any instances of ${ or ` to prevent them from being interpreted\n * as a template placeholder. However, if the code already contains a backslash before the ${ or `\n * for some reason, don't add another backslash, because that would change the meaning of the code (it would cause\n * an actual backslash character to appear before the dollar sign).\n */",
"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",
")",
";",
"}",
"/*\n * Otherwise, these nodes should not be combined into a template curly, since there is nowhere to put\n * the text between them.\n */",
"return",
"`",
"${",
"getTemplateLiteral",
"(",
"currentNode",
".",
"left",
",",
"textBeforeNode",
",",
"null",
")",
"}",
"${",
"textBeforePlus",
"}",
"${",
"textAfterPlus",
"}",
"${",
"getTemplateLiteral",
"(",
"currentNode",
".",
"right",
",",
"textAfterNode",
",",
"null",
")",
"}",
"`",
";",
"}",
"return",
"`",
"\\`",
"\\$",
"${",
"textBeforeNode",
"||",
"\"\"",
"}",
"${",
"sourceCode",
".",
"getText",
"(",
"currentNode",
")",
"}",
"${",
"textAfterNode",
"||",
"\"\"",
"}",
"\\`",
"`",
";",
"}"
] | 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 |
2,888 | 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 |
2,889 | 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",
")",
";",
"// 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",
")",
"}",
")",
";",
"}",
"}"
] | 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 |
2,890 | 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 |
2,891 | 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 |
2,892 | 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",
")",
"||",
"(",
"// 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",
";",
"}"
] | 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 |
2,893 | 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 |
2,894 | 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 |
2,895 | 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 |
2,896 | 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 |
2,897 | 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 |
2,898 | 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\"",
";",
"}",
"// 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",
")",
";",
"}"
] | 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 |
2,899 | 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 |
Subsets and Splits