tools: update ESLint to 5.15.2

Update ESLint to 5.15.2

PR-URL: https://github.com/nodejs/node/pull/26687
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
cjihrig 2019-03-15 13:40:34 -04:00 committed by Daniel Bevenius
parent bab5544476
commit 1ceb6d8e9b
10 changed files with 66 additions and 56 deletions

View File

@ -268,7 +268,7 @@ The following companies, organizations, and individuals support ESLint's ongoing
<h3>Gold Sponsors</h3> <h3>Gold Sponsors</h3>
<p><a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F098e3bd0-4d57-11e8-9324-0f6cc1f92bf1.png&height=96" alt="Airbnb" height="96"></a> <a href="https://code.facebook.com/projects/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fres.cloudinary.com%2Fopencollective%2Fimage%2Fupload%2Fv1508519428%2FS9gk78AS_400x400_fulq2l.jpg&height=96" alt="Facebook Open Source" height="96"></a> <a href="https://badoo.com/team?utm_source=eslint"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2Fbbdb9cc0-3b5d-11e9-9537-ad85092287b8.png&height=96" alt="Badoo" height="96"></a></p><h3>Silver Sponsors</h3> <p><a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F098e3bd0-4d57-11e8-9324-0f6cc1f92bf1.png&height=96" alt="Airbnb" height="96"></a> <a href="https://code.facebook.com/projects/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fres.cloudinary.com%2Fopencollective%2Fimage%2Fupload%2Fv1508519428%2FS9gk78AS_400x400_fulq2l.jpg&height=96" alt="Facebook Open Source" height="96"></a> <a href="https://badoo.com/team?utm_source=eslint"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2Fbbdb9cc0-3b5d-11e9-9537-ad85092287b8.png&height=96" alt="Badoo" height="96"></a></p><h3>Silver Sponsors</h3>
<p><a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F68ed8b70-ebf2-11e6-9958-cb7e79408c56.png&height=96" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3> <p><a href="https://www.ampproject.org/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Fopencollective-production.s3-us-west-1.amazonaws.com%2F68ed8b70-ebf2-11e6-9958-cb7e79408c56.png&height=96" alt="AMP Project" height="64"></a></p><h3>Bronze Sponsors</h3>
<p><a href="http://faithlife.com/ref/about"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Flogo.clearbit.com%2Ffaithlife.com&height=96" alt="Faithlife" height="32"></a></p> <p><a href="http://faithlife.com/ref/about"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Flogo.clearbit.com%2Ffaithlife.com&height=96" alt="Faithlife" height="32"></a> <a href="https://jsheroes.io/"><img src="https://images.opencollective.com/proxy/images/?src=https%3A%2F%2Flogo.clearbit.com%2Fjsheroes.io&height=96" alt="JSHeroes " height="32"></a></p>
<!--sponsorsend--> <!--sponsorsend-->
## Technology Sponsors ## Technology Sponsors

View File

