Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable caching for ESLint #8296

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ node_g
/.project
/.cproject
icu_config.gypi
.eslintcache

/out

Expand Down
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,8 @@ bench: bench-net bench-http bench-fs bench-tls
bench-ci: bench

jslint:
$(NODE) tools/jslint.js -J benchmark lib test tools
$(NODE) tools/eslint/bin/eslint.js --cache --rulesdir=tools/eslint-rules \
benchmark lib test tools

jslint-ci:
$(NODE) tools/jslint.js $(PARALLEL_ARGS) -f tap -o test-eslint.tap \
Expand Down
3 changes: 2 additions & 1 deletion tools/eslint/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,14 @@ ESLint follows [semantic versioning](http://semver.org). However, due to the nat
* Minor release (might break your lint build)
* A bug fix in a rule that results in ESLint reporting more errors.
* A new rule is created.
* A new option to an existing rule is created.
* A new option to an existing rule that does not result in ESLint reporting more errors by default.
* An existing rule is deprecated.
* A new CLI capability is created.
* New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
* A new formatter is created.
* Major release (likely to break your lint build)
* `eslint:recommended` is updated.
* A new option to an existing rule that results in ESLint reporting more errors by default.
* An existing rule is removed.
* An existing formatter is removed.
* Part of the public API is removed or changed in an incompatible way.
Expand Down
77 changes: 77 additions & 0 deletions tools/eslint/bin/eslint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#!/usr/bin/env node

/**
* @fileoverview Main CLI that is run via the eslint command.
* @author Nicholas C. Zakas
*/

"use strict";

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

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

// must do this initialization *before* other requires in order to work
if (debug) {
require("debug").enable("eslint:*,-eslint:code-path");
}

//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------

// now we can safely include the other modules that use debug
var concat = require("concat-stream"),
cli = require("../lib/cli"),
path = require("path"),
fs = require("fs");

//------------------------------------------------------------------------------
// Execution
//------------------------------------------------------------------------------

process.on("uncaughtException", function(err){
// lazy load
var 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"));

console.log("\nOops! Something went wrong! :(");
console.log("\n" + template(err.messageData || {}));
} else {
console.log(err.message);
console.log(err.stack);
}

process.exit(1);
});

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;
}
}));
} else if (init) {
var configInit = require("../lib/config/config-initializer");
configInit.initializeConfig(function(err) {
if (err) {
process.exitCode = 1;
console.error(err.message);
console.error(err.stack);
} else {
process.exitCode = 0;
}
});
} else {
process.exitCode = cli.execute(process.argv);
}
2 changes: 2 additions & 0 deletions tools/eslint/conf/eslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
"brace-style": "off",
"callback-return": "off",
"camelcase": "off",
"class-methods-use-this": "off",
"comma-dangle": "off",
"comma-spacing": "off",
"comma-style": "off",
Expand Down Expand Up @@ -217,6 +218,7 @@
"space-unary-ops": "off",
"spaced-comment": "off",
"strict": "off",
"symbol-description": "off",
"template-curly-spacing": "off",
"unicode-bom": "off",
"use-isnan": "error",
Expand Down
36 changes: 18 additions & 18 deletions tools/eslint/lib/ast-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,23 @@ module.exports = {
* @returns {boolean} Whether or not the tokens are on the same line.
* @public
*/
isTokenOnSameLine: function(left, right) {
isTokenOnSameLine(left, right) {
return left.loc.end.line === right.loc.start.line;
},

isNullOrUndefined: isNullOrUndefined,
isCallee: isCallee,
isES5Constructor: isES5Constructor,
getUpperFunction: getUpperFunction,
isArrayFromMethod: isArrayFromMethod,
isParenthesised: isParenthesised,
isNullOrUndefined,
isCallee,
isES5Constructor,
getUpperFunction,
isArrayFromMethod,
isParenthesised,

/**
* Checks whether or not a given node is a string literal.
* @param {ASTNode} node - A node to check.
* @returns {boolean} `true` if the node is a string literal.
*/
isStringLiteral: function(node) {
isStringLiteral(node) {
return (
(node.type === "Literal" && typeof node.value === "string") ||
node.type === "TemplateLiteral"
Expand All @@ -247,7 +247,7 @@ module.exports = {
* @param {ASTNode} node - A node to check.
* @returns {boolean} `true` if the node is breakable.
*/
isBreakableStatement: function(node) {
isBreakableStatement(node) {
return breakableTypePattern.test(node.type);
},

Expand All @@ -257,7 +257,7 @@ module.exports = {
* @param {ASTNode} node - A node to get.
* @returns {string|null} The label or `null`.
*/
getLabel: function(node) {
getLabel(node) {
if (node.parent.type === "LabeledStatement") {
return node.parent.label.name;
}
Expand All @@ -270,7 +270,7 @@ module.exports = {
* @returns {Reference[]} An array of only references which are non initializer and writable.
* @public
*/
getModifyingReferences: function(references) {
getModifyingReferences(references) {
return references.filter(isModifyingReference);
},

Expand All @@ -281,7 +281,7 @@ module.exports = {
* @returns {boolean} True if the text is surrounded by the character, false if not.
* @private
*/
isSurroundedBy: function(val, character) {
isSurroundedBy(val, character) {
return val[0] === character && val[val.length - 1] === character;
},

Expand All @@ -290,7 +290,7 @@ module.exports = {
* @param {LineComment|BlockComment} node The node to be checked
* @returns {boolean} `true` if the node is an ESLint directive comment
*/
isDirectiveComment: function(node) {
isDirectiveComment(node) {
const comment = node.value.trim();

return (
Expand Down Expand Up @@ -323,7 +323,7 @@ module.exports = {
* @param {string} name - A variable name to find.
* @returns {escope.Variable|null} A found variable or `null`.
*/
getVariableByName: function(initScope, name) {
getVariableByName(initScope, name) {
let scope = initScope;

while (scope) {
Expand Down Expand Up @@ -360,7 +360,7 @@ module.exports = {
* @param {SourceCode} sourceCode - A SourceCode instance to get comments.
* @returns {boolean} The function node is the default `this` binding.
*/
isDefaultThisBinding: function(node, sourceCode) {
isDefaultThisBinding(node, sourceCode) {
if (isES5Constructor(node) || hasJSDocThisTag(node, sourceCode)) {
return false;
}
Expand Down Expand Up @@ -496,7 +496,7 @@ module.exports = {
* @returns {int} precedence level
* @private
*/
getPrecedence: function(node) {
getPrecedence(node) {
switch (node.type) {
case "SequenceExpression":
return 0;
Expand Down Expand Up @@ -594,7 +594,7 @@ module.exports = {
* @param {ASTNode|null} node - A node to check.
* @returns {boolean} `true` if the node is a loop node.
*/
isLoop: function(node) {
isLoop(node) {
return Boolean(node && anyLoopPattern.test(node.type));
},

Expand All @@ -609,7 +609,7 @@ module.exports = {
* @param {ASTNode|null} node - A node to check.
* @returns {boolean} `true` if the node is a function node.
*/
isFunction: function(node) {
isFunction(node) {
return Boolean(node && anyFunctionPattern.test(node.type));
},

Expand Down
32 changes: 16 additions & 16 deletions tools/eslint/lib/cli-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {

parsedBlocks.forEach(function(block) {
unprocessedMessages.push(eslint.verify(block, config, {
filename: filename,
allowInlineConfig: allowInlineConfig
filename,
allowInlineConfig
}));
});

Expand All @@ -254,14 +254,14 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {

if (fix) {
fixedResult = multipassFix(text, config, {
filename: filename,
allowInlineConfig: allowInlineConfig
filename,
allowInlineConfig
});
messages = fixedResult.messages;
} else {
messages = eslint.verify(text, config, {
filename: filename,
allowInlineConfig: allowInlineConfig
filename,
allowInlineConfig
});
}
}
Expand All @@ -270,7 +270,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {

const result = {
filePath: filename,
messages: messages,
messages,
errorCount: stats.errorCount,
warningCount: stats.warningCount
};
Expand Down Expand Up @@ -329,7 +329,7 @@ function createIgnoreResult(filePath, baseDir) {
{
fatal: false,
severity: 1,
message: message
message
}
],
errorCount: 0,
Expand Down Expand Up @@ -559,7 +559,7 @@ CLIEngine.prototype = {
* @param {Object} pluginobject Plugin configuration object.
* @returns {void}
*/
addPlugin: function(name, pluginobject) {
addPlugin(name, pluginobject) {
Plugins.define(name, pluginobject);
},

Expand All @@ -569,7 +569,7 @@ CLIEngine.prototype = {
* @param {string[]} patterns The file patterns passed on the command line.
* @returns {string[]} The equivalent glob patterns.
*/
resolveFileGlobPatterns: function(patterns) {
resolveFileGlobPatterns(patterns) {
return globUtil.resolveFileGlobPatterns(patterns, this.options);
},

Expand All @@ -578,7 +578,7 @@ CLIEngine.prototype = {
* @param {string[]} patterns An array of file and directory names.
* @returns {Object} The results for all files that were linted.
*/
executeOnFiles: function(patterns) {
executeOnFiles(patterns) {
const results = [],
options = this.options,
fileCache = this._fileCache,
Expand Down Expand Up @@ -716,7 +716,7 @@ CLIEngine.prototype = {
debug("Linting complete in: " + (Date.now() - startTime) + "ms");

return {
results: results,
results,
errorCount: stats.errorCount,
warningCount: stats.warningCount
};
Expand All @@ -729,7 +729,7 @@ CLIEngine.prototype = {
* @param {boolean} warnIgnored Always warn when a file is ignored
* @returns {Object} The results for the linting.
*/
executeOnText: function(text, filename, warnIgnored) {
executeOnText(text, filename, warnIgnored) {

const results = [],
options = this.options,
Expand All @@ -752,7 +752,7 @@ CLIEngine.prototype = {
const stats = calculateStatsPerRun(results);

return {
results: results,
results,
errorCount: stats.errorCount,
warningCount: stats.warningCount
};
Expand All @@ -765,7 +765,7 @@ CLIEngine.prototype = {
* @param {string} filePath The path of the file to retrieve a config object for.
* @returns {Object} A configuration object for the file.
*/
getConfigForFile: function(filePath) {
getConfigForFile(filePath) {
const configHelper = new Config(this.options);

return configHelper.getConfig(filePath);
Expand All @@ -776,7 +776,7 @@ CLIEngine.prototype = {
* @param {string} filePath The path of the file to check.
* @returns {boolean} Whether or not the given path is ignored.
*/
isPathIgnored: function(filePath) {
isPathIgnored(filePath) {
const resolvedPath = path.resolve(this.options.cwd, filePath);
const ignoredPaths = new IgnoredPaths(this.options);

Expand Down
2 changes: 1 addition & 1 deletion tools/eslint/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ const cli = {
* @param {string} [text] The text to lint (used for TTY).
* @returns {int} The exit code for the operation.
*/
execute: function(args, text) {
execute(args, text) {

let currentOptions;

Expand Down
Loading