Skip to content

Commit 2011158

Browse files
committed
tools: update ESLint to 3.4.0
PR-URL: #8296 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Roman Reiss <[email protected]>
1 parent 932c824 commit 2011158

File tree

303 files changed

+2227
-2058
lines changed

Some content is hidden

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

303 files changed

+2227
-2058
lines changed

tools/eslint/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ ESLint follows [semantic versioning](http://semver.org). However, due to the nat
155155
* Minor release (might break your lint build)
156156
* A bug fix in a rule that results in ESLint reporting more errors.
157157
* A new rule is created.
158-
* A new option to an existing rule is created.
158+
* A new option to an existing rule that does not result in ESLint reporting more errors by default.
159159
* An existing rule is deprecated.
160160
* A new CLI capability is created.
161161
* New capabilities to the public API are added (new classes, new methods, new arguments to existing methods, etc.).
162162
* A new formatter is created.
163163
* Major release (likely to break your lint build)
164164
* `eslint:recommended` is updated.
165+
* A new option to an existing rule that results in ESLint reporting more errors by default.
165166
* An existing rule is removed.
166167
* An existing formatter is removed.
167168
* Part of the public API is removed or changed in an incompatible way.

tools/eslint/bin/eslint.js

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* @fileoverview Main CLI that is run via the eslint command.
5+
* @author Nicholas C. Zakas
6+
*/
7+
8+
"use strict";
9+
10+
//------------------------------------------------------------------------------
11+
// Helpers
12+
//------------------------------------------------------------------------------
13+
14+
var useStdIn = (process.argv.indexOf("--stdin") > -1),
15+
init = (process.argv.indexOf("--init") > -1),
16+
debug = (process.argv.indexOf("--debug") > -1);
17+
18+
// must do this initialization *before* other requires in order to work
19+
if (debug) {
20+
require("debug").enable("eslint:*,-eslint:code-path");
21+
}
22+
23+
//------------------------------------------------------------------------------
24+
// Requirements
25+
//------------------------------------------------------------------------------
26+
27+
// now we can safely include the other modules that use debug
28+
var concat = require("concat-stream"),
29+
cli = require("../lib/cli"),
30+
path = require("path"),
31+
fs = require("fs");
32+
33+
//------------------------------------------------------------------------------
34+
// Execution
35+
//------------------------------------------------------------------------------
36+
37+
process.on("uncaughtException", function(err){
38+
// lazy load
39+
var lodash = require("lodash");
40+
41+
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"));
43+
44+
console.log("\nOops! Something went wrong! :(");
45+
console.log("\n" + template(err.messageData || {}));
46+
} else {
47+
console.log(err.message);
48+
console.log(err.stack);
49+
}
50+
51+
process.exit(1);
52+
});
53+
54+
if (useStdIn) {
55+
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+
}
63+
}));
64+
} else if (init) {
65+
var configInit = require("../lib/config/config-initializer");
66+
configInit.initializeConfig(function(err) {
67+
if (err) {
68+
process.exitCode = 1;
69+
console.error(err.message);
70+
console.error(err.stack);
71+
} else {
72+
process.exitCode = 0;
73+
}
74+
});
75+
} else {
76+
process.exitCode = cli.execute(process.argv);
77+
}

tools/eslint/conf/eslint.json

+2
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
"brace-style": "off",
141141
"callback-return": "off",
142142
"camelcase": "off",
143+
"class-methods-use-this": "off",
143144
"comma-dangle": "off",
144145
"comma-spacing": "off",
145146
"comma-style": "off",
@@ -217,6 +218,7 @@
217218
"space-unary-ops": "off",
218219
"spaced-comment": "off",
219220
"strict": "off",
221+
"symbol-description": "off",
220222
"template-curly-spacing": "off",
221223
"unicode-bom": "off",
222224
"use-isnan": "error",