@ -541,7 +541,7 @@ function loadFromDisk(resolvedPath, configContext) {
const ruleMap = configContext.linterContext.getRules(); const ruleMap = configContext.linterContext.getRules();
// validate the configuration before continuing // validate the configuration before continuing
validator.validate(config, resolvedPath.configFullName, ruleMap.get.bind(ruleMap), configContext.linterContext.environments); validator.validate(config, ruleMap.get.bind(ruleMap), configContext.linterContext.environments, resolvedPath.configFullName);
/* /*
* If an `extends` property is defined, it represents a configuration file to use as * If an `extends` property is defined, it represents a configuration file to use as

View File

@ -116,7 +116,7 @@ function validateRuleSchema(rule, localOptions) {
* no source is prepended to the message. * no source is prepended to the message.
* @returns {void} * @returns {void}
*/ */
function validateRuleOptions(rule, ruleId, options, source) { function validateRuleOptions(rule, ruleId, options, source = null) {
if (!rule) { if (!rule) {
return; return;
} }
@ -140,11 +140,11 @@ function validateRuleOptions(rule, ruleId, options, source) {
/** /**
* Validates an environment object * Validates an environment object
* @param {Object} environment The environment config object to validate. * @param {Object} environment The environment config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {Environments} envContext Env context * @param {Environments} envContext Env context
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void} * @returns {void}
*/ */
function validateEnvironment(environment, source, envContext) { function validateEnvironment(environment, envContext, source = null) {
// not having an environment is ok // not having an environment is ok
if (!environment) { if (!environment) {
@ -163,11 +163,11 @@ function validateEnvironment(environment, source, envContext) {
/** /**
* Validates a rules config object * Validates a rules config object
* @param {Object} rulesConfig The rules config object to validate. * @param {Object} rulesConfig The rules config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {function(string): {create: Function}} ruleMapper A mapper function from strings to loaded rules * @param {function(string): {create: Function}} ruleMapper A mapper function from strings to loaded rules
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void} * @returns {void}
*/ */
function validateRules(rulesConfig, source, ruleMapper) { function validateRules(rulesConfig, ruleMapper, source = null) {
if (!rulesConfig) { if (!rulesConfig) {
return; return;
} }
@ -228,7 +228,7 @@ const emitDeprecationWarning = lodash.memoize((source, errorCode) => {
* @param {string} source The name of the configuration source to report in any errors. * @param {string} source The name of the configuration source to report in any errors.
* @returns {void} * @returns {void}
*/ */
function validateConfigSchema(config, source) { function validateConfigSchema(config, source = null) {
validateSchema = validateSchema || ajv.compile(configSchema); validateSchema = validateSchema || ajv.compile(configSchema);
if (!validateSchema(config)) { if (!validateSchema(config)) {
@ -252,19 +252,19 @@ function validateConfigSchema(config, source) {
/** /**
* Validates an entire config object. * Validates an entire config object.
* @param {Object} config The config object to validate. * @param {Object} config The config object to validate.
* @param {string} source The name of the configuration source to report in any errors.
* @param {function(string): {create: Function}} ruleMapper A mapper function from rule IDs to defined rules * @param {function(string): {create: Function}} ruleMapper A mapper function from rule IDs to defined rules
* @param {Environments} envContext The env context * @param {Environments} envContext The env context
* @param {string} source The name of the configuration source to report in any errors.
* @returns {void} * @returns {void}
*/ */
function validate(config, source, ruleMapper, envContext) { function validate(config, ruleMapper, envContext, source = null) {
validateConfigSchema(config, source); validateConfigSchema(config, source);
validateRules(config.rules, source, ruleMapper); validateRules(config.rules, ruleMapper, source);
validateEnvironment(config.env, source, envContext); validateEnvironment(config.env, envContext, source);
for (const override of config.overrides || []) { for (const override of config.overrides || []) {
validateRules(override.rules, source, ruleMapper); validateRules(override.rules, ruleMapper, source);
validateEnvironment(override.env, source, envContext); validateEnvironment(override.env, envContext, source);
} }
} }

View File

@ -747,11 +747,16 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
nodeQueue.forEach(traversalInfo => { nodeQueue.forEach(traversalInfo => {
currentNode = traversalInfo.node; currentNode = traversalInfo.node;
try {
if (traversalInfo.isEntering) { if (traversalInfo.isEntering) {
eventGenerator.enterNode(currentNode); eventGenerator.enterNode(currentNode);
} else { } else {
eventGenerator.leaveNode(currentNode); eventGenerator.leaveNode(currentNode);
} }
} catch (err) {
err.currentNode = currentNode;
throw err;
}
}); });
return lintingProblems; return lintingProblems;
@ -901,8 +906,15 @@ module.exports = class Linter {
options.filename options.filename
); );
} catch (err) { } catch (err) {
err.message += `\nOccurred while linting ${options.filename}`;
debug("An error occurred while traversing"); debug("An error occurred while traversing");
debug("Filename:", options.filename); debug("Filename:", options.filename);
if (err.currentNode) {
const { line } = err.currentNode.loc.start;
debug("Line:", line);
err.message += `:${line}`;
}
debug("Parser Options:", parserOptions); debug("Parser Options:", parserOptions);
debug("Parser Path:", parserName); debug("Parser Path:", parserName);
debug("Settings:", settings); debug("Settings:", settings);

View File

@ -6,8 +6,7 @@
const { const {
isArrowToken, isArrowToken,
isParenthesised, isParenthesised
isOpeningParenToken
} = require("../util/ast-utils"); } = require("../util/ast-utils");
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
@ -57,8 +56,7 @@ module.exports = {
* @param {Integer} column The column number of the first token * @param {Integer} column The column number of the first token
* @returns {string} A string of comment text joined by line breaks * @returns {string} A string of comment text joined by line breaks
*/ */
function formatComments(comments, column) { function formatComments(comments) {
const whiteSpaces = " ".repeat(column);
return `${comments.map(comment => { return `${comments.map(comment => {
@ -67,12 +65,12 @@ module.exports = {
} }
return `/*${comment.value}*/`; return `/*${comment.value}*/`;
}).join(`\n${whiteSpaces}`)}\n${whiteSpaces}`; }).join("\n")}\n`;
} }
/** /**
* Finds the first token to prepend comments to depending on the parent type * Finds the first token to prepend comments to depending on the parent type
* @param {Node} node The validated node * @param {ASTNode} node The validated node
* @returns {Token|Node} The node to prepend comments to * @returns {Token|Node} The node to prepend comments to
*/ */
function findFirstToken(node) { function findFirstToken(node) {
@ -109,24 +107,19 @@ module.exports = {
let followingBody = arrowBody; let followingBody = arrowBody;
let currentArrow = arrow; let currentArrow = arrow;
while (currentArrow) { while (currentArrow && followingBody.type !== "BlockStatement") {
if (!isParenthesised(sourceCode, followingBody)) { if (!isParenthesised(sourceCode, followingBody)) {
parenthesesFixes.push( parenthesesFixes.push(
fixer.insertTextAfter(currentArrow, " (") fixer.insertTextAfter(currentArrow, " (")
); );
const paramsToken = sourceCode.getTokenBefore(currentArrow, token => closingParentheses = `\n)${closingParentheses}`;
isOpeningParenToken(token) || token.type === "Identifier");
const whiteSpaces = " ".repeat(paramsToken.loc.start.column);
closingParentheses = `\n${whiteSpaces})${closingParentheses}`;
} }
currentArrow = sourceCode.getTokenAfter(currentArrow, isArrowToken); currentArrow = sourceCode.getTokenAfter(currentArrow, isArrowToken);
if (currentArrow) { if (currentArrow) {
followingBody = sourceCode.getTokenAfter(currentArrow, token => !isOpeningParenToken(token)); followingBody = followingBody.body;
} }
} }
@ -137,10 +130,10 @@ module.exports = {
/** /**
* Autofixes the function body to collapse onto the same line as the arrow. * Autofixes the function body to collapse onto the same line as the arrow.
* If comments exist, prepends the comments before the arrow function. * If comments exist, checks if the function body contains arrow functions, and appends the body with parentheses.
* If the function body contains arrow functions, appends the function bodies with parentheses. * Otherwise, prepends the comments before the arrow function.
* @param {Token} arrowToken The arrow token. * @param {Token} arrowToken The arrow token.
* @param {ASTNode} arrowBody the function body * @param {ASTNode|Token} arrowBody the function body
* @param {ASTNode} node The evaluated node * @param {ASTNode} node The evaluated node
* @returns {Function} autofixer -- validates the node to adhere to besides * @returns {Function} autofixer -- validates the node to adhere to besides
*/ */
@ -161,23 +154,18 @@ module.exports = {
) { ) {
// If any arrow functions follow, return the necessary parens fixes. // If any arrow functions follow, return the necessary parens fixes.
if (sourceCode.getTokenAfter(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") { if (node.body.type === "ArrowFunctionExpression" &&
arrowBody.parent.parent.type !== "VariableDeclarator"
) {
return addParentheses(fixer, arrowToken, arrowBody); return addParentheses(fixer, arrowToken, arrowBody);
} }
// If any arrow functions precede, the necessary fixes have already been returned, so return null.
if (sourceCode.getTokenBefore(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") {
return null;
}
} }
const firstToken = findFirstToken(node); const firstToken = findFirstToken(node);
const commentText = formatComments(comments, firstToken.loc.start.column);
const commentBeforeExpression = fixer.insertTextBeforeRange( const commentBeforeExpression = fixer.insertTextBeforeRange(
firstToken.range, firstToken.range,
commentText formatComments(comments)
); );
return [placeBesides, commentBeforeExpression]; return [placeBesides, commentBeforeExpression];

View File

@ -379,7 +379,7 @@ class RuleTester {
} }
} }
validator.validate(config, "rule-tester", ruleMap.get.bind(ruleMap), new Environments()); validator.validate(config, ruleMap.get.bind(ruleMap), new Environments(), "rule-tester");
return { return {
messages: linter.verify(code, config, filename, true), messages: linter.verify(code, config, filename, true),

View File

@ -70,6 +70,10 @@ function processPath(options) {
* @private * @private
*/ */
return function(pathname) { return function(pathname) {
if (pathname === "") {
return "";
}
let newPath = pathname; let newPath = pathname;
const resolvedPath = path.resolve(cwd, pathname); const resolvedPath = path.resolve(cwd, pathname);
@ -201,6 +205,13 @@ function listFilesToProcess(globPatterns, providedOptions) {
debug("Creating list of files to process."); debug("Creating list of files to process.");
const resolvedPathsByGlobPattern = resolvedGlobPatterns.map(pattern => { const resolvedPathsByGlobPattern = resolvedGlobPatterns.map(pattern => {
if (pattern === "") {
return [{
filename: "",
behavior: SILENTLY_IGNORE
}];
}
const file = path.resolve(cwd, pattern); const file = path.resolve(cwd, pattern);
if (options.globInputPaths === false || (fs.existsSync(file) && fs.statSync(file).isFile())) { if (options.globInputPaths === false || (fs.existsSync(file) && fs.statSync(file).isFile())) {
@ -240,7 +251,7 @@ function listFilesToProcess(globPatterns, providedOptions) {
}); });
const allPathDescriptors = resolvedPathsByGlobPattern.reduce((pathsForAllGlobs, pathsForCurrentGlob, index) => { const allPathDescriptors = resolvedPathsByGlobPattern.reduce((pathsForAllGlobs, pathsForCurrentGlob, index) => {
if (pathsForCurrentGlob.every(pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE)) { if (pathsForCurrentGlob.every(pathDescriptor => pathDescriptor.behavior === SILENTLY_IGNORE && pathDescriptor.filename !== "")) {
throw new (pathsForCurrentGlob.length ? AllFilesIgnoredError : NoFilesFoundError)(globPatterns[index]); throw new (pathsForCurrentGlob.length ? AllFilesIgnoredError : NoFilesFoundError)(globPatterns[index]);
} }

View File

@ -49,11 +49,6 @@ function isStrictScope(scope, block, isMethodDefinition, useDirective) {
return true; return true;
} }
// ArrowFunctionExpression's scope is always strict scope.
if (block.type === Syntax.ArrowFunctionExpression) {
return true;
}
if (isMethodDefinition) { if (isMethodDefinition) {
return true; return true;
} }
@ -67,6 +62,10 @@ function isStrictScope(scope, block, isMethodDefinition, useDirective) {
} }
if (scope.type === "function") { if (scope.type === "function") {
if (block.type === Syntax.ArrowFunctionExpression && block.body.type !== Syntax.BlockStatement) {
return false;
}
if (block.type === Syntax.Program) { if (block.type === Syntax.Program) {
body = block; body = block;
} else { } else {

View File

@ -47,5 +47,5 @@
"publish-release": "eslint-publish-release", "publish-release": "eslint-publish-release",
"test": "node Makefile.js test" "test": "node Makefile.js test"
}, },
"version": "4.0.2" "version": "4.0.3"
} }

View File

@ -18,7 +18,7 @@
"debug": "^4.0.1", "debug": "^4.0.1",
"doctrine": "^3.0.0", "doctrine": "^3.0.0",
"eslint-plugin-markdown": "^1.0.0", "eslint-plugin-markdown": "^1.0.0",
"eslint-scope": "^4.0.2", "eslint-scope": "^4.0.3",
"eslint-utils": "^1.3.1", "eslint-utils": "^1.3.1",
"eslint-visitor-keys": "^1.0.0", "eslint-visitor-keys": "^1.0.0",
"espree": "^5.0.1", "espree": "^5.0.1",
@ -64,11 +64,11 @@
"coveralls": "^3.0.1", "coveralls": "^3.0.1",
"dateformat": "^3.0.3", "dateformat": "^3.0.3",
"ejs": "^2.6.1", "ejs": "^2.6.1",
"eslint-config-eslint": "file:packages/eslint-config-eslint",
"eslint-plugin-eslint-plugin": "^2.0.1", "eslint-plugin-eslint-plugin": "^2.0.1",
"eslint-plugin-internal-rules": "file:tools/internal-rules",
"eslint-plugin-node": "^8.0.0", "eslint-plugin-node": "^8.0.0",
"eslint-plugin-rulesdir": "^0.1.0",
"eslint-release": "^1.2.0", "eslint-release": "^1.2.0",
"eslint-rule-composer": "^0.3.0",
"eslump": "^2.0.0", "eslump": "^2.0.0",
"esprima": "^4.0.1", "esprima": "^4.0.1",
"istanbul": "^0.4.5", "istanbul": "^0.4.5",
@ -135,5 +135,5 @@
"test": "node Makefile.js test", "test": "node Makefile.js test",
"webpack": "node Makefile.js webpack" "webpack": "node Makefile.js webpack"
}, },
"version": "5.15.1" "version": "5.15.2"
} }