Skip to content

Commit

Permalink
tools: update to ESLint 4.1.0
Browse files Browse the repository at this point in the history
Update ESLint to 4.1.0. This fixes a bug that previously prevented us
from using the new and stricter indentation checking.

Refs: eslint/eslint#8721
PR-URL: #13895
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: Roman Reiss <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
  • Loading branch information
Trott authored and addaleax committed Jul 18, 2017
1 parent 74aed0b commit 6a5c376
Show file tree
Hide file tree
Showing 242 changed files with 10,297 additions and 10,789 deletions.
4 changes: 4 additions & 0 deletions tools/eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ These folks keep the project moving and are resources for help.

We have scheduled releases every two weeks on Friday or Saturday.

## Code of Conduct

ESLint adheres to the [JS Foundation Code of Conduct](https://js.foundation/community/code-of-conduct).

## Filing Issues

Before filing an issue, please be sure to read the guidelines for what you're reporting:
Expand Down
68 changes: 68 additions & 0 deletions tools/eslint/conf/config-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* @fileoverview Defines a schema for configs.
* @author Sylvan Mably
*/

"use strict";

const baseConfigProperties = {
env: { type: "object" },
globals: { type: "object" },
parser: { type: ["string", "null"] },
parserOptions: { type: "object" },
plugins: { type: "array" },
rules: { type: "object" },
settings: { type: "object" }
};

const overrideProperties = Object.assign(
{},
baseConfigProperties,
{
files: {
oneOf: [
{ type: "string" },
{
type: "array",
items: { type: "string" },
minItems: 1
}
]
},
excludedFiles: {
oneOf: [
{ type: "string" },
{
type: "array",
items: { type: "string" }
}
]
}
}
);

const topLevelConfigProperties = Object.assign(
{},
baseConfigProperties,
{
extends: { type: ["string", "array"] },
root: { type: "boolean" },
overrides: {
type: "array",
items: {
type: "object",
properties: overrideProperties,
required: ["files"],
additionalProperties: false
}
}
}
);

const configSchema = {
type: "object",
properties: topLevelConfigProperties,
additionalProperties: false
};

module.exports = configSchema;
15 changes: 0 additions & 15 deletions tools/eslint/conf/config-schema.json

This file was deleted.

6 changes: 1 addition & 5 deletions tools/eslint/conf/default-config-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,5 @@ module.exports = deepFreeze({
rules: {},
settings: {},
parser: "espree",
parserOptions: {
ecmaVersion: 5,
sourceType: "script",
ecmaFeatures: {}
}
parserOptions: {}
});
109 changes: 19 additions & 90 deletions tools/eslint/lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ const fs = require("fs"),
Config = require("./config"),
fileEntryCache = require("file-entry-cache"),
globUtil = require("./util/glob-util"),
SourceCodeFixer = require("./util/source-code-fixer"),
validator = require("./config/config-validator"),
stringify = require("json-stable-stringify"),
hash = require("./util/hash"),

pkg = require("../package.json");

const debug = require("debug")("eslint:cli-engine");
Expand Down Expand Up @@ -132,80 +130,6 @@ function calculateStatsPerRun(results) {
});
}

/**
* Performs multiple autofix passes over the text until as many fixes as possible
* have been applied.
* @param {string} text The source text to apply fixes to.
* @param {Object} config The ESLint config object to use.
* @param {Object} options The ESLint options object to use.
* @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 {Linter} linter Linter context
* @returns {Object} The result of the fix operation as returned from the
* SourceCodeFixer.
* @private
*/
function multipassFix(text, config, options, linter) {
const MAX_PASSES = 10;
let messages = [],
fixedResult,
fixed = false,
passNumber = 0;

/**
* This loop continues until one of the following is true:
*
* 1. No more fixes have been applied.
* 2. Ten passes have been made.
*
* That means anytime a fix is successfully applied, there will be another pass.
* Essentially, guaranteeing a minimum of two passes.
*/
do {
passNumber++;

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

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

// stop if there are any syntax errors.
// 'fixedResult.output' is a empty string.
if (messages.length === 1 && messages[0].fatal) {
break;
}

// keep track if any fixes were ever applied - important for return value
fixed = fixed || fixedResult.fixed;

// update to use the fixed output instead of the original text
text = fixedResult.output;

} while (
fixedResult.fixed &&
passNumber < MAX_PASSES
);


/*
* If the last result had fixes, we need to lint again to be sure we have
* the most up-to-date information.
*/
if (fixedResult.fixed) {
fixedResult.messages = linter.verify(text, config, options);
}


// ensure the last result properly reflects if fixes were done
fixedResult.fixed = fixed;
fixedResult.output = text;

return fixedResult;

}

/**
* Processes an source code using ESLint.
* @param {string} text The source code to check.
Expand Down Expand Up @@ -269,10 +193,10 @@ function processText(text, configHelper, filename, fix, allowInlineConfig, linte
} else {

if (fix) {
fixedResult = multipassFix(text, config, {
fixedResult = linter.verifyAndFix(text, config, {
filename,
allowInlineConfig
}, linter);
});
messages = fixedResult.messages;
} else {
messages = linter.verify(text, config, {
Expand Down Expand Up @@ -394,7 +318,7 @@ function getCacheFile(cacheFile, cwd) {
cacheFile = path.normalize(cacheFile);

const resolvedCacheFile = path.resolve(cwd, cacheFile);
const looksLikeADirectory = cacheFile[cacheFile.length - 1 ] === path.sep;
const looksLikeADirectory = cacheFile[cacheFile.length - 1] === path.sep;

/**
* return the name for the cache file in case the provided parameter is a directory
Expand Down Expand Up @@ -474,15 +398,17 @@ class CLIEngine {
this.options = options;
this.linter = new Linter();

const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);

/**
* Cache used to avoid operating on files that haven't changed since the
* last successful execution (e.g., file passed linting with no errors and
* no warnings).
* @type {Object}
*/
this._fileCache = fileEntryCache.create(cacheFile);
if (options.cache) {
const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);

/**
* Cache used to avoid operating on files that haven't changed since the
* last successful execution (e.g., file passed linting with no errors and
* no warnings).
* @type {Object}
*/
this._fileCache = fileEntryCache.create(cacheFile);
}

// load in additional rules
if (this.options.rulePaths) {
Expand Down Expand Up @@ -571,6 +497,11 @@ class CLIEngine {
fileCache = this._fileCache,
configHelper = this.config;
let prevConfig; // the previous configuration used
const cacheFile = getCacheFile(this.options.cacheLocation || this.options.cacheFile, this.options.cwd);

if (!options.cache && fs.existsSync(cacheFile)) {
fs.unlinkSync(cacheFile);
}

/**
* Calculates the hash of the config file used to validate a given file
Expand Down Expand Up @@ -646,8 +577,6 @@ class CLIEngine {
// move to the next file
return;
}
} else {
fileCache.destroy();
}

debug(`Processing ${filename}`);
Expand Down
2 changes: 1 addition & 1 deletion tools/eslint/lib/code-path-analysis/code-path-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class CodePathState {
this.breakContext = null;

this.currentSegments = [];
this.initialSegment = this.forkContext.head[ 0 ];
this.initialSegment = this.forkContext.head[0];

// returnedSegments and thrownSegments push elements into finalSegments also.
const final = this.finalSegments = [];
Expand Down
Loading

0 comments on commit 6a5c376

Please sign in to comment.