tools/eslint/lib/ast-utils.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -210,23 +210,23 @@ module.exports = {
210210
* @returns {boolean} Whether or not the tokens are on the same line.
211211
* @public
212212
*/
213-
isTokenOnSameLine: function(left, right) {
213+
isTokenOnSameLine(left, right) {
214214
return left.loc.end.line === right.loc.start.line;
215215
},
216216

217-
isNullOrUndefined: isNullOrUndefined,
218-
isCallee: isCallee,
219-
isES5Constructor: isES5Constructor,
220-
getUpperFunction: getUpperFunction,
221-
isArrayFromMethod: isArrayFromMethod,
222-
isParenthesised: isParenthesised,
217+
isNullOrUndefined,
218+
isCallee,
219+
isES5Constructor,
220+
getUpperFunction,
221+
isArrayFromMethod,
222+
isParenthesised,
223223

224224
/**
225225
* Checks whether or not a given node is a string literal.
226226
* @param {ASTNode} node - A node to check.
227227
* @returns {boolean} `true` if the node is a string literal.
228228
*/
229-
isStringLiteral: function(node) {
229+
isStringLiteral(node) {
230230
return (
231231
(node.type === "Literal" && typeof node.value === "string") ||
232232
node.type === "TemplateLiteral"
@@ -247,7 +247,7 @@ module.exports = {
247247
* @param {ASTNode} node - A node to check.
248248
* @returns {boolean} `true` if the node is breakable.
249249
*/
250-
isBreakableStatement: function(node) {
250+
isBreakableStatement(node) {
251251
return breakableTypePattern.test(node.type);
252252
},
253253

@@ -257,7 +257,7 @@ module.exports = {
257257
* @param {ASTNode} node - A node to get.
258258
* @returns {string|null} The label or `null`.
259259
*/
260-
getLabel: function(node) {
260+
getLabel(node) {
261261
if (node.parent.type === "LabeledStatement") {
262262
return node.parent.label.name;
263263
}
@@ -270,7 +270,7 @@ module.exports = {
270270
* @returns {Reference[]} An array of only references which are non initializer and writable.
271271
* @public
272272
*/
273-
getModifyingReferences: function(references) {
273+
getModifyingReferences(references) {
274274
return references.filter(isModifyingReference);
275275
},
276276

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

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

296296
return (
@@ -323,7 +323,7 @@ module.exports = {
323323
* @param {string} name - A variable name to find.
324324
* @returns {escope.Variable|null} A found variable or `null`.
325325
*/
326-
getVariableByName: function(initScope, name) {
326+
getVariableByName(initScope, name) {
327327
let scope = initScope;
328328

329329
while (scope) {
@@ -360,7 +360,7 @@ module.exports = {
360360
* @param {SourceCode} sourceCode - A SourceCode instance to get comments.
361361
* @returns {boolean} The function node is the default `this` binding.
362362
*/
363-
isDefaultThisBinding: function(node, sourceCode) {
363+
isDefaultThisBinding(node, sourceCode) {
364364
if (isES5Constructor(node) || hasJSDocThisTag(node, sourceCode)) {
365365
return false;
366366
}
@@ -496,7 +496,7 @@ module.exports = {
496496
* @returns {int} precedence level
497497
* @private
498498
*/
499-
getPrecedence: function(node) {
499+
getPrecedence(node) {
500500
switch (node.type) {
501501
case "SequenceExpression":
502502
return 0;
@@ -594,7 +594,7 @@ module.exports = {
594594
* @param {ASTNode|null} node - A node to check.
595595
* @returns {boolean} `true` if the node is a loop node.
596596
*/
597-
isLoop: function(node) {
597+
isLoop(node) {
598598
return Boolean(node && anyLoopPattern.test(node.type));
599599
},
600600

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

tools/eslint/lib/cli-engine.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,8 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
241241

242242
parsedBlocks.forEach(function(block) {
243243
unprocessedMessages.push(eslint.verify(block, config, {
244-
filename: filename,
245-
allowInlineConfig: allowInlineConfig
244+
filename,
245+
allowInlineConfig
246246
}));
247247
});
248248

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

255255
if (fix) {
256256
fixedResult = multipassFix(text, config, {
257-
filename: filename,
258-
allowInlineConfig: allowInlineConfig
257+
filename,
258+
allowInlineConfig
259259
});
260260
messages = fixedResult.messages;
261261
} else {
262262
messages = eslint.verify(text, config, {
263-
filename: filename,
264-
allowInlineConfig: allowInlineConfig
263+
filename,
264+
allowInlineConfig
265265
});
266266
}
267267
}
@@ -270,7 +270,7 @@ function processText(text, configHelper, filename, fix, allowInlineConfig) {
270270

271271
const result = {
272272
filePath: filename,
273-
messages: messages,
273+
messages,
274274
errorCount: stats.errorCount,
275275
warningCount: stats.warningCount
276276
};
@@ -329,7 +329,7 @@ function createIgnoreResult(filePath, baseDir) {
329329
{
330330
fatal: false,
331331
severity: 1,
332-
message: message
332+
message
333333
}
334334
],
335335
errorCount: 0,
@@ -559,7 +559,7 @@ CLIEngine.prototype = {
559559
* @param {Object} pluginobject Plugin configuration object.
560560
* @returns {void}
561561
*/
562-
addPlugin: function(name, pluginobject) {
562+
addPlugin(name, pluginobject) {
563563
Plugins.define(name, pluginobject);
564564
},
565565

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

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

718718
return {
719-
results: results,
719+
results,
720720
errorCount: stats.errorCount,
721721
warningCount: stats.warningCount
722722
};
@@ -729,7 +729,7 @@ CLIEngine.prototype = {
729729
* @param {boolean} warnIgnored Always warn when a file is ignored
730730
* @returns {Object} The results for the linting.
731731
*/
732-
executeOnText: function(text, filename, warnIgnored) {
732+
executeOnText(text, filename, warnIgnored) {
733733

734734
const results = [],
735735
options = this.options,
@@ -752,7 +752,7 @@ CLIEngine.prototype = {
752752
const stats = calculateStatsPerRun(results);
753753

754754
return {
755-
results: results,
755+
results,
756756
errorCount: stats.errorCount,
757757
warningCount: stats.warningCount
758758
};
@@ -765,7 +765,7 @@ CLIEngine.prototype = {
765765
* @param {string} filePath The path of the file to retrieve a config object for.
766766
* @returns {Object} A configuration object for the file.
767767
*/
768-
getConfigForFile: function(filePath) {
768+
getConfigForFile(filePath) {
769769
const configHelper = new Config(this.options);
770770

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

tools/eslint/lib/cli.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ const cli = {
120120
* @param {string} [text] The text to lint (used for TTY).
121121
* @returns {int} The exit code for the operation.
122122
*/
123-
execute: function(args, text) {
123+
execute(args, text) {
124124

125125
let currentOptions;
126126

tools/eslint/lib/code-path-analysis/code-path-analyzer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ CodePathAnalyzer.prototype = {
592592
* @param {ASTNode} node - A node which is entering.
593593
* @returns {void}
594594
*/
595-
enterNode: function(node) {
595+
enterNode(node) {
596596
this.currentNode = node;
597597

598598
// Updates the code path due to node's position in its parent node.
@@ -617,7 +617,7 @@ CodePathAnalyzer.prototype = {
617617
* @param {ASTNode} node - A node which is leaving.
618618
* @returns {void}
619619
*/
620-
leaveNode: function(node) {
620+
leaveNode(node) {
621621
this.currentNode = node;
622622

623623
// Updates the code path.
@@ -641,7 +641,7 @@ CodePathAnalyzer.prototype = {
641641
* @param {CodePathSegment} toSegment - A segment of next.
642642
* @returns {void}
643643
*/
644-
onLooped: function(fromSegment, toSegment) {
644+
onLooped(fromSegment, toSegment) {
645645
if (fromSegment.reachable && toSegment.reachable) {
646646
debug.dump("onCodePathSegmentLoop " + fromSegment.id + " -> " + toSegment.id);
647647
this.emitter.emit(

tools/eslint/lib/code-path-analysis/code-path-segment.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ CodePathSegment.prototype = {
138138
* @param {CodePathSegment} segment - A previous segment to check.
139139
* @returns {boolean} `true` if the segment is coming from the end of a loop.
140140
*/
141-
isLoopedPrevSegment: function(segment) {
141+
isLoopedPrevSegment(segment) {
142142
return this.internal.loopedPrevSegments.indexOf(segment) !== -1;
143143
}
144144
};

0 commit comments

Comments
 (0)