Skip to content

Commit c5adb5f

Browse files
TrottMylesBorins
authored andcommitted
tools: update ESLint to 4.2.0
ESLint 4.2.0 contains a fix for a bug that is blocking us from moving to the non-legacy stricter indentation linting. Update to 4.2.0 to remove the blocking issue. Backport-PR-URL: #14859 PR-URL: #14155 Ref: eslint/eslint#8882 Ref: eslint/eslint#8885 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Refael Ackermann <[email protected]>
1 parent 688e5ed commit c5adb5f

File tree

556 files changed

+65376
-28736
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

556 files changed

+65376
-28736
lines changed

tools/eslint/conf/eslint-recommended.js

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ module.exports = {
4848
"func-names": "off",
4949
"func-style": "off",
5050
"generator-star-spacing": "off",
51+
"getter-return": "off",
5152
"global-require": "off",
5253
"guard-for-in": "off",
5354
"handle-callback-err": "off",

tools/eslint/lib/cli-engine.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const debug = require("debug")("eslint:cli-engine");
4545
* @property {string} cwd The value to use for the current working directory.
4646
* @property {string[]} envs An array of environments to load.
4747
* @property {string[]} extensions An array of file extensions to check.
48-
* @property {boolean} fix Execute in autofix mode.
48+
* @property {boolean|Function} fix Execute in autofix mode. If a function, should return a boolean.
4949
* @property {string[]} globals An array of global variables to declare.
5050
* @property {boolean} ignore False disables use of .eslintignore.
5151
* @property {string} ignorePath The ignore file to use instead of .eslintignore.
@@ -135,7 +135,7 @@ function calculateStatsPerRun(results) {
135135
* @param {string} text The source code to check.
136136
* @param {Object} configHelper The configuration options for ESLint.
137137
* @param {string} filename An optional string representing the texts filename.
138-
* @param {boolean} fix Indicates if fixes should be processed.
138+
* @param {boolean|Function} fix Indicates if fixes should be processed.
139139
* @param {boolean} allowInlineConfig Allow/ignore comments that change config.
140140
* @param {Linter} linter Linter context
141141
* @returns {LintResult} The results for linting on this text.
@@ -195,7 +195,8 @@ function processText(text, configHelper, filename, fix, allowInlineConfig, linte
195195
if (fix) {
196196
fixedResult = linter.verifyAndFix(text, config, {
197197
filename,
198-
allowInlineConfig
198+
allowInlineConfig,
199+
fix
199200
});
200201
messages = fixedResult.messages;
201202
} else {

tools/eslint/lib/cli.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ const debug = require("debug")("eslint:cli");
2828
// Helpers
2929
//------------------------------------------------------------------------------
3030

31+
/**
32+
* Predicate function for whether or not to apply fixes in quiet mode.
33+
* If a message is a warning, do not apply a fix.
34+
* @param {LintResult} lintResult The lint result.
35+
* @returns {boolean} True if the lint message is an error (and thus should be
36+
* autofixed), false otherwise.
37+
*/
38+
function quietFixPredicate(lintResult) {
39+
return lintResult.severity === 2;
40+
}
41+
3142
/**
3243
* Translates the CLI options into the options expected by the CLIEngine.
3344
* @param {Object} cliOptions The CLI options to translate.
@@ -52,7 +63,7 @@ function translateOptions(cliOptions) {
5263
cache: cliOptions.cache,
5364
cacheFile: cliOptions.cacheFile,
5465
cacheLocation: cliOptions.cacheLocation,
55-
fix: cliOptions.fix,
66+
fix: cliOptions.fix && (cliOptions.quiet ? quietFixPredicate : true),
5667
allowInlineConfig: cliOptions.inlineConfig
5768
};
5869
}

tools/eslint/lib/config/config-validator.js

+19-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Requirements
1010
//------------------------------------------------------------------------------
1111

12-
const schemaValidator = require("is-my-json-valid"),
12+
const ajv = require("../util/ajv"),
1313
configSchema = require("../../conf/config-schema.js"),
1414
util = require("util");
1515

@@ -20,6 +20,7 @@ const validators = {
2020
//------------------------------------------------------------------------------
2121
// Private
2222
//------------------------------------------------------------------------------
23+
let validateSchema;
2324

2425
/**
2526
* Gets a complete options schema for a rule.
@@ -79,15 +80,15 @@ function validateRuleSchema(id, localOptions, rulesContext) {
7980
const schema = getRuleOptionsSchema(id, rulesContext);
8081

8182
if (!validators.rules[id] && schema) {
82-
validators.rules[id] = schemaValidator(schema, { verbose: true });
83+
validators.rules[id] = ajv.compile(schema);
8384
}
8485

8586
const validateRule = validators.rules[id];
8687

8788
if (validateRule) {
8889
validateRule(localOptions);
8990
if (validateRule.errors) {
90-
throw new Error(validateRule.errors.map(error => `\tValue "${error.value}" ${error.message}.\n`).join(""));
91+
throw new Error(validateRule.errors.map(error => `\tValue "${error.data}" ${error.message}.\n`).join(""));
9192
}
9293
}
9394
}
@@ -158,19 +159,23 @@ function validateRules(rulesConfig, source, rulesContext) {
158159
* @returns {string} Formatted error message
159160
*/
160161
function formatErrors(errors) {
161-
162162
return errors.map(error => {
163-
if (error.message === "has additional properties") {
164-
return `Unexpected top-level property "${error.value.replace(/^data\./, "")}"`;
163+
if (error.keyword === "additionalProperties") {
164+
const formattedPropertyPath = error.dataPath.length ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}` : error.params.additionalProperty;
165+
166+
return `Unexpected top-level property "${formattedPropertyPath}"`;
165167
}
166-
if (error.message === "is the wrong type") {
167-
const formattedField = error.field.replace(/^data\./, "");
168-
const formattedExpectedType = typeof error.type === "string" ? error.type : error.type.join("/");
169-
const formattedValue = JSON.stringify(error.value);
168+
if (error.keyword === "type") {
169+
const formattedField = error.dataPath.slice(1);
170+
const formattedExpectedType = Array.isArray(error.schema) ? error.schema.join("/") : error.schema;
171+
const formattedValue = JSON.stringify(error.data);
170172

171173
return `Property "${formattedField}" is the wrong type (expected ${formattedExpectedType} but got \`${formattedValue}\`)`;
172174
}
173-
return `"${error.field.replace(/^(data\.)/, "")}" ${error.message}. Value: ${JSON.stringify(error.value)}`;
175+
176+
const field = error.dataPath[0] === "." ? error.dataPath.slice(1) : error.dataPath;
177+
178+
return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`;
174179
}).map(message => `\t- ${message}.\n`).join("");
175180
}
176181

@@ -181,10 +186,10 @@ function formatErrors(errors) {
181186
* @returns {void}
182187
*/
183188
function validateConfigSchema(config, source) {
184-
const validator = schemaValidator(configSchema, { verbose: true });
189+
validateSchema = validateSchema || ajv.compile(configSchema);
185190

186-
if (!validator(config)) {
187-
throw new Error(`${source}:\n\tESLint configuration is invalid:\n${formatErrors(validator.errors)}`);
191+
if (!validateSchema(config)) {
192+
throw new Error(`${source}:\n\tESLint configuration is invalid:\n${formatErrors(validateSchema.errors)}`);
188193
}
189194
}
190195

tools/eslint/lib/linter.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1197,6 +1197,7 @@ class Linter extends EventEmitter {
11971197
* @param {string} options.filename The filename from which the text was read.
11981198
* @param {boolean} options.allowInlineConfig Flag indicating if inline comments
11991199
* should be allowed.
1200+
* @param {boolean|Function} options.fix Determines whether fixes should be applied
12001201
* @returns {Object} The result of the fix operation as returned from the
12011202
* SourceCodeFixer.
12021203
*/
@@ -1205,6 +1206,8 @@ class Linter extends EventEmitter {
12051206
fixedResult,
12061207
fixed = false,
12071208
passNumber = 0;
1209+
const debugTextDescription = options && options.filename || `${text.slice(0, 10)}...`;
1210+
const shouldFix = options && options.fix || true;
12081211

12091212
/**
12101213
* This loop continues until one of the following is true:
@@ -1218,11 +1221,11 @@ class Linter extends EventEmitter {
12181221
do {
12191222
passNumber++;
12201223

1221-
debug(`Linting code for ${options.filename} (pass ${passNumber})`);
1224+
debug(`Linting code for ${debugTextDescription} (pass ${passNumber})`);
12221225
messages = this.verify(text, config, options);
12231226

1224-
debug(`Generating fixed text for ${options.filename} (pass ${passNumber})`);
1225-
fixedResult = SourceCodeFixer.applyFixes(this.getSourceCode(), messages);
1227+
debug(`Generating fixed text for ${debugTextDescription} (pass ${passNumber})`);
1228+
fixedResult = SourceCodeFixer.applyFixes(this.getSourceCode(), messages, shouldFix);
12261229

12271230
// stop if there are any syntax errors.
12281231
// 'fixedResult.output' is a empty string.

tools/eslint/lib/rules/arrow-parens.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ module.exports = {
6666
*/
6767
function fixParamsWithParenthesis(fixer) {
6868
const paramToken = sourceCode.getTokenAfter(firstTokenOfParam);
69-
const closingParenToken = sourceCode.getTokenAfter(paramToken);
69+
70+
// ES8 allows Trailing commas in function parameter lists and calls
71+
// https://github.com/eslint/eslint/issues/8834
72+
const closingParenToken = sourceCode.getTokenAfter(paramToken, astUtils.isClosingParenToken);
7073
const asyncToken = isAsync ? sourceCode.getTokenBefore(firstTokenOfParam) : null;
7174
const shouldAddSpaceForAsync = asyncToken && (asyncToken.end === firstTokenOfParam.start);
7275

tools/eslint/lib/rules/comma-dangle.js

+40-40
Original file line numberDiff line numberDiff line change
@@ -81,49 +81,49 @@ module.exports = {
8181
category: "Stylistic Issues",
8282
recommended: false
8383
},
84-
8584
fixable: "code",
86-
87-
schema: [
88-
{
89-
defs: {
90-
value: {
91-
enum: [
92-
"always",
93-
"always-multiline",
94-
"only-multiline",
95-
"never"
96-
]
97-
},
98-
valueWithIgnore: {
99-
anyOf: [
100-
{
101-
$ref: "#/defs/value"
102-
},
103-
{
104-
enum: ["ignore"]
105-
}
106-
]
107-
}
85+
schema: {
86+
definitions: {
87+
value: {
88+
enum: [
89+
"always-multiline",
90+
"always",
91+
"never",
92+
"only-multiline"
93+
]
10894
},
109-
anyOf: [
110-
{
111-
$ref: "#/defs/value"
112-
},
113-
{
114-
type: "object",
115-
properties: {
116-
arrays: { $refs: "#/defs/valueWithIgnore" },
117-
objects: { $refs: "#/defs/valueWithIgnore" },
118-
imports: { $refs: "#/defs/valueWithIgnore" },
119-
exports: { $refs: "#/defs/valueWithIgnore" },
120-
functions: { $refs: "#/defs/valueWithIgnore" }
95+
valueWithIgnore: {
96+
enum: [
97+
"always-multiline",
98+
"always",
99+
"ignore",
100+
"never",
101+
"only-multiline"
102+
]
103+
}
104+
},
105+
type: "array",
106+
items: [
107+
{
108+
oneOf: [
109+
{
110+
$ref: "#/definitions/value"
121111
},
122-
additionalProperties: false
123-
}
124-
]
125-
}
126-
]
112+
{
113+
type: "object",
114+
properties: {
115+
arrays: { $ref: "#/definitions/valueWithIgnore" },
116+
objects: { $ref: "#/definitions/valueWithIgnore" },
117+
imports: { $ref: "#/definitions/valueWithIgnore" },
118+
exports: { $ref: "#/definitions/valueWithIgnore" },
119+
functions: { $ref: "#/definitions/valueWithIgnore" }
120+
},
121+
additionalProperties: false
122+
}
123+
]
124+
}
125+
]
126+
}
127127
},
128128

129129
create(context) {

tools/eslint/lib/rules/dot-notation.js

+9
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ module.exports = {
116116
return null;
117117
}
118118

119+
if (node.object.type === "Identifier" && node.object.name === "let") {
120+
121+
/*
122+
* A statement that starts with `let[` is parsed as a destructuring variable declaration, not
123+
* a MemberExpression.
124+
*/
125+
return null;
126+
}
127+
119128
return fixer.replaceTextRange(
120129
[dot.range[0], node.property.range[1]],
121130
`[${textAfterDot}"${node.property.name}"]`

0 commit comments

Comments
 (0)