From 30d7f67e0f84456e689fe88597886cac6984e8b1 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 15 Mar 2019 13:40:34 -0400 Subject: [PATCH] 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 Reviewed-By: Ruben Bridgewater Reviewed-By: Rich Trott --- tools/node_modules/eslint/README.md | 2 +- .../eslint/lib/config/config-file.js | 2 +- .../eslint/lib/config/config-validator.js | 24 +++++------ tools/node_modules/eslint/lib/linter.js | 20 ++++++++-- .../lib/rules/implicit-arrow-linebreak.js | 40 +++++++------------ .../eslint/lib/testers/rule-tester.js | 2 +- .../eslint/lib/util/glob-utils.js | 13 +++++- .../node_modules/eslint-scope/lib/scope.js | 9 ++--- .../node_modules/eslint-scope/package.json | 2 +- tools/node_modules/eslint/package.json | 8 ++-- 10 files changed, 66 insertions(+), 56 deletions(-) diff --git a/tools/node_modules/eslint/README.md b/tools/node_modules/eslint/README.md index 8ac9fbe4d5cb05..437794dc650483 100644 --- a/tools/node_modules/eslint/README.md +++ b/tools/node_modules/eslint/README.md @@ -268,7 +268,7 @@ The following companies, organizations, and individuals support ESLint's ongoing

Gold Sponsors

Airbnb Facebook Open Source Badoo

Silver Sponsors

AMP Project

Bronze Sponsors

-

Faithlife

+

Faithlife JSHeroes

