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.
Files changed (49) hide show
  1. package/CHANGELOG.md +98 -0
  2. package/bin/eslint.js +2 -1
  3. package/conf/eslint-recommended.js +1 -0
  4. package/lib/ast-utils.js +20 -17
  5. package/lib/cli-engine.js +51 -124
  6. package/lib/code-path-analysis/code-path-analyzer.js +8 -4
  7. package/lib/code-path-analysis/code-path-segment.js +2 -1
  8. package/lib/code-path-analysis/code-path-state.js +21 -14
  9. package/lib/code-path-analysis/code-path.js +3 -2
  10. package/lib/code-path-analysis/fork-context.js +2 -1
  11. package/lib/config/autoconfig.js +2 -4
  12. package/lib/config/config-initializer.js +9 -5
  13. package/lib/config/config-ops.js +15 -15
  14. package/lib/config.js +8 -12
  15. package/lib/formatters/codeframe.js +1 -1
  16. package/lib/formatters/stylish.js +1 -1
  17. package/lib/ignored-paths.js +0 -2
  18. package/lib/linter.js +468 -638
  19. package/lib/report-translator.js +274 -0
  20. package/lib/rules/function-paren-newline.js +221 -0
  21. package/lib/rules/generator-star-spacing.js +70 -19
  22. package/lib/rules/indent-legacy.js +3 -2
  23. package/lib/rules/indent.js +15 -6
  24. package/lib/rules/key-spacing.js +2 -1
  25. package/lib/rules/newline-per-chained-call.js +20 -3
  26. package/lib/rules/no-extra-parens.js +75 -33
  27. package/lib/rules/no-invalid-this.js +2 -1
  28. package/lib/rules/no-tabs.js +1 -1
  29. package/lib/rules/no-undef-init.js +4 -0
  30. package/lib/rules/no-unmodified-loop-condition.js +1 -1
  31. package/lib/rules/no-unused-vars.js +47 -4
  32. package/lib/rules/padded-blocks.js +2 -2
  33. package/lib/rules/prefer-arrow-callback.js +1 -2
  34. package/lib/rules/quote-props.js +4 -2
  35. package/lib/rules/quotes.js +1 -2
  36. package/lib/rules/space-before-blocks.js +1 -1
  37. package/lib/rules/valid-jsdoc.js +2 -2
  38. package/lib/rules.js +48 -3
  39. package/lib/testers/rule-tester.js +27 -51
  40. package/lib/timing.js +2 -2
  41. package/lib/util/apply-disable-directives.js +131 -0
  42. package/lib/util/fix-tracker.js +1 -2
  43. package/lib/util/npm-util.js +21 -4
  44. package/lib/util/source-code-fixer.js +5 -14
  45. package/lib/util/source-code.js +3 -5
  46. package/package.json +8 -8
  47. package/lib/rule-context.js +0 -241
  48. package/lib/testers/event-generator-tester.js +0 -62
  49. 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 requiredESLintVersionRange = getPeerDependencies(moduleName).eslint;
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
  });
@@ -193,25 +193,25 @@ module.exports = {
193
193
  },
194
194
 
195
195
  /**
196
- * Converts new-style severity settings (off, warn, error) into old-style
197
- * severity settings (0, 1, 2) for all rules. Assumption is that severity
198
- * values have already been validated as correct.
199
- * @param {Object} config The config object to normalize.
200
- * @returns {void}
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
- normalize(config) {
203
+ getRuleSeverity(ruleConfig) {
204
+ const severityValue = Array.isArray(ruleConfig) ? ruleConfig[0] : ruleConfig;
203
205
 
204
- if (config.rules) {
205
- Object.keys(config.rules).forEach(ruleId => {
206
- const ruleConfig = config.rules[ruleId];
206
+ if (severityValue === 0 || severityValue === 1 || severityValue === 2) {
207
+ return severityValue;
208
+ }
207
209
 
208
- if (typeof ruleConfig === "string") {
209
- config.rules[ruleId] = RULE_SEVERITY[ruleConfig.toLowerCase()] || 0;
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() || null;
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 (PERSONAL_CONFIG_DIR) {
153
- const filename = ConfigFile.getFilenameForDirectory(PERSONAL_CONFIG_DIR);
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 if present
355
- if (config.env) {
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;
@@ -65,7 +65,7 @@ module.exports = function(results) {
65
65
  message.line || 0,
66
66
  message.column || 0,
67
67
  messageType,
68
- message.message.replace(/\.$/, ""),
68
+ message.message.replace(/([^ ])\.$/, "$1"),
69
69
  chalk.dim(message.ruleId || "")
70
70
  ];
71
71
  }),
@@ -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 : "";