aboutsummaryrefslogtreecommitdiff
path: root/tools/node_modules/eslint/lib
diff options
context:
space:
mode:
authorRich Trott <rtrott@gmail.com>2019-02-01 11:44:36 -0800
committerRich Trott <rtrott@gmail.com>2019-02-03 16:46:26 -0800
commit7540f9dbe8114c62e0ec7d751bf2a36998514b2c (patch)
tree1fe235430de7fd84606affb77b6fb68bf516915a /tools/node_modules/eslint/lib
parentb322b76dad5b05e20586622cdc86c83367e863e1 (diff)
downloadandroid-node-v8-7540f9dbe8114c62e0ec7d751bf2a36998514b2c.tar.gz
android-node-v8-7540f9dbe8114c62e0ec7d751bf2a36998514b2c.tar.bz2
android-node-v8-7540f9dbe8114c62e0ec7d751bf2a36998514b2c.zip
tools: update ESLint to 5.13.0
PR-URL: https://github.com/nodejs/node/pull/25877 Reviewed-By: Michaƫl Zasso <targos@protonmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Yuta Hiroto <hello@hiroppy.me>
Diffstat (limited to 'tools/node_modules/eslint/lib')
-rw-r--r--tools/node_modules/eslint/lib/cli-engine.js5
-rw-r--r--tools/node_modules/eslint/lib/config.js2
-rw-r--r--tools/node_modules/eslint/lib/config/config-ops.js28
-rw-r--r--tools/node_modules/eslint/lib/config/config-rule.js6
-rw-r--r--tools/node_modules/eslint/lib/config/plugins.js16
-rw-r--r--tools/node_modules/eslint/lib/formatters/table.js17
-rw-r--r--tools/node_modules/eslint/lib/linter.js62
-rw-r--r--tools/node_modules/eslint/lib/load-rules.js7
-rw-r--r--tools/node_modules/eslint/lib/rules.js45
-rw-r--r--tools/node_modules/eslint/lib/rules/for-direction.js47
-rw-r--r--tools/node_modules/eslint/lib/rules/no-constant-condition.js20
-rw-r--r--tools/node_modules/eslint/lib/rules/object-shorthand.js2
-rw-r--r--tools/node_modules/eslint/lib/util/config-comment-parser.js17
13 files changed, 152 insertions, 122 deletions
diff --git a/tools/node_modules/eslint/lib/cli-engine.js b/tools/node_modules/eslint/lib/cli-engine.js
index ce9fe289b8..d7de2592a1 100644
--- a/tools/node_modules/eslint/lib/cli-engine.js
+++ b/tools/node_modules/eslint/lib/cli-engine.js
@@ -29,7 +29,8 @@ const fs = require("fs"),
hash = require("./util/hash"),
ModuleResolver = require("./util/module-resolver"),
naming = require("./util/naming"),
- pkg = require("../package.json");
+ pkg = require("../package.json"),
+ loadRules = require("./load-rules");
const debug = require("debug")("eslint:cli-engine");
const resolver = new ModuleResolver();
@@ -447,7 +448,7 @@ class CLIEngine {
this.options.rulePaths.forEach(rulesdir => {
debug(`Loading rules from ${rulesdir}`);
- this.linter.rules.load(rulesdir, cwd);
+ this.linter.defineRules(loadRules(rulesdir, cwd));
});
}
diff --git a/tools/node_modules/eslint/lib/config.js b/tools/node_modules/eslint/lib/config.js
index abcb38b50d..9c8438859e 100644
--- a/tools/node_modules/eslint/lib/config.js
+++ b/tools/node_modules/eslint/lib/config.js
@@ -71,7 +71,7 @@ class Config {
const options = providedOptions || {};
this.linterContext = linterContext;
- this.plugins = new Plugins(linterContext.environments, linterContext.rules);
+ this.plugins = new Plugins(linterContext.environments, linterContext.defineRule.bind(linterContext));
this.options = options;
this.ignore = options.ignore;
diff --git a/tools/node_modules/eslint/lib/config/config-ops.js b/tools/node_modules/eslint/lib/config/config-ops.js
index 6c298d3647..48f38b4905 100644
--- a/tools/node_modules/eslint/lib/config/config-ops.js
+++ b/tools/node_modules/eslint/lib/config/config-ops.js
@@ -370,5 +370,33 @@ module.exports = {
return patternList.some(pattern => minimatch(filePath, pattern, opts)) &&
!excludedPatternList.some(excludedPattern => minimatch(filePath, excludedPattern, opts));
+ },
+
+ /**
+ * Normalizes a value for a global in a config
+ * @param {(boolean|string|null)} configuredValue The value given for a global in configuration or in
+ * a global directive comment
+ * @returns {("readable"|"writeable"|"off")} The value normalized as a string
+ */
+ normalizeConfigGlobal(configuredValue) {
+ switch (configuredValue) {
+ case "off":
+ return "off";
+
+ case true:
+ case "true":
+ case "writeable":
+ return "writeable";
+
+ case null:
+ case false:
+ case "false":
+ case "readable":
+ return "readable";
+
+ // Fallback to minimize compatibility impact
+ default:
+ return "writeable";
+ }
}
};
diff --git a/tools/node_modules/eslint/lib/config/config-rule.js b/tools/node_modules/eslint/lib/config/config-rule.js
index e4221406df..29aac0b9a1 100644
--- a/tools/node_modules/eslint/lib/config/config-rule.js
+++ b/tools/node_modules/eslint/lib/config/config-rule.js
@@ -10,7 +10,7 @@
//------------------------------------------------------------------------------
const Rules = require("../rules"),
- loadRules = require("../load-rules");
+ builtInRules = require("../built-in-rules-index");
const rules = new Rules();
@@ -299,9 +299,7 @@ function generateConfigsFromSchema(schema) {
* @returns {rulesConfig} Hash of rule names and arrays of possible configurations
*/
function createCoreRuleConfigs() {
- const ruleList = loadRules();
-
- return Object.keys(ruleList).reduce((accumulator, id) => {
+ return Object.keys(builtInRules).reduce((accumulator, id) => {
const rule = rules.get(id);
const schema = (typeof rule === "function") ? rule.schema : rule.meta.schema;
diff --git a/tools/node_modules/eslint/lib/config/plugins.js b/tools/node_modules/eslint/lib/config/plugins.js
index 37c3be497c..f32cc26c33 100644
--- a/tools/node_modules/eslint/lib/config/plugins.js
+++ b/tools/node_modules/eslint/lib/config/plugins.js
@@ -24,12 +24,12 @@ class Plugins {
/**
* Creates the plugins context
* @param {Environments} envContext - env context
- * @param {Rules} rulesContext - rules context
+ * @param {function(string, Rule): void} defineRule - Callback for when a plugin is defined which introduces rules
*/
- constructor(envContext, rulesContext) {
+ constructor(envContext, defineRule) {
this._plugins = Object.create(null);
this._environments = envContext;
- this._rules = rulesContext;
+ this._defineRule = defineRule;
}
/**
@@ -45,7 +45,15 @@ class Plugins {
// load up environments and rules
this._plugins[shortName] = plugin;
this._environments.importPlugin(plugin, shortName);
- this._rules.importPlugin(plugin, shortName);
+
+ if (plugin.rules) {
+ Object.keys(plugin.rules).forEach(ruleId => {
+ const qualifiedRuleId = `${shortName}/${ruleId}`,
+ rule = plugin.rules[ruleId];
+
+ this._defineRule(qualifiedRuleId, rule);
+ });
+ }
}
/**
diff --git a/tools/node_modules/eslint/lib/formatters/table.js b/tools/node_modules/eslint/lib/formatters/table.js
index ebc3314e7a..a74cce0d51 100644
--- a/tools/node_modules/eslint/lib/formatters/table.js
+++ b/tools/node_modules/eslint/lib/formatters/table.js
@@ -9,14 +9,23 @@
//------------------------------------------------------------------------------
const chalk = require("chalk"),
- table = require("table").table,
- pluralize = require("pluralize");
+ table = require("table").table;
//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------
/**
+ * Given a word and a count, append an "s" if count is not one.
+ * @param {string} word A word.
+ * @param {number} count Quantity.
+ * @returns {string} The original word with an s on the end if count is not one.
+ */
+function pluralize(word, count) {
+ return (count === 1 ? word : `${word}s`);
+}
+
+/**
* Draws text table.
* @param {Array<Object>} messages Error messages relating to a specific file.
* @returns {string} A text table.
@@ -129,10 +138,10 @@ module.exports = function(report) {
result += `\n${table([
[
- chalk.red(pluralize("Error", errorCount, true))
+ chalk.red(pluralize(`${errorCount} Error`, errorCount))
],
[
- chalk.yellow(pluralize("Warning", warningCount, true))
+ chalk.yellow(pluralize(`${warningCount} Warning`, warningCount))
]
], {
columns: {
diff --git a/tools/node_modules/eslint/lib/linter.js b/tools/node_modules/eslint/lib/linter.js
index d6d635f9f4..29505e9ac0 100644
--- a/tools/node_modules/eslint/lib/linter.js
+++ b/tools/node_modules/eslint/lib/linter.js
@@ -70,30 +70,30 @@ const commentParser = new ConfigCommentParser();
* @returns {void}
*/
function addDeclaredGlobals(globalScope, configGlobals, commentDirectives) {
- Object.keys(configGlobals).forEach(name => {
- let variable = globalScope.set.get(name);
-
- if (!variable) {
- variable = new eslintScope.Variable(name, globalScope);
- variable.eslintExplicitGlobal = false;
- globalScope.variables.push(variable);
- globalScope.set.set(name, variable);
- }
- variable.writeable = configGlobals[name];
- });
-
- Object.keys(commentDirectives.enabledGlobals).forEach(name => {
- let variable = globalScope.set.get(name);
+ const mergedGlobalsInfo = Object.assign(
+ {},
+ lodash.mapValues(configGlobals, value => ({ sourceComment: null, value: ConfigOps.normalizeConfigGlobal(value) })),
+ lodash.mapValues(commentDirectives.enabledGlobals, ({ comment, value }) => ({ sourceComment: comment, value: ConfigOps.normalizeConfigGlobal(value) }))
+ );
- if (!variable) {
- variable = new eslintScope.Variable(name, globalScope);
- variable.eslintExplicitGlobal = true;
- variable.eslintExplicitGlobalComment = commentDirectives.enabledGlobals[name].comment;
- globalScope.variables.push(variable);
- globalScope.set.set(name, variable);
- }
- variable.writeable = commentDirectives.enabledGlobals[name].value;
- });
+ Object.keys(mergedGlobalsInfo)
+ .filter(name => mergedGlobalsInfo[name].value !== "off")
+ .forEach(name => {
+ let variable = globalScope.set.get(name);
+
+ if (!variable) {
+ variable = new eslintScope.Variable(name, globalScope);
+ if (mergedGlobalsInfo[name].sourceComment === null) {
+ variable.eslintExplicitGlobal = false;
+ } else {
+ variable.eslintExplicitGlobal = true;
+ variable.eslintExplicitGlobalComment = mergedGlobalsInfo[name].sourceComment;
+ }
+ globalScope.variables.push(variable);
+ globalScope.set.set(name, variable);
+ }
+ variable.writeable = (mergedGlobalsInfo[name].value === "writeable");
+ });
// mark all exported variables as such
Object.keys(commentDirectives.exportedVariables).forEach(name => {
@@ -191,12 +191,12 @@ function getDirectiveComments(filename, ast, ruleMapper) {
} else if (comment.type === "Block") {
switch (match[1]) {
case "exported":
- Object.assign(exportedVariables, commentParser.parseBooleanConfig(directiveValue, comment));
+ Object.assign(exportedVariables, commentParser.parseStringConfig(directiveValue, comment));
break;
case "globals":
case "global":
- Object.assign(enabledGlobals, commentParser.parseBooleanConfig(directiveValue, comment));
+ Object.assign(enabledGlobals, commentParser.parseStringConfig(directiveValue, comment));
break;
case "eslint-disable":
@@ -758,6 +758,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
const lastSourceCodes = new WeakMap();
const loadedParserMaps = new WeakMap();
+const ruleMaps = new WeakMap();
//------------------------------------------------------------------------------
// Public Interface
@@ -772,9 +773,8 @@ module.exports = class Linter {
constructor() {
lastSourceCodes.set(this, null);
loadedParserMaps.set(this, new Map());
+ ruleMaps.set(this, new Rules());
this.version = pkg.version;
-
- this.rules = new Rules();
this.environments = new Environments();
}
@@ -873,7 +873,7 @@ module.exports = class Linter {
const sourceCode = lastSourceCodes.get(this);
const commentDirectives = options.allowInlineConfig
- ? getDirectiveComments(options.filename, sourceCode.ast, ruleId => this.rules.get(ruleId))
+ ? getDirectiveComments(options.filename, sourceCode.ast, ruleId => ruleMaps.get(this).get(ruleId))
: { configuredRules: {}, enabledGlobals: {}, exportedVariables: {}, problems: [], disableDirectives: [] };
// augment global scope with declared global variables
@@ -891,7 +891,7 @@ module.exports = class Linter {
lintingProblems = runRules(
sourceCode,
configuredRules,
- ruleId => this.rules.get(ruleId),
+ ruleId => ruleMaps.get(this).get(ruleId),
parserOptions,
parserName,
settings,
@@ -957,7 +957,7 @@ module.exports = class Linter {
* @returns {void}
*/
defineRule(ruleId, ruleModule) {
- this.rules.define(ruleId, ruleModule);
+ ruleMaps.get(this).define(ruleId, ruleModule);
}
/**
@@ -976,7 +976,7 @@ module.exports = class Linter {
* @returns {Map} All loaded rules
*/
getRules() {
- return this.rules.getAllLoadedRules();
+ return ruleMaps.get(this).getAllLoadedRules();
}
/**
diff --git a/tools/node_modules/eslint/lib/load-rules.js b/tools/node_modules/eslint/lib/load-rules.js
index a9da956bdd..a738362465 100644
--- a/tools/node_modules/eslint/lib/load-rules.js
+++ b/tools/node_modules/eslint/lib/load-rules.js
@@ -20,15 +20,12 @@ const rulesDirCache = {};
/**
* Load all rule modules from specified directory.
- * @param {string} [relativeRulesDir] Path to rules directory, may be relative. Defaults to `lib/rules`.
+ * @param {string} relativeRulesDir Path to rules directory, may be relative.
* @param {string} cwd Current working directory
* @returns {Object} Loaded rule modules by rule ids (file names).
*/
module.exports = function(relativeRulesDir, cwd) {
-
- const rulesDir = relativeRulesDir
- ? path.resolve(cwd, relativeRulesDir)
- : path.join(__dirname, "rules");
+ const rulesDir = path.resolve(cwd, relativeRulesDir);
// cache will help performance as IO operation are expensive
if (rulesDirCache[rulesDir]) {
diff --git a/tools/node_modules/eslint/lib/rules.js b/tools/node_modules/eslint/lib/rules.js
index ee747311e7..d0f9095141 100644
--- a/tools/node_modules/eslint/lib/rules.js
+++ b/tools/node_modules/eslint/lib/rules.js
@@ -10,7 +10,6 @@
//------------------------------------------------------------------------------
const lodash = require("lodash");
-const loadRules = require("./load-rules");
const ruleReplacements = require("../conf/replacements").rules;
const builtInRules = require("./built-in-rules-index");
@@ -60,7 +59,9 @@ function normalizeRule(rule) {
class Rules {
constructor() {
this._rules = Object.create(null);
- this.defineAll(builtInRules);
+ Object.keys(builtInRules).forEach(ruleId => {
+ this.define(ruleId, builtInRules[ruleId]);
+ });
}
/**
@@ -74,46 +75,6 @@ class Rules {
}
/**
- * Loads and registers all rules from passed rules directory.
- * @param {string} [rulesDir] Path to rules directory, may be relative. Defaults to `lib/rules`.
- * @param {string} cwd Current working directory
- * @returns {void}
- */
- load(rulesDir, cwd) {
- const newRules = loadRules(rulesDir, cwd);
-
- this.defineAll(newRules);
- }
-
- /**
- * Pulls a Map of new rules to the defined ones of this instance.
- * @param {Object} newRules Expects to have an object here that maps the rule ID to the rule definition.
- * @returns {void}
- */
- defineAll(newRules) {
- Object.keys(newRules).forEach(ruleId => {
- this.define(ruleId, newRules[ruleId]);
- });
- }
-
- /**
- * Registers all given rules of a plugin.
- * @param {Object} plugin The plugin object to import.
- * @param {string} pluginName The name of the plugin without prefix (`eslint-plugin-`).
- * @returns {void}
- */
- importPlugin(plugin, pluginName) {
- if (plugin.rules) {
- Object.keys(plugin.rules).forEach(ruleId => {
- const qualifiedRuleId = `${pluginName}/${ruleId}`,
- rule = plugin.rules[ruleId];
-
- this.define(qualifiedRuleId, rule);
- });
- }
- }
-
- /**
* Access rule handler by id (file name).
* @param {string} ruleId Rule id (file name).
* @returns {{create: Function, schema: JsonSchema[]}}
diff --git a/tools/node_modules/eslint/lib/rules/for-direction.js b/tools/node_modules/eslint/lib/rules/for-direction.js
index db079b2679..c15d10e5f8 100644
--- a/tools/node_modules/eslint/lib/rules/for-direction.js
+++ b/tools/node_modules/eslint/lib/rules/for-direction.js
@@ -43,6 +43,23 @@ module.exports = {
}
/**
+ * check the right side of the assignment
+ * @param {ASTNode} update UpdateExpression to check
+ * @param {int} dir expected direction that could either be turned around or invalidated
+ * @returns {int} return dir, the negated dir or zero if it's not clear for identifiers
+ */
+ function getRightDirection(update, dir) {
+ if (update.right.type === "UnaryExpression") {
+ if (update.right.operator === "-") {
+ return -dir;
+ }
+ } else if (update.right.type === "Identifier") {
+ return 0;
+ }
+ return dir;
+ }
+
+ /**
* check UpdateExpression add/sub the counter
* @param {ASTNode} update UpdateExpression to check
* @param {string} counter variable name to check
@@ -69,10 +86,10 @@ module.exports = {
function getAssignmentDirection(update, counter) {
if (update.left.name === counter) {
if (update.operator === "+=") {
- return 1;
+ return getRightDirection(update, 1);
}
if (update.operator === "-=") {
- return -1;
+ return getRightDirection(update, -1);
}
}
return 0;
@@ -85,26 +102,22 @@ module.exports = {
const operator = node.test.operator;
const update = node.update;
- if (operator === "<" || operator === "<=") {
-
- // report error if update sub the counter (--, -=)
- if (update.type === "UpdateExpression" && getUpdateDirection(update, counter) < 0) {
- report(node);
- }
+ let wrongDirection;
- if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) < 0) {
- report(node);
- }
+ if (operator === "<" || operator === "<=") {
+ wrongDirection = -1;
} else if (operator === ">" || operator === ">=") {
+ wrongDirection = 1;
+ } else {
+ return;
+ }
- // report error if update add the counter (++, +=)
- if (update.type === "UpdateExpression" && getUpdateDirection(update, counter) > 0) {
- report(node);
- }
-
- if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) > 0) {
+ if (update.type === "UpdateExpression") {
+ if (getUpdateDirection(update, counter) === wrongDirection) {
report(node);
}
+ } else if (update.type === "AssignmentExpression" && getAssignmentDirection(update, counter) === wrongDirection) {
+ report(node);
}
}
}
diff --git a/tools/node_modules/eslint/lib/rules/no-constant-condition.js b/tools/node_modules/eslint/lib/rules/no-constant-condition.js
index 39c2928eed..fb36207ebb 100644
--- a/tools/node_modules/eslint/lib/rules/no-constant-condition.js
+++ b/tools/node_modules/eslint/lib/rules/no-constant-condition.js
@@ -6,6 +6,13 @@
"use strict";
//------------------------------------------------------------------------------
+// Helpers
+//------------------------------------------------------------------------------
+
+const EQUALITY_OPERATORS = ["===", "!==", "==", "!="];
+const RELATIONAL_OPERATORS = [">", "<", ">=", "<=", "in", "instanceof"];
+
+//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
@@ -110,7 +117,18 @@ module.exports = {
const isRightShortCircuit = (isRightConstant && isLogicalIdentity(node.right, node.operator));
return (isLeftConstant && isRightConstant) ||
- (node.operator === "||" && isRightConstant && node.right.value) || // in the case of an "OR", we need to know if the right constant value is truthy
+ (
+
+ // 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;
}
diff --git a/tools/node_modules/eslint/lib/rules/object-shorthand.js b/tools/node_modules/eslint/lib/rules/object-shorthand.js
index ff6a51a4d1..31010f0e73 100644
--- a/tools/node_modules/eslint/lib/rules/object-shorthand.js
+++ b/tools/node_modules/eslint/lib/rules/object-shorthand.js
@@ -255,7 +255,7 @@ module.exports = {
keyPrefix + keyText + sourceCode.text.slice(tokenBeforeParams.range[1], node.value.range[1])
);
}
- const arrowToken = sourceCode.getTokens(node.value).find(token => token.value === "=>");
+ const arrowToken = sourceCode.getTokenBefore(node.value.body, { filter: token => token.value === "=>" });
const tokenBeforeArrow = sourceCode.getTokenBefore(arrowToken);
const hasParensAroundParameters = tokenBeforeArrow.type === "Punctuator" && tokenBeforeArrow.value === ")";
const oldParamText = sourceCode.text.slice(sourceCode.getFirstToken(node.value, node.value.async ? 1 : 0).range[0], tokenBeforeArrow.range[1]);
diff --git a/tools/node_modules/eslint/lib/util/config-comment-parser.js b/tools/node_modules/eslint/lib/util/config-comment-parser.js
index 88504caf1c..8ee0230cb2 100644
--- a/tools/node_modules/eslint/lib/util/config-comment-parser.js
+++ b/tools/node_modules/eslint/lib/util/config-comment-parser.js
@@ -26,14 +26,14 @@ const debug = require("debug")("eslint:config-comment-parser");
module.exports = class ConfigCommentParser {
/**
- * Parses a list of "name:boolean_value" or/and "name" options divided by comma or
+ * Parses a list of "name:string_value" or/and "name" options divided by comma or
* whitespace. Used for "global" and "exported" comments.
* @param {string} string The string to parse.
* @param {Comment} comment The comment node which has the string.
- * @returns {Object} Result map object of names and boolean values
+ * @returns {Object} Result map object of names and string values, or null values if no value was provided
*/
- parseBooleanConfig(string, comment) {
- debug("Parsing Boolean config");
+ parseStringConfig(string, comment) {
+ debug("Parsing String config");
const items = {};
@@ -45,13 +45,10 @@ module.exports = class ConfigCommentParser {
return;
}
- // value defaults to "false" (if not provided), e.g: "foo" => ["foo", "false"]
- const [key, value = "false"] = name.split(":");
+ // value defaults to null (if not provided), e.g: "foo" => ["foo", null]
+ const [key, value = null] = name.split(":");
- items[key] = {
- value: value === "true",
- comment
- };
+ items[key] = { value, comment };
});
return items;
}