Skip to content

Commit

Permalink
tools: update ESLint to v3.8.0
Browse files Browse the repository at this point in the history
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 <teddy.katz@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
  • Loading branch information
Trott authored and Myles Borins committed Nov 11, 2016
1 parent 39a53a0 commit e9d5cd7
Show file tree
Hide file tree
Showing 645 changed files with 40,455 additions and 25,113 deletions.
3,412 changes: 0 additions & 3,412 deletions tools/eslint/CHANGELOG.md

This file was deleted.

1 change: 1 addition & 0 deletions tools/eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ These folks keep the project moving and are resources for help.
* Kevin Partington ([@platinumazure](https://github.com/platinumazure))
* Vitor Balocco ([@vitorbal](https://github.com/vitorbal))
* James Henry ([@JamesHenry](https://github.com/JamesHenry))
* Teddy Katz ([@not-an-aardvark](https://github.com/not-an-aardvark))

## Releases

Expand Down
26 changes: 12 additions & 14 deletions tools/eslint/bin/eslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
* @author Nicholas C. Zakas
*/

/* eslint no-console:off, no-process-exit:off */

"use strict";

//------------------------------------------------------------------------------
// Helpers
//------------------------------------------------------------------------------

var useStdIn = (process.argv.indexOf("--stdin") > -1),
const useStdIn = (process.argv.indexOf("--stdin") > -1),
init = (process.argv.indexOf("--init") > -1),
debug = (process.argv.indexOf("--debug") > -1);

Expand All @@ -25,7 +27,7 @@ if (debug) {
//------------------------------------------------------------------------------

// now we can safely include the other modules that use debug
var concat = require("concat-stream"),
const concat = require("concat-stream"),
cli = require("../lib/cli"),
path = require("path"),
fs = require("fs");
Expand All @@ -34,15 +36,16 @@ var concat = require("concat-stream"),
// Execution
//------------------------------------------------------------------------------

process.on("uncaughtException", function(err){
process.on("uncaughtException", function(err) {

// lazy load
var lodash = require("lodash");
const lodash = require("lodash");

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

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

if (useStdIn) {
process.stdin.pipe(concat({ encoding: "string" }, function(text) {
try {
process.exitCode = cli.execute(process.argv, text);
} catch (ex) {
console.error(ex.message);
console.error(ex.stack);
process.exitCode = 1;
}
process.exitCode = cli.execute(process.argv, text);
}));
} else if (init) {
var configInit = require("../lib/config/config-initializer");
const configInit = require("../lib/config/config-initializer");

configInit.initializeConfig(function(err) {
if (err) {
process.exitCode = 1;
Expand Down
1 change: 1 addition & 0 deletions tools/eslint/conf/eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
"eqeqeq": "off",
"func-call-spacing": "off",
"func-names": "off",
"func-name-matching": "off",
"func-style": "off",
"generator-star-spacing": "off",
"global-require": "off",
Expand Down
23 changes: 23 additions & 0 deletions tools/eslint/lib/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ module.exports = {
/* falls through */

case "UnaryExpression":
case "AwaitExpression":
return 14;

case "UpdateExpression":
Expand Down Expand Up @@ -715,5 +716,27 @@ module.exports = {
}

return directives;
},


/**
* Determines whether this node is a decimal integer literal. If a node is a decimal integer literal, a dot added
after the node will be parsed as a decimal point, rather than a property-access dot.
* @param {ASTNode} node - The node to check.
* @returns {boolean} `true` if this node is a decimal integer.
* @example
*
* 5 // true
* 5. // false
* 5.0 // false
* 05 // false
* 0x5 // false
* 0b101 // false
* 0o5 // false
* 5e0 // false
* '5' // false
*/
isDecimalInteger(node) {
return node.type === "Literal" && typeof node.value === "number" && /^(0|[1-9]\d*)$/.test(node.raw);
}
};
51 changes: 29 additions & 22 deletions tools/eslint/lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ const debug = require("debug")("eslint:cli-engine");
* @property {LintMessage[]} messages All of the messages for the result.
* @property {number} errorCount Number or errors for the result.
* @property {number} warningCount Number or warnings for the result.
* @property {string=} [source] The source code of the file that was linted.
* @property {string=} [output] The source code of the file that was linted, with as many fixes applied as possible.
*/

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -150,10 +152,10 @@ function multipassFix(text, config, options) {
do {
passNumber++;

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

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

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


/*
* If the last result had fixes, we need to lint again to me sure we have
* 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) {
Expand All @@ -198,7 +200,7 @@ function multipassFix(text, config, options) {
* @param {string} filename An optional string representing the texts filename.
* @param {boolean} fix Indicates if fixes should be processed.
* @param {boolean} allowInlineConfig Allow/ignore comments that change config.
* @returns {Result} The results for linting on this text.
* @returns {LintResult} The results for linting on this text.
* @private
*/
function processText(text, configHelper, filename, fix, allowInlineConfig) {
Expand All @@ -218,7 +220,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
}

filename = filename || "<text>";
debug("Linting " + filename);
debug(`Linting ${filename}`);
const config = configHelper.getConfig(filePath);

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

if (result.errorCount + result.warningCount > 0 && typeof result.output === "undefined") {
result.source = text;
}

return result;
}

Expand All @@ -288,7 +294,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
* @param {string} filename The filename of the file being checked.
* @param {Object} configHelper The configuration options for ESLint.
* @param {Object} options The CLIEngine options object.
* @returns {Result} The results for linting on this file.
* @returns {LintResult} The results for linting on this file.
* @private
*/
function processFile(filename, configHelper, options) {
Expand All @@ -304,7 +310,7 @@ function processFile(filename, configHelper, options) {
* Returns result with warning by ignore settings
* @param {string} filePath - File path of checked code
* @param {string} baseDir - Absolute path of base directory
* @returns {Result} Result with single warning
* @returns {LintResult} Result with single warning
* @private
*/
function createIgnoreResult(filePath, baseDir) {
Expand Down Expand Up @@ -376,7 +382,7 @@ function getCacheFile(cacheFile, cwd) {
* @returns {string} the resolved path to the cacheFile
*/
function getCacheFileForDirectory() {
return path.join(resolvedCacheFile, ".cache_" + hash(cwd));
return path.join(resolvedCacheFile, `.cache_${hash(cwd)}`);
}

let fileStats;
Expand Down Expand Up @@ -461,7 +467,7 @@ function CLIEngine(options) {
const cwd = this.options.cwd;

this.options.rulePaths.forEach(function(rulesdir) {
debug("Loading rules from " + rulesdir);
debug(`Loading rules from ${rulesdir}`);
rules.load(rulesdir, cwd);
});
}
Expand Down Expand Up @@ -497,13 +503,13 @@ CLIEngine.getFormatter = function(format) {

formatterPath = path.resolve(cwd, format);
} else {
formatterPath = "./formatters/" + format;
formatterPath = `./formatters/${format}`;
}

try {
return require(formatterPath);
} catch (ex) {
ex.message = "There was a problem loading formatter: " + formatterPath + "\nError: " + ex.message;
ex.message = `There was a problem loading formatter: ${formatterPath}\nError: ${ex.message}`;
throw ex;
}

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

if (filteredMessages.length > 0) {
filtered.push({
filePath: result.filePath,
messages: filteredMessages,
errorCount: filteredMessages.length,
warningCount: 0
});
filtered.push(
Object.assign(result, {
messages: filteredMessages,
errorCount: filteredMessages.length,
warningCount: 0
})
);
}
});

Expand Down Expand Up @@ -608,7 +615,7 @@ CLIEngine.prototype = {

const eslintVersion = pkg.version;

prevConfig.hash = hash(eslintVersion + "_" + stringify(config));
prevConfig.hash = hash(`${eslintVersion}_${stringify(config)}`);
}

return prevConfig.hash;
Expand Down Expand Up @@ -645,7 +652,7 @@ CLIEngine.prototype = {
const changed = descriptor.changed || meta.hashOfConfig !== hashOfConfig;

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

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

debug("Processing " + filename);
debug(`Processing ${filename}`);

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

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

// remove the entry from the cache
fileCache.removeEntry(filename);
Expand Down Expand Up @@ -713,7 +720,7 @@ CLIEngine.prototype = {
fileCache.reconcile();
}

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

return {
results,
Expand Down
37 changes: 17 additions & 20 deletions tools/eslint/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,30 @@ const cli = {

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

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

} else if (currentOptions.printConfig) {
if (files.length) {
log.error("The --print-config option must be used with exactly one file name.");
return 1;
} else if (text) {
log.error("The --print-config option is not available for piped-in code.");
return 1;
}

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

const fileConfig = engine.getConfigForFile(currentOptions.printConfig);

log.info(JSON.stringify(fileConfig, null, " "));
return 0;
} else if (currentOptions.help || (!files.length && !text)) {

log.info(options.generateHelp());

} else {

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

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

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

if (currentOptions.printConfig) {
if (files.length !== 1) {
log.error("The --print-config option requires a " +
"single file as positional argument.");
return 1;
}

if (text) {
log.error("The --print-config option is not available for piped-in code.");
return 1;
}

const fileConfig = engine.getConfigForFile(files[0]);

log.info(JSON.stringify(fileConfig, null, " "));
return 0;
}

const report = text ? engine.executeOnText(text, currentOptions.stdinFilename, true) : engine.executeOnFiles(files);

if (currentOptions.fix) {
Expand Down
Loading

0 comments on commit e9d5cd7

Please sign in to comment.