## Technology Sponsors diff --git a/tools/node_modules/eslint/lib/config/config-file.js b/tools/node_modules/eslint/lib/config/config-file.js index 492800b7a3cf6a..80344f50973df2 100644 --- a/tools/node_modules/eslint/lib/config/config-file.js +++ b/tools/node_modules/eslint/lib/config/config-file.js @@ -541,7 +541,7 @@ function loadFromDisk(resolvedPath, configContext) { const ruleMap = configContext.linterContext.getRules(); // 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 diff --git a/tools/node_modules/eslint/lib/config/config-validator.js b/tools/node_modules/eslint/lib/config/config-validator.js index 2345b28893c6e4..386db77750238d 100644 --- a/tools/node_modules/eslint/lib/config/config-validator.js +++ b/tools/node_modules/eslint/lib/config/config-validator.js @@ -116,7 +116,7 @@ function validateRuleSchema(rule, localOptions) { * no source is prepended to the message. * @returns {void} */ -function validateRuleOptions(rule, ruleId, options, source) { +function validateRuleOptions(rule, ruleId, options, source = null) { if (!rule) { return; } @@ -140,11 +140,11 @@ function validateRuleOptions(rule, ruleId, options, source) { /** * Validates an environment object * @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 {string} source The name of the configuration source to report in any errors. * @returns {void} */ -function validateEnvironment(environment, source, envContext) { +function validateEnvironment(environment, envContext, source = null) { // not having an environment is ok if (!environment) { @@ -163,11 +163,11 @@ function validateEnvironment(environment, source, envContext) { /** * Validates a rules config object * @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 {string} source The name of the configuration source to report in any errors. * @returns {void} */ -function validateRules(rulesConfig, source, ruleMapper) { +function validateRules(rulesConfig, ruleMapper, source = null) { if (!rulesConfig) { 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. * @returns {void} */ -function validateConfigSchema(config, source) { +function validateConfigSchema(config, source = null) { validateSchema = validateSchema || ajv.compile(configSchema); if (!validateSchema(config)) { @@ -252,19 +252,19 @@ function validateConfigSchema(config, source) { /** * Validates an entire config object. * @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 {Environments} envContext The env context + * @param {string} source The name of the configuration source to report in any errors. * @returns {void} */ -function validate(config, source, ruleMapper, envContext) { +function validate(config, ruleMapper, envContext, source = null) { validateConfigSchema(config, source); - validateRules(config.rules, source, ruleMapper); - validateEnvironment(config.env, source, envContext); + validateRules(config.rules, ruleMapper, source); + validateEnvironment(config.env, envContext, source); for (const override of config.overrides || []) { - validateRules(override.rules, source, ruleMapper); - validateEnvironment(override.env, source, envContext); + validateRules(override.rules, ruleMapper, source); + validateEnvironment(override.env, envContext, source); } } diff --git a/tools/node_modules/eslint/lib/linter.js b/tools/node_modules/eslint/lib/linter.js index 88448d90f8aa5f..be38b99087de74 100644 --- a/tools/node_modules/eslint/lib/linter.js +++ b/tools/node_modules/eslint/lib/linter.js @@ -747,10 +747,15 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser nodeQueue.forEach(traversalInfo => { currentNode = traversalInfo.node; - if (traversalInfo.isEntering) { - eventGenerator.enterNode(currentNode); - } else { - eventGenerator.leaveNode(currentNode); + try { + if (traversalInfo.isEntering) { + eventGenerator.enterNode(currentNode); + } else { + eventGenerator.leaveNode(currentNode); + } + } catch (err) { + err.currentNode = currentNode; + throw err; } }); @@ -901,8 +906,15 @@ module.exports = class Linter { options.filename ); } catch (err) { + err.message += `\nOccurred while linting ${options.filename}`; debug("An error occurred while traversing"); 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 Path:", parserName); debug("Settings:", settings); diff --git a/tools/node_modules/eslint/lib/rules/implicit-arrow-linebreak.js b/tools/node_modules/eslint/lib/rules/implicit-arrow-linebreak.js index ad0d70da66cc76..50f64561847b9f 100644 --- a/tools/node_modules/eslint/lib/rules/implicit-arrow-linebreak.js +++ b/tools/node_modules/eslint/lib/rules/implicit-arrow-linebreak.js @@ -6,8 +6,7 @@ const { isArrowToken, - isParenthesised, - isOpeningParenToken + isParenthesised } = require("../util/ast-utils"); //------------------------------------------------------------------------------ @@ -57,8 +56,7 @@ module.exports = { * @param {Integer} column The column number of the first token * @returns {string} A string of comment text joined by line breaks */ - function formatComments(comments, column) { - const whiteSpaces = " ".repeat(column); + function formatComments(comments) { return `${comments.map(comment => { @@ -67,12 +65,12 @@ module.exports = { } return `/*${comment.value}*/`; - }).join(`\n${whiteSpaces}`)}\n${whiteSpaces}`; + }).join("\n")}\n`; } /** * 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 */ function findFirstToken(node) { @@ -109,24 +107,19 @@ module.exports = { let followingBody = arrowBody; let currentArrow = arrow; - while (currentArrow) { + while (currentArrow && followingBody.type !== "BlockStatement") { if (!isParenthesised(sourceCode, followingBody)) { parenthesesFixes.push( fixer.insertTextAfter(currentArrow, " (") ); - const paramsToken = sourceCode.getTokenBefore(currentArrow, token => - isOpeningParenToken(token) || token.type === "Identifier"); - - const whiteSpaces = " ".repeat(paramsToken.loc.start.column); - - closingParentheses = `\n${whiteSpaces})${closingParentheses}`; + closingParentheses = `\n)${closingParentheses}`; } currentArrow = sourceCode.getTokenAfter(currentArrow, isArrowToken); 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. - * If comments exist, prepends the comments before the arrow function. - * If the function body contains arrow functions, appends the function bodies with parentheses. + * If comments exist, checks if the function body contains arrow functions, and appends the body with parentheses. + * Otherwise, prepends the comments before the arrow function. * @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 * @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 (sourceCode.getTokenAfter(arrowToken, isArrowToken) && arrowBody.parent.parent.type !== "VariableDeclarator") { + if (node.body.type === "ArrowFunctionExpression" && + arrowBody.parent.parent.type !== "VariableDeclarator" + ) { 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 commentText = formatComments(comments, firstToken.loc.start.column); - const commentBeforeExpression = fixer.insertTextBeforeRange( firstToken.range, - commentText + formatComments(comments) ); return [placeBesides, commentBeforeExpression]; diff --git a/tools/node_modules/eslint/lib/testers/rule-tester.js b/tools/node_modules/eslint/lib/testers/rule-tester.js index 6d1bba989fdeea..f1d915531323a0 100644 --- a/tools/node_modules/eslint/lib/testers/rule-tester.js +++ b/tools/node_modules/eslint/lib/testers/rule-tester.js @@ -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 { messages: linter.verify(code, config, filename, true), diff --git a/tools/node_modules/eslint/lib/util/glob-utils.js b/tools/node_modules/eslint/lib/util/glob-utils.js index b05c354439dc42..33cb8e7c885a17 100644 --- a/tools/node_modules/eslint/lib/util/glob-utils.js +++ b/tools/node_modules/eslint/lib/util/glob-utils.js @@ -70,6 +70,10 @@ function processPath(options) { * @private */ return function(pathname) { + if (pathname === "") { + return ""; + } + let newPath = pathname; const resolvedPath = path.resolve(cwd, pathname); @@ -201,6 +205,13 @@ function listFilesToProcess(globPatterns, providedOptions) { debug("Creating list of files to process."); const resolvedPathsByGlobPattern = resolvedGlobPatterns.map(pattern => { + if (pattern === "") { + return [{ + filename: "", + behavior: SILENTLY_IGNORE + }]; + } + const file = path.resolve(cwd, pattern); 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) => { - 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]); } diff --git a/tools/node_modules/eslint/node_modules/eslint-scope/lib/scope.js b/tools/node_modules/eslint/node_modules/eslint-scope/lib/scope.js index b3c5040bb1ae1c..f0c3006c601f62 100644 --- a/tools/node_modules/eslint/node_modules/eslint-scope/lib/scope.js +++ b/tools/node_modules/eslint/node_modules/eslint-scope/lib/scope.js @@ -49,11 +49,6 @@ function isStrictScope(scope, block, isMethodDefinition, useDirective) { return true; } - // ArrowFunctionExpression's scope is always strict scope. - if (block.type === Syntax.ArrowFunctionExpression) { - return true; - } - if (isMethodDefinition) { return true; } @@ -67,6 +62,10 @@ function isStrictScope(scope, block, isMethodDefinition, useDirective) { } if (scope.type === "function") { + if (block.type === Syntax.ArrowFunctionExpression && block.body.type !== Syntax.BlockStatement) { + return false; + } + if (block.type === Syntax.Program) { body = block; } else { diff --git a/tools/node_modules/eslint/node_modules/eslint-scope/package.json b/tools/node_modules/eslint/node_modules/eslint-scope/package.json index 1d38e549770ca7..f3239af383b050 100644 --- a/tools/node_modules/eslint/node_modules/eslint-scope/package.json +++ b/tools/node_modules/eslint/node_modules/eslint-scope/package.json @@ -47,5 +47,5 @@ "publish-release": "eslint-publish-release", "test": "node Makefile.js test" }, - "version": "4.0.2" + "version": "4.0.3" } \ No newline at end of file diff --git a/tools/node_modules/eslint/package.json b/tools/node_modules/eslint/package.json index c07c99868f1a43..885af12a72ba4d 100644 --- a/tools/node_modules/eslint/package.json +++ b/tools/node_modules/eslint/package.json @@ -18,7 +18,7 @@ "debug": "^4.0.1", "doctrine": "^3.0.0", "eslint-plugin-markdown": "^1.0.0", - "eslint-scope": "^4.0.2", + "eslint-scope": "^4.0.3", "eslint-utils": "^1.3.1", "eslint-visitor-keys": "^1.0.0", "espree": "^5.0.1", @@ -64,11 +64,11 @@ "coveralls": "^3.0.1", "dateformat": "^3.0.3", "ejs": "^2.6.1", + "eslint-config-eslint": "file:packages/eslint-config-eslint", "eslint-plugin-eslint-plugin": "^2.0.1", + "eslint-plugin-internal-rules": "file:tools/internal-rules", "eslint-plugin-node": "^8.0.0", - "eslint-plugin-rulesdir": "^0.1.0", "eslint-release": "^1.2.0", - "eslint-rule-composer": "^0.3.0", "eslump": "^2.0.0", "esprima": "^4.0.1", "istanbul": "^0.4.5", @@ -135,5 +135,5 @@ "test": "node Makefile.js test", "webpack": "node Makefile.js webpack" }, - "version": "5.15.1" + "version": "5.15.2" } \ No newline at end of file