eslint 4.5.0 → 4.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +98 -0
- package/bin/eslint.js +2 -1
- package/conf/eslint-recommended.js +1 -0
- package/lib/ast-utils.js +20 -17
- package/lib/cli-engine.js +51 -124
- package/lib/code-path-analysis/code-path-analyzer.js +8 -4
- package/lib/code-path-analysis/code-path-segment.js +2 -1
- package/lib/code-path-analysis/code-path-state.js +21 -14
- package/lib/code-path-analysis/code-path.js +3 -2
- package/lib/code-path-analysis/fork-context.js +2 -1
- package/lib/config/autoconfig.js +2 -4
- package/lib/config/config-initializer.js +9 -5
- package/lib/config/config-ops.js +15 -15
- package/lib/config.js +8 -12
- package/lib/formatters/codeframe.js +1 -1
- package/lib/formatters/stylish.js +1 -1
- package/lib/ignored-paths.js +0 -2
- package/lib/linter.js +468 -638
- package/lib/report-translator.js +274 -0
- package/lib/rules/function-paren-newline.js +221 -0
- package/lib/rules/generator-star-spacing.js +70 -19
- package/lib/rules/indent-legacy.js +3 -2
- package/lib/rules/indent.js +15 -6
- package/lib/rules/key-spacing.js +2 -1
- package/lib/rules/newline-per-chained-call.js +20 -3
- package/lib/rules/no-extra-parens.js +75 -33
- package/lib/rules/no-invalid-this.js +2 -1
- package/lib/rules/no-tabs.js +1 -1
- package/lib/rules/no-undef-init.js +4 -0
- package/lib/rules/no-unmodified-loop-condition.js +1 -1
- package/lib/rules/no-unused-vars.js +47 -4
- package/lib/rules/padded-blocks.js +2 -2
- package/lib/rules/prefer-arrow-callback.js +1 -2
- package/lib/rules/quote-props.js +4 -2
- package/lib/rules/quotes.js +1 -2
- package/lib/rules/space-before-blocks.js +1 -1
- package/lib/rules/valid-jsdoc.js +2 -2
- package/lib/rules.js +48 -3
- package/lib/testers/rule-tester.js +27 -51
- package/lib/timing.js +2 -2
- package/lib/util/apply-disable-directives.js +131 -0
- package/lib/util/fix-tracker.js +1 -2
- package/lib/util/npm-util.js +21 -4
- package/lib/util/source-code-fixer.js +5 -14
- package/lib/util/source-code.js +3 -5
- package/package.json +8 -8
- package/lib/rule-context.js +0 -241
- package/lib/testers/event-generator-tester.js +0 -62
- package/lib/testers/test-parser.js +0 -48
@@ -65,6 +65,7 @@ function writeFile(config, format) {
|
|
65
65
|
* @param {string} moduleName The module name to get.
|
66
66
|
* @returns {Object} The peer dependencies of the given module.
|
67
67
|
* This object is the object of `peerDependencies` field of `package.json`.
|
68
|
+
* Returns null if npm was not found.
|
68
69
|
*/
|
69
70
|
function getPeerDependencies(moduleName) {
|
70
71
|
let result = getPeerDependencies.cache.get(moduleName);
|
@@ -356,7 +357,8 @@ function hasESLintVersionConflict(answers) {
|
|
356
357
|
// Get the required range of ESLint version.
|
357
358
|
const configName = getStyleGuideName(answers);
|
358
359
|
const moduleName = `eslint-config-${configName}@latest`;
|
359
|
-
const
|
360
|
+
const peerDependencies = getPeerDependencies(moduleName) || {};
|
361
|
+
const requiredESLintVersionRange = peerDependencies.eslint;
|
360
362
|
|
361
363
|
if (!requiredESLintVersionRange) {
|
362
364
|
return false;
|
@@ -380,7 +382,6 @@ function hasESLintVersionConflict(answers) {
|
|
380
382
|
* @returns {Promise} The promise with the result of the prompt
|
381
383
|
*/
|
382
384
|
function promptUser() {
|
383
|
-
let config;
|
384
385
|
|
385
386
|
return inquirer.prompt([
|
386
387
|
{
|
@@ -467,7 +468,8 @@ function promptUser() {
|
|
467
468
|
earlyAnswers.styleguide = "airbnb-base";
|
468
469
|
}
|
469
470
|
|
470
|
-
config = getConfigForStyleGuide(earlyAnswers.styleguide, earlyAnswers.installESLint);
|
471
|
+
const config = getConfigForStyleGuide(earlyAnswers.styleguide, earlyAnswers.installESLint);
|
472
|
+
|
471
473
|
writeFile(config, earlyAnswers.format);
|
472
474
|
|
473
475
|
return void 0;
|
@@ -527,7 +529,8 @@ function promptUser() {
|
|
527
529
|
if (earlyAnswers.source === "auto") {
|
528
530
|
const combinedAnswers = Object.assign({}, earlyAnswers, secondAnswers);
|
529
531
|
|
530
|
-
config = processAnswers(combinedAnswers);
|
532
|
+
const config = processAnswers(combinedAnswers);
|
533
|
+
|
531
534
|
installModules(config);
|
532
535
|
writeFile(config, earlyAnswers.format);
|
533
536
|
|
@@ -573,7 +576,8 @@ function promptUser() {
|
|
573
576
|
]).then(answers => {
|
574
577
|
const totalAnswers = Object.assign({}, earlyAnswers, secondAnswers, answers);
|
575
578
|
|
576
|
-
config = processAnswers(totalAnswers);
|
579
|
+
const config = processAnswers(totalAnswers);
|
580
|
+
|
577
581
|
installModules(config);
|
578
582
|
writeFile(config, answers.format);
|
579
583
|
});
|
package/lib/config/config-ops.js
CHANGED
@@ -193,25 +193,25 @@ module.exports = {
|
|
193
193
|
},
|
194
194
|
|
195
195
|
/**
|
196
|
-
*
|
197
|
-
*
|
198
|
-
*
|
199
|
-
*
|
200
|
-
*
|
196
|
+
* Normalizes the severity value of a rule's configuration to a number
|
197
|
+
* @param {(number|string|[number, ...*]|[string, ...*])} ruleConfig A rule's configuration value, generally
|
198
|
+
* received from the user. A valid config value is either 0, 1, 2, the string "off" (treated the same as 0),
|
199
|
+
* the string "warn" (treated the same as 1), the string "error" (treated the same as 2), or an array
|
200
|
+
* whose first element is one of the above values. Strings are matched case-insensitively.
|
201
|
+
* @returns {(0|1|2)} The numeric severity value if the config value was valid, otherwise 0.
|
201
202
|
*/
|
202
|
-
|
203
|
+
getRuleSeverity(ruleConfig) {
|
204
|
+
const severityValue = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
|
203
205
|
|
204
|
-
if (
|
205
|
-
|
206
|
-
|
206
|
+
if (severityValue === 0 || severityValue === 1 || severityValue === 2) {
|
207
|
+
return severityValue;
|
208
|
+
}
|
207
209
|
|
208
|
-
|
209
|
-
|
210
|
-
} else if (Array.isArray(ruleConfig) && typeof ruleConfig[0] === "string") {
|
211
|
-
ruleConfig[0] = RULE_SEVERITY[ruleConfig[0].toLowerCase()] || 0;
|
212
|
-
}
|
213
|
-
});
|
210
|
+
if (typeof severityValue === "string") {
|
211
|
+
return RULE_SEVERITY[severityValue.toLowerCase()] || 0;
|
214
212
|
}
|
213
|
+
|
214
|
+
return 0;
|
215
215
|
},
|
216
216
|
|
217
217
|
/**
|
package/lib/config.js
CHANGED
@@ -24,7 +24,7 @@ const debug = require("debug")("eslint:config");
|
|
24
24
|
// Constants
|
25
25
|
//------------------------------------------------------------------------------
|
26
26
|
|
27
|
-
const PERSONAL_CONFIG_DIR = os.homedir()
|
27
|
+
const PERSONAL_CONFIG_DIR = os.homedir();
|
28
28
|
const SUBCONFIG_SEP = ":";
|
29
29
|
|
30
30
|
//------------------------------------------------------------------------------
|
@@ -148,15 +148,13 @@ class Config {
|
|
148
148
|
getPersonalConfig() {
|
149
149
|
if (typeof this.personalConfig === "undefined") {
|
150
150
|
let config;
|
151
|
+
const filename = ConfigFile.getFilenameForDirectory(PERSONAL_CONFIG_DIR);
|
151
152
|
|
152
|
-
if (
|
153
|
-
|
154
|
-
|
155
|
-
if (filename) {
|
156
|
-
debug("Using personal config");
|
157
|
-
config = ConfigFile.load(filename, this);
|
158
|
-
}
|
153
|
+
if (filename) {
|
154
|
+
debug("Using personal config");
|
155
|
+
config = ConfigFile.load(filename, this);
|
159
156
|
}
|
157
|
+
|
160
158
|
this.personalConfig = config || null;
|
161
159
|
}
|
162
160
|
|
@@ -351,10 +349,8 @@ class Config {
|
|
351
349
|
config = ConfigOps.merge(config, { parser: this.parser });
|
352
350
|
}
|
353
351
|
|
354
|
-
// Step 4: Apply environments to the config
|
355
|
-
|
356
|
-
config = ConfigOps.applyEnvironments(config, this.linterContext.environments);
|
357
|
-
}
|
352
|
+
// Step 4: Apply environments to the config
|
353
|
+
config = ConfigOps.applyEnvironments(config, this.linterContext.environments);
|
358
354
|
|
359
355
|
this.configCache.setMergedConfig(vector, config);
|
360
356
|
|
@@ -47,7 +47,7 @@ function formatFilePath(filePath, line, column) {
|
|
47
47
|
*/
|
48
48
|
function formatMessage(message, parentResult) {
|
49
49
|
const type = (message.fatal || message.severity === 2) ? chalk.red("error") : chalk.yellow("warning");
|
50
|
-
const msg = `${chalk.bold(message.message.replace(
|
50
|
+
const msg = `${chalk.bold(message.message.replace(/([^ ])\.$/, "$1"))}`;
|
51
51
|
const ruleId = message.fatal ? "" : chalk.dim(`(${message.ruleId})`);
|
52
52
|
const filePath = formatFilePath(parentResult.filePath, message.line, message.column);
|
53
53
|
const sourceCode = parentResult.output ? parentResult.output : parentResult.source;
|
package/lib/ignored-paths.js
CHANGED
@@ -47,8 +47,6 @@ const DEFAULT_OPTIONS = {
|
|
47
47
|
* @returns {string} Path of ignore file or an empty string.
|
48
48
|
*/
|
49
49
|
function findFile(cwd, name) {
|
50
|
-
cwd = cwd || DEFAULT_OPTIONS.cwd;
|
51
|
-
|
52
50
|
const ignoreFilePath = path.resolve(cwd, name);
|
53
51
|
|
54
52
|
return fs.existsSync(ignoreFilePath) && fs.statSync(ignoreFilePath).isFile() ? ignoreFilePath : "";
|