Skip to content

Commit

Permalink
tools: update ESLint to 4.2.0
Browse files Browse the repository at this point in the history
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.

PR-URL: #14155
Ref: eslint/eslint#8882
Ref: eslint/eslint#8885
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
  • Loading branch information
Trott authored and addaleax committed Jul 18, 2017
1 parent 096080b commit ef53149
Show file tree
Hide file tree
Showing 350 changed files with 36,664 additions and 20,632 deletions.
1 change: 1 addition & 0 deletions tools/eslint/conf/eslint-recommended.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
"func-names": "off",
"func-style": "off",
"generator-star-spacing": "off",
"getter-return": "off",
"global-require": "off",
"guard-for-in": "off",
"handle-callback-err": "off",
Expand Down
7 changes: 4 additions & 3 deletions tools/eslint/lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const debug = require("debug")("eslint:cli-engine");
* @property {string} cwd The value to use for the current working directory.
* @property {string[]} envs An array of environments to load.
* @property {string[]} extensions An array of file extensions to check.
* @property {boolean} fix Execute in autofix mode.
* @property {boolean|Function} fix Execute in autofix mode. If a function, should return a boolean.
* @property {string[]} globals An array of global variables to declare.
* @property {boolean} ignore False disables use of .eslintignore.
* @property {string} ignorePath The ignore file to use instead of .eslintignore.
Expand Down Expand Up @@ -135,7 +135,7 @@ function calculateStatsPerRun(results) {
* @param {string} text The source code to check.
* @param {Object} configHelper The configuration options for ESLint.
* @param {string} filename An optional string representing the texts filename.
* @param {boolean} fix Indicates if fixes should be processed.
* @param {boolean|Function} fix Indicates if fixes should be processed.
* @param {boolean} allowInlineConfig Allow/ignore comments that change config.
* @param {Linter} linter Linter context
* @returns {LintResult} The results for linting on this text.
Expand Down Expand Up @@ -195,7 +195,8 @@ function processText(text, configHelper, filename, fix, allowInlineConfig, linte
if (fix) {
fixedResult = linter.verifyAndFix(text, config, {
filename,
allowInlineConfig
allowInlineConfig,
fix
});
messages = fixedResult.messages;
} else {
Expand Down
13 changes: 12 additions & 1 deletion tools/eslint/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ const debug = require("debug")("eslint:cli");
// Helpers
//------------------------------------------------------------------------------

/**
* Predicate function for whether or not to apply fixes in quiet mode.
* If a message is a warning, do not apply a fix.
* @param {LintResult} lintResult The lint result.
* @returns {boolean} True if the lint message is an error (and thus should be
* autofixed), false otherwise.
*/
function quietFixPredicate(lintResult) {
return lintResult.severity === 2;
}

/**
* Translates the CLI options into the options expected by the CLIEngine.
* @param {Object} cliOptions The CLI options to translate.
Expand All @@ -52,7 +63,7 @@ function translateOptions(cliOptions) {
cache: cliOptions.cache,
cacheFile: cliOptions.cacheFile,
cacheLocation: cliOptions.cacheLocation,
fix: cliOptions.fix,
fix: cliOptions.fix && (cliOptions.quiet ? quietFixPredicate : true),
allowInlineConfig: cliOptions.inlineConfig
};
}
Expand Down
33 changes: 19 additions & 14 deletions tools/eslint/lib/config/config-validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// Requirements
//------------------------------------------------------------------------------

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

Expand All @@ -20,6 +20,7 @@ const validators = {
//------------------------------------------------------------------------------
// Private
//------------------------------------------------------------------------------
let validateSchema;

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

if (!validators.rules[id] && schema) {
validators.rules[id] = schemaValidator(schema, { verbose: true });
validators.rules[id] = ajv.compile(schema);
}

const validateRule = validators.rules[id];

if (validateRule) {
validateRule(localOptions);
if (validateRule.errors) {
throw new Error(validateRule.errors.map(error => `\tValue "${error.value}" ${error.message}.\n`).join(""));
throw new Error(validateRule.errors.map(error => `\tValue "${error.data}" ${error.message}.\n`).join(""));
}
}
}
Expand Down Expand Up @@ -158,19 +159,23 @@ function validateRules(rulesConfig, source, rulesContext) {
* @returns {string} Formatted error message
*/
function formatErrors(errors) {

return errors.map(error => {
if (error.message === "has additional properties") {
return `Unexpected top-level property "${error.value.replace(/^data\./, "")}"`;
if (error.keyword === "additionalProperties") {
const formattedPropertyPath = error.dataPath.length ? `${error.dataPath.slice(1)}.${error.params.additionalProperty}` : error.params.additionalProperty;

return `Unexpected top-level property "${formattedPropertyPath}"`;
}
if (error.message === "is the wrong type") {
const formattedField = error.field.replace(/^data\./, "");
const formattedExpectedType = typeof error.type === "string" ? error.type : error.type.join("/");
const formattedValue = JSON.stringify(error.value);
if (error.keyword === "type") {
const formattedField = error.dataPath.slice(1);
const formattedExpectedType = Array.isArray(error.schema) ? error.schema.join("/") : error.schema;
const formattedValue = JSON.stringify(error.data);

return `Property "${formattedField}" is the wrong type (expected ${formattedExpectedType} but got \`${formattedValue}\`)`;
}
return `"${error.field.replace(/^(data\.)/, "")}" ${error.message}. Value: ${JSON.stringify(error.value)}`;

const field = error.dataPath[0] === "." ? error.dataPath.slice(1) : error.dataPath;

return `"${field}" ${error.message}. Value: ${JSON.stringify(error.data)}`;
}).map(message => `\t- ${message}.\n`).join("");
}

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

if (!validator(config)) {
throw new Error(`${source}:\n\tESLint configuration is invalid:\n${formatErrors(validator.errors)}`);
if (!validateSchema(config)) {
throw new Error(`${source}:\n\tESLint configuration is invalid:\n${formatErrors(validateSchema.errors)}`);
}
}

Expand Down
9 changes: 6 additions & 3 deletions tools/eslint/lib/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,7 @@ class Linter extends EventEmitter {
* @param {string} options.filename The filename from which the text was read.
* @param {boolean} options.allowInlineConfig Flag indicating if inline comments
* should be allowed.
* @param {boolean|Function} options.fix Determines whether fixes should be applied
* @returns {Object} The result of the fix operation as returned from the
* SourceCodeFixer.
*/
Expand All @@ -1205,6 +1206,8 @@ class Linter extends EventEmitter {
fixedResult,
fixed = false,
passNumber = 0;
const debugTextDescription = options && options.filename || `${text.slice(0, 10)}...`;
const shouldFix = options && options.fix || true;

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

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

debug(`Generating fixed text for ${options.filename} (pass ${passNumber})`);
fixedResult = SourceCodeFixer.applyFixes(this.getSourceCode(), messages);
debug(`Generating fixed text for ${debugTextDescription} (pass ${passNumber})`);
fixedResult = SourceCodeFixer.applyFixes(this.getSourceCode(), messages, shouldFix);

// stop if there are any syntax errors.
// 'fixedResult.output' is a empty string.
Expand Down
5 changes: 4 additions & 1 deletion tools/eslint/lib/rules/arrow-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ module.exports = {
*/
function fixParamsWithParenthesis(fixer) {
const paramToken = sourceCode.getTokenAfter(firstTokenOfParam);
const closingParenToken = sourceCode.getTokenAfter(paramToken);

// ES8 allows Trailing commas in function parameter lists and calls
// https://github.com/eslint/eslint/issues/8834
const closingParenToken = sourceCode.getTokenAfter(paramToken, astUtils.isClosingParenToken);
const asyncToken = isAsync ? sourceCode.getTokenBefore(firstTokenOfParam) : null;
const shouldAddSpaceForAsync = asyncToken && (asyncToken.end === firstTokenOfParam.start);

Expand Down
80 changes: 40 additions & 40 deletions tools/eslint/lib/rules/comma-dangle.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,49 +81,49 @@ module.exports = {
category: "Stylistic Issues",
recommended: false
},

fixable: "code",

schema: [
{
defs: {
value: {
enum: [
"always",
"always-multiline",
"only-multiline",
"never"
]
},
valueWithIgnore: {
anyOf: [
{
$ref: "#/defs/value"
},
{
enum: ["ignore"]
}
]
}
schema: {
definitions: {
value: {
enum: [
"always-multiline",
"always",
"never",
"only-multiline"
]
},
anyOf: [
{
$ref: "#/defs/value"
},
{
type: "object",
properties: {
arrays: { $refs: "#/defs/valueWithIgnore" },
objects: { $refs: "#/defs/valueWithIgnore" },
imports: { $refs: "#/defs/valueWithIgnore" },
exports: { $refs: "#/defs/valueWithIgnore" },
functions: { $refs: "#/defs/valueWithIgnore" }
valueWithIgnore: {
enum: [
"always-multiline",
"always",
"ignore",
"never",
"only-multiline"
]
}
},
type: "array",
items: [
{
oneOf: [
{
$ref: "#/definitions/value"
},
additionalProperties: false
}
]
}
]
{
type: "object",
properties: {
arrays: { $ref: "#/definitions/valueWithIgnore" },
objects: { $ref: "#/definitions/valueWithIgnore" },
imports: { $ref: "#/definitions/valueWithIgnore" },
exports: { $ref: "#/definitions/valueWithIgnore" },
functions: { $ref: "#/definitions/valueWithIgnore" }
},
additionalProperties: false
}
]
}
]
}
},

create(context) {
Expand Down
9 changes: 9 additions & 0 deletions tools/eslint/lib/rules/dot-notation.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ module.exports = {
return null;
}

if (node.object.type === "Identifier" && node.object.name === "let") {

/*
* A statement that starts with `let[` is parsed as a destructuring variable declaration, not
* a MemberExpression.
*/
return null;
}

return fixer.replaceTextRange(
[dot.range[0], node.property.range[1]],
`[${textAfterDot}"${node.property.name}"]`
Expand Down
Loading

0 comments on commit ef53149

Please sign in to comment.