Skip to content

Commit e9d5cd7

Browse files
TrottMyles Borins
authored and
Myles Borins
committed
tools: update ESLint to v3.8.0
Update ESLint to v3.8.0. * Installed with `npm install --production` to avoid installing unnecessary dev files * Used `dmn -f clean` to further eliminate unneeded files PR-URL: #9112 Reviewed-By: Teddy Katz <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent 39a53a0 commit e9d5cd7

File tree

645 files changed

+40455
-25113
lines changed

Some content is hidden

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

645 files changed

+40455
-25113
lines changed

tools/eslint/CHANGELOG.md

-3,412
This file was deleted.

tools/eslint/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ These folks keep the project moving and are resources for help.
129129
* Kevin Partington ([@platinumazure](https://github.com/platinumazure))
130130
* Vitor Balocco ([@vitorbal](https://github.com/vitorbal))
131131
* James Henry ([@JamesHenry](https://github.com/JamesHenry))
132+
* Teddy Katz ([@not-an-aardvark](https://github.com/not-an-aardvark))
132133

133134
## Releases
134135

tools/eslint/bin/eslint.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
* @author Nicholas C. Zakas
66
*/
77

8+
/* eslint no-console:off, no-process-exit:off */
9+
810
"use strict";
911

1012
//------------------------------------------------------------------------------
1113
// Helpers
1214
//------------------------------------------------------------------------------
1315

14-
var useStdIn = (process.argv.indexOf("--stdin") > -1),
16+
const useStdIn = (process.argv.indexOf("--stdin") > -1),
1517
init = (process.argv.indexOf("--init") > -1),
1618
debug = (process.argv.indexOf("--debug") > -1);
1719

@@ -25,7 +27,7 @@ if (debug) {
2527
//------------------------------------------------------------------------------
2628

2729
// now we can safely include the other modules that use debug
28-
var concat = require("concat-stream"),
30+
const concat = require("concat-stream"),
2931
cli = require("../lib/cli"),
3032
path = require("path"),
3133
fs = require("fs");
@@ -34,15 +36,16 @@ var concat = require("concat-stream"),
3436
// Execution
3537
//------------------------------------------------------------------------------
3638

37-
process.on("uncaughtException", function(err){
39+
process.on("uncaughtException", function(err) {
40+
3841
// lazy load
39-
var lodash = require("lodash");
42+
const lodash = require("lodash");
4043

4144
if (typeof err.messageTemplate === "string" && err.messageTemplate.length > 0) {
42-
var template = lodash.template(fs.readFileSync(path.resolve(__dirname, "../messages/" + err.messageTemplate + ".txt"), "utf-8"));
45+
const template = lodash.template(fs.readFileSync(path.resolve(__dirname, `../messages/${err.messageTemplate}.txt`), "utf-8"));
4346

4447
console.log("\nOops! Something went wrong! :(");
45-
console.log("\n" + template(err.messageData || {}));
48+
console.log(`\n${template(err.messageData || {})}`);
4649
} else {
4750
console.log(err.message);
4851
console.log(err.stack);
@@ -53,16 +56,11 @@ process.on("uncaughtException", function(err){
5356

5457
if (useStdIn) {
5558
process.stdin.pipe(concat({ encoding: "string" }, function(text) {
56-
try {
57-
process.exitCode = cli.execute(process.argv, text);
58-
} catch (ex) {
59-
console.error(ex.message);
60-
console.error(ex.stack);
61-
process.exitCode = 1;
62-
}
59+
process.exitCode = cli.execute(process.argv, text);
6360
}));
6461
} else if (init) {
65-
var configInit = require("../lib/config/config-initializer");
62+
const configInit = require("../lib/config/config-initializer");
63+
6664
configInit.initializeConfig(function(err) {
6765
if (err) {
6866
process.exitCode = 1;

tools/eslint/conf/eslint.json

+1
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@
158158
"eqeqeq": "off",
159159
"func-call-spacing": "off",
160160
"func-names": "off",
161+
"func-name-matching": "off",
161162
"func-style": "off",
162163
"generator-star-spacing": "off",
163164
"global-require": "off",

tools/eslint/lib/ast-utils.js

+23
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ module.exports = {
560560
/* falls through */
561561

562562
case "UnaryExpression":
563+
case "AwaitExpression":
563564
return 14;
564565

565566
case "UpdateExpression":
@@ -715,5 +716,27 @@ module.exports = {
715716
}
716717

717718
return directives;
719+
},
720+
721+
722+
/**
723+
* Determines whether this node is a decimal integer literal. If a node is a decimal integer literal, a dot added
724+
after the node will be parsed as a decimal point, rather than a property-access dot.
725+
* @param {ASTNode} node - The node to check.
726+
* @returns {boolean} `true` if this node is a decimal integer.
727+
* @example
728+
*
729+
* 5 // true
730+
* 5. // false
731+
* 5.0 // false
732+
* 05 // false
733+
* 0x5 // false
734+
* 0b101 // false
735+
* 0o5 // false
736+
* 5e0 // false
737+
* '5' // false
738+
*/
739+
isDecimalInteger(node) {
740+
return node.type === "Literal" && typeof node.value === "number" && /^(0|[1-9]\d*)$/.test(node.raw);
718741
}
719742
};

tools/eslint/lib/cli-engine.js

+29-22
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ const debug = require("debug")("eslint:cli-engine");
7575
* @property {LintMessage[]} messages All of the messages for the result.
7676
* @property {number} errorCount Number or errors for the result.
7777
* @property {number} warningCount Number or warnings for the result.
78+
* @property {string=} [source] The source code of the file that was linted.
79+
* @property {string=} [output] The source code of the file that was linted, with as many fixes applied as possible.
7880
*/
7981

8082
//------------------------------------------------------------------------------
@@ -150,10 +152,10 @@ function multipassFix(text, config, options) {
150152
do {
151153
passNumber++;
152154

153-
debug("Linting code for " + options.filename + " (pass " + passNumber + ")");
155+
debug(`Linting code for ${options.filename} (pass ${passNumber})`);
154156
messages = eslint.verify(text, config, options);
155157

156-
debug("Generating fixed text for " + options.filename + " (pass " + passNumber + ")");
158+
debug(`Generating fixed text for ${options.filename} (pass ${passNumber})`);
157159
fixedResult = SourceCodeFixer.applyFixes(eslint.getSourceCode(), messages);
158160

159161
// stop if there are any syntax errors.
@@ -175,7 +177,7 @@ function multipassFix(text, config, options) {
175177

176178

177179
/*
178-
* If the last result had fixes, we need to lint again to me sure we have
180+
* If the last result had fixes, we need to lint again to be sure we have
179181
* the most up-to-date information.
180182
*/
181183
if (fixedResult.fixed) {
@@ -198,7 +200,7 @@ function multipassFix(text, config, options) {
198200
* @param {string} filename An optional string representing the texts filename.
199201
* @param {boolean} fix Indicates if fixes should be processed.
200202
* @param {boolean} allowInlineConfig Allow/ignore comments that change config.
201-
* @returns {Result} The results for linting on this text.
203+
* @returns {LintResult} The results for linting on this text.
202204
* @private
203205
*/
204206
function processText(text, configHelper, filename, fix, allowInlineConfig) {
@@ -218,7 +220,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
218220
}
219221

220222
filename = filename || "<text>";
221-
debug("Linting " + filename);
223+
debug(`Linting ${filename}`);
222224
const config = configHelper.getConfig(filePath);
223225

224226
if (config.plugins) {
@@ -279,6 +281,10 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
279281
result.output = fixedResult.output;
280282
}
281283

284+
if (result.errorCount + result.warningCount > 0 && typeof result.output === "undefined") {
285+
result.source = text;
286+
}
287+
282288
return result;
283289
}
284290

@@ -288,7 +294,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
288294
* @param {string} filename The filename of the file being checked.
289295
* @param {Object} configHelper The configuration options for ESLint.
290296
* @param {Object} options The CLIEngine options object.
291-
* @returns {Result} The results for linting on this file.
297+
* @returns {LintResult} The results for linting on this file.
292298
* @private
293299
*/
294300
function processFile(filename, configHelper, options) {
@@ -304,7 +310,7 @@ function processFile(filename, configHelper, options) {
304310
* Returns result with warning by ignore settings
305311
* @param {string} filePath - File path of checked code
306312
* @param {string} baseDir - Absolute path of base directory
307-
* @returns {Result} Result with single warning
313+
* @returns {LintResult} Result with single warning
308314
* @private
309315
*/
310316
function createIgnoreResult(filePath, baseDir) {
@@ -376,7 +382,7 @@ function getCacheFile(cacheFile, cwd) {
376382
* @returns {string} the resolved path to the cacheFile
377383
*/
378384
function getCacheFileForDirectory() {
379-
return path.join(resolvedCacheFile, ".cache_" + hash(cwd));
385+
return path.join(resolvedCacheFile, `.cache_${hash(cwd)}`);
380386
}
381387

382388
let fileStats;
@@ -461,7 +467,7 @@ function CLIEngine(options) {
461467
const cwd = this.options.cwd;
462468

463469
this.options.rulePaths.forEach(function(rulesdir) {
464-
debug("Loading rules from " + rulesdir);
470+
debug(`Loading rules from ${rulesdir}`);
465471
rules.load(rulesdir, cwd);
466472
});
467473
}
@@ -497,13 +503,13 @@ CLIEngine.getFormatter = function(format) {
497503

498504
formatterPath = path.resolve(cwd, format);
499505
} else {
500-
formatterPath = "./formatters/" + format;
506+
formatterPath = `./formatters/${format}`;
501507
}
502508

503509
try {
504510
return require(formatterPath);
505511
} catch (ex) {
506-
ex.message = "There was a problem loading formatter: " + formatterPath + "\nError: " + ex.message;
512+
ex.message = `There was a problem loading formatter: ${formatterPath}\nError: ${ex.message}`;
507513
throw ex;
508514
}
509515

@@ -524,12 +530,13 @@ CLIEngine.getErrorResults = function(results) {
524530
const filteredMessages = result.messages.filter(isErrorMessage);
525531

526532
if (filteredMessages.length > 0) {
527-
filtered.push({
528-
filePath: result.filePath,
529-
messages: filteredMessages,
530-
errorCount: filteredMessages.length,
531-
warningCount: 0
532-
});
533+
filtered.push(
534+
Object.assign(result, {
535+
messages: filteredMessages,
536+
errorCount: filteredMessages.length,
537+
warningCount: 0
538+
})
539+
);
533540
}
534541
});
535542

@@ -608,7 +615,7 @@ CLIEngine.prototype = {
608615

609616
const eslintVersion = pkg.version;
610617

611-
prevConfig.hash = hash(eslintVersion + "_" + stringify(config));
618+
prevConfig.hash = hash(`${eslintVersion}_${stringify(config)}`);
612619
}
613620

614621
return prevConfig.hash;
@@ -645,7 +652,7 @@ CLIEngine.prototype = {
645652
const changed = descriptor.changed || meta.hashOfConfig !== hashOfConfig;
646653

647654
if (!changed) {
648-
debug("Skipping file since hasn't changed: " + filename);
655+
debug(`Skipping file since hasn't changed: ${filename}`);
649656

650657
/*
651658
* Add the the cached results (always will be 0 error and
@@ -662,7 +669,7 @@ CLIEngine.prototype = {
662669
fileCache.destroy();
663670
}
664671

665-
debug("Processing " + filename);
672+
debug(`Processing ${filename}`);
666673

667674
const res = processFile(filename, configHelper, options);
668675

@@ -674,7 +681,7 @@ CLIEngine.prototype = {
674681
* next execution will also operate on this file
675682
*/
676683
if (res.errorCount > 0 || res.warningCount > 0) {
677-
debug("File has problems, skipping it: " + filename);
684+
debug(`File has problems, skipping it: ${filename}`);
678685

679686
// remove the entry from the cache
680687
fileCache.removeEntry(filename);
@@ -713,7 +720,7 @@ CLIEngine.prototype = {
713720
fileCache.reconcile();
714721
}
715722

716-
debug("Linting complete in: " + (Date.now() - startTime) + "ms");
723+
debug(`Linting complete in: ${Date.now() - startTime}ms`);
717724

718725
return {
719726
results,

tools/eslint/lib/cli.js

+17-20
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,30 @@ const cli = {
135135

136136
if (currentOptions.version) { // version from package.json
137137

138-
log.info("v" + require("../package.json").version);
138+
log.info(`v${require("../package.json").version}`);
139139

140+
} else if (currentOptions.printConfig) {
141+
if (files.length) {
142+
log.error("The --print-config option must be used with exactly one file name.");
143+
return 1;
144+
} else if (text) {
145+
log.error("The --print-config option is not available for piped-in code.");
146+
return 1;
147+
}
148+
149+
const engine = new CLIEngine(translateOptions(currentOptions));
150+
151+
const fileConfig = engine.getConfigForFile(currentOptions.printConfig);
152+
153+
log.info(JSON.stringify(fileConfig, null, " "));
154+
return 0;
140155
} else if (currentOptions.help || (!files.length && !text)) {
141156

142157
log.info(options.generateHelp());
143158

144159
} else {
145160

146-
debug("Running on " + (text ? "text" : "files"));
161+
debug(`Running on ${text ? "text" : "files"}`);
147162

148163
// disable --fix for piped-in code until we know how to do it correctly
149164
if (text && currentOptions.fix) {
@@ -153,24 +168,6 @@ const cli = {
153168

154169
const engine = new CLIEngine(translateOptions(currentOptions));
155170

156-
if (currentOptions.printConfig) {
157-
if (files.length !== 1) {
158-
log.error("The --print-config option requires a " +
159-
"single file as positional argument.");
160-
return 1;
161-
}
162-
163-
if (text) {
164-
log.error("The --print-config option is not available for piped-in code.");
165-
return 1;
166-
}
167-
168-
const fileConfig = engine.getConfigForFile(files[0]);
169-
170-
log.info(JSON.stringify(fileConfig, null, " "));
171-
return 0;
172-
}
173-
174171
const report = text ? engine.executeOnText(text, currentOptions.stdinFilename, true) : engine.executeOnFiles(files);
175172

176173
if (currentOptions.fix) {

0 commit comments

Comments
 (0)