eslint 4.10.0 → 4.11.0

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 (103) hide show
  1. package/CHANGELOG.md +36 -22
  2. package/conf/default-cli-options.js +5 -3
  3. package/lib/ast-utils.js +81 -41
  4. package/lib/cli-engine.js +27 -12
  5. package/lib/code-path-analysis/code-path-analyzer.js +8 -4
  6. package/lib/code-path-analysis/code-path-segment.js +4 -2
  7. package/lib/code-path-analysis/code-path-state.js +4 -2
  8. package/lib/config/autoconfig.js +14 -12
  9. package/lib/config/config-file.js +8 -51
  10. package/lib/config/config-initializer.js +10 -6
  11. package/lib/config/config-ops.js +21 -21
  12. package/lib/config/config-rule.js +24 -24
  13. package/lib/config/config-validator.js +38 -36
  14. package/lib/config/plugins.js +8 -35
  15. package/lib/config.js +12 -8
  16. package/lib/formatters/junit.js +21 -15
  17. package/lib/formatters/tap.js +5 -3
  18. package/lib/ignored-paths.js +4 -2
  19. package/lib/linter.js +16 -10
  20. package/lib/rules/.eslintrc.yml +2 -2
  21. package/lib/rules/array-bracket-newline.js +20 -20
  22. package/lib/rules/array-bracket-spacing.js +28 -28
  23. package/lib/rules/array-callback-return.js +13 -9
  24. package/lib/rules/array-element-newline.js +8 -8
  25. package/lib/rules/arrow-body-style.js +12 -6
  26. package/lib/rules/arrow-parens.js +4 -2
  27. package/lib/rules/brace-style.js +14 -14
  28. package/lib/rules/computed-property-spacing.js +22 -22
  29. package/lib/rules/consistent-return.js +4 -4
  30. package/lib/rules/consistent-this.js +4 -2
  31. package/lib/rules/curly.js +13 -9
  32. package/lib/rules/dot-notation.js +5 -5
  33. package/lib/rules/func-call-spacing.js +4 -2
  34. package/lib/rules/getter-return.js +2 -1
  35. package/lib/rules/indent-legacy.js +20 -12
  36. package/lib/rules/indent.js +77 -73
  37. package/lib/rules/key-spacing.js +5 -3
  38. package/lib/rules/lines-around-directive.js +16 -12
  39. package/lib/rules/max-statements-per-line.js +5 -3
  40. package/lib/rules/newline-after-var.js +8 -6
  41. package/lib/rules/newline-before-return.js +9 -7
  42. package/lib/rules/no-await-in-loop.js +17 -9
  43. package/lib/rules/no-bitwise.js +5 -3
  44. package/lib/rules/no-catch-shadow.js +4 -2
  45. package/lib/rules/no-console.js +2 -1
  46. package/lib/rules/no-else-return.js +17 -11
  47. package/lib/rules/no-empty-character-class.js +11 -11
  48. package/lib/rules/no-extra-parens.js +16 -8
  49. package/lib/rules/no-extra-semi.js +5 -3
  50. package/lib/rules/no-global-assign.js +4 -2
  51. package/lib/rules/no-implicit-coercion.js +6 -6
  52. package/lib/rules/no-implied-eval.js +2 -1
  53. package/lib/rules/no-label-var.js +4 -2
  54. package/lib/rules/no-lone-blocks.js +3 -3
  55. package/lib/rules/no-loop-func.js +8 -4
  56. package/lib/rules/no-native-reassign.js +4 -2
  57. package/lib/rules/no-param-reassign.js +4 -2
  58. package/lib/rules/no-regex-spaces.js +1 -1
  59. package/lib/rules/no-restricted-properties.js +10 -10
  60. package/lib/rules/no-return-await.js +6 -6
  61. package/lib/rules/no-self-assign.js +4 -2
  62. package/lib/rules/no-sequences.js +6 -4
  63. package/lib/rules/no-trailing-spaces.js +13 -7
  64. package/lib/rules/no-unreachable.js +4 -2
  65. package/lib/rules/no-use-before-define.js +13 -11
  66. package/lib/rules/no-useless-call.js +1 -25
  67. package/lib/rules/no-useless-escape.js +23 -22
  68. package/lib/rules/no-useless-return.js +14 -8
  69. package/lib/rules/no-whitespace-before-property.js +4 -2
  70. package/lib/rules/object-curly-newline.js +9 -2
  71. package/lib/rules/object-curly-spacing.js +20 -20
  72. package/lib/rules/object-shorthand.js +41 -33
  73. package/lib/rules/operator-assignment.js +9 -9
  74. package/lib/rules/operator-linebreak.js +12 -10
  75. package/lib/rules/padding-line-between-statements.js +4 -2
  76. package/lib/rules/prefer-arrow-callback.js +12 -10
  77. package/lib/rules/prefer-const.js +18 -10
  78. package/lib/rules/prefer-destructuring.js +4 -2
  79. package/lib/rules/prefer-numeric-literals.js +4 -2
  80. package/lib/rules/prefer-promise-reject-errors.js +16 -16
  81. package/lib/rules/prefer-rest-params.js +4 -2
  82. package/lib/rules/prefer-spread.js +1 -25
  83. package/lib/rules/prefer-template.js +33 -29
  84. package/lib/rules/quote-props.js +8 -8
  85. package/lib/rules/semi-style.js +44 -19
  86. package/lib/rules/semi.js +5 -3
  87. package/lib/rules/sort-imports.js +5 -3
  88. package/lib/rules/space-unary-ops.js +61 -61
  89. package/lib/rules/strict.js +8 -8
  90. package/lib/rules/valid-typeof.js +4 -4
  91. package/lib/rules/wrap-iife.js +4 -4
  92. package/lib/rules/yoda.js +9 -7
  93. package/lib/testers/rule-tester.js +43 -34
  94. package/lib/token-store/backward-token-cursor.js +5 -3
  95. package/lib/token-store/forward-token-cursor.js +5 -3
  96. package/lib/token-store/utils.js +8 -4
  97. package/lib/util/glob.js +1 -1
  98. package/lib/util/naming.js +112 -0
  99. package/lib/util/node-event-generator.js +10 -10
  100. package/lib/util/safe-emitter.js +1 -1
  101. package/lib/util/source-code-fixer.js +4 -2
  102. package/lib/util/source-code.js +2 -1
  103. package/package.json +6 -5
@@ -187,19 +187,19 @@ class RuleConfigSet {
187
187
  constructor(configs) {
188
188
 
189
189
  /**
190
- * Stored valid rule configurations for this instance
191
- * @type {array}
192
- */
190
+ * Stored valid rule configurations for this instance
191
+ * @type {array}
192
+ */
193
193
  this.ruleConfigs = configs || [];
194
194
  }
195
195
 
196
196
  /**
197
- * Add a severity level to the front of all configs in the instance.
198
- * This should only be called after all configs have been added to the instance.
199
- *
200
- * @param {number} [severity=2] The level of severity for the rule (0, 1, 2)
201
- * @returns {void}
202
- */
197
+ * Add a severity level to the front of all configs in the instance.
198
+ * This should only be called after all configs have been added to the instance.
199
+ *
200
+ * @param {number} [severity=2] The level of severity for the rule (0, 1, 2)
201
+ * @returns {void}
202
+ */
203
203
  addErrorSeverity(severity) {
204
204
  severity = severity || 2;
205
205
 
@@ -213,19 +213,19 @@ class RuleConfigSet {
213
213
  }
214
214
 
215
215
  /**
216
- * Add rule configs from an array of strings (schema enums)
217
- * @param {string[]} enums Array of valid rule options (e.g. ["always", "never"])
218
- * @returns {void}
219
- */
216
+ * Add rule configs from an array of strings (schema enums)
217
+ * @param {string[]} enums Array of valid rule options (e.g. ["always", "never"])
218
+ * @returns {void}
219
+ */
220
220
  addEnums(enums) {
221
221
  this.ruleConfigs = this.ruleConfigs.concat(combineArrays(this.ruleConfigs, enums));
222
222
  }
223
223
 
224
224
  /**
225
- * Add rule configurations from a schema object
226
- * @param {Object} obj Schema item with type === "object"
227
- * @returns {boolean} true if at least one schema for the object could be generated, false otherwise
228
- */
225
+ * Add rule configurations from a schema object
226
+ * @param {Object} obj Schema item with type === "object"
227
+ * @returns {boolean} true if at least one schema for the object could be generated, false otherwise
228
+ */
229
229
  addObject(obj) {
230
230
  const objectConfigSet = {
231
231
  objectConfigs: [],
@@ -267,10 +267,10 @@ class RuleConfigSet {
267
267
  }
268
268
 
269
269
  /**
270
- * Generate valid rule configurations based on a schema object
271
- * @param {Object} schema A rule's schema object
272
- * @returns {array[]} Valid rule configurations
273
- */
270
+ * Generate valid rule configurations based on a schema object
271
+ * @param {Object} schema A rule's schema object
272
+ * @returns {array[]} Valid rule configurations
273
+ */
274
274
  function generateConfigsFromSchema(schema) {
275
275
  const configSet = new RuleConfigSet();
276
276
 
@@ -296,9 +296,9 @@ function generateConfigsFromSchema(schema) {
296
296
  }
297
297
 
298
298
  /**
299
- * Generate possible rule configurations for all of the core rules
300
- * @returns {rulesConfig} Hash of rule names and arrays of possible configurations
301
- */
299
+ * Generate possible rule configurations for all of the core rules
300
+ * @returns {rulesConfig} Hash of rule names and arrays of possible configurations
301
+ */
302
302
  function createCoreRuleConfigs() {
303
303
  const ruleList = loadRules();
304
304
 
@@ -14,9 +14,7 @@ const ajv = require("../util/ajv"),
14
14
  configSchema = require("../../conf/config-schema.js"),
15
15
  util = require("util");
16
16
 
17
- const validators = {
18
- rules: Object.create(null)
19
- };
17
+ const ruleValidators = new WeakMap();
20
18
 
21
19
  //------------------------------------------------------------------------------
22
20
  // Private
@@ -25,13 +23,11 @@ let validateSchema;
25
23
 
26
24
  /**
27
25
  * Gets a complete options schema for a rule.
28
- * @param {string} id The rule's unique name.
29
- * @param {Rules} rulesContext Rule context
26
+ * @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
30
27
  * @returns {Object} JSON Schema for the rule's options.
31
28
  */
32
- function getRuleOptionsSchema(id, rulesContext) {
33
- const rule = rulesContext.get(id),
34
- schema = rule && rule.schema || rule && rule.meta && rule.meta.schema;
29
+ function getRuleOptionsSchema(rule) {
30
+ const schema = rule.schema || rule.meta && rule.meta.schema;
35
31
 
36
32
  // Given a tuple of schemas, insert warning level at the beginning
37
33
  if (Array.isArray(schema)) {
@@ -56,10 +52,10 @@ function getRuleOptionsSchema(id, rulesContext) {
56
52
  }
57
53
 
58
54
  /**
59
- * Validates a rule's severity and returns the severity value. Throws an error if the severity is invalid.
60
- * @param {options} options The given options for the rule.
61
- * @returns {number|string} The rule's severity value
62
- */
55
+ * Validates a rule's severity and returns the severity value. Throws an error if the severity is invalid.
56
+ * @param {options} options The given options for the rule.
57
+ * @returns {number|string} The rule's severity value
58
+ */
63
59
  function validateRuleSeverity(options) {
64
60
  const severity = Array.isArray(options) ? options[0] : options;
65
61
 
@@ -71,46 +67,52 @@ function validateRuleSeverity(options) {
71
67
  }
72
68
 
73
69
  /**
74
- * Validates the non-severity options passed to a rule, based on its schema.
75
- * @param {string} id The rule's unique name
76
- * @param {array} localOptions The options for the rule, excluding severity
77
- * @param {Rules} rulesContext Rule context
78
- * @returns {void}
79
- */
80
- function validateRuleSchema(id, localOptions, rulesContext) {
81
- const schema = getRuleOptionsSchema(id, rulesContext);
82
-
83
- if (!validators.rules[id] && schema) {
84
- validators.rules[id] = ajv.compile(schema);
70
+ * Validates the non-severity options passed to a rule, based on its schema.
71
+ * @param {{create: Function}} rule The rule to validate
72
+ * @param {array} localOptions The options for the rule, excluding severity
73
+ * @returns {void}
74
+ */
75
+ function validateRuleSchema(rule, localOptions) {
76
+ if (!ruleValidators.has(rule)) {
77
+ const schema = getRuleOptionsSchema(rule);
78
+
79
+ if (schema) {
80
+ ruleValidators.set(rule, ajv.compile(schema));
81
+ }
85
82
  }
86
83
 
87
- const validateRule = validators.rules[id];
84
+ const validateRule = ruleValidators.get(rule);
88
85
 
89
86
  if (validateRule) {
90
87
  validateRule(localOptions);
91
88
  if (validateRule.errors) {
92
- throw new Error(validateRule.errors.map(error => `\tValue "${error.data}" ${error.message}.\n`).join(""));
89
+ throw new Error(validateRule.errors.map(
90
+ error => `\tValue ${JSON.stringify(error.data)} ${error.message}.\n`
91
+ ).join(""));
93
92
  }
94
93
  }
95
94
  }
96
95
 
97
96
  /**
98
97
  * Validates a rule's options against its schema.
99
- * @param {string} id The rule's unique name.
98
+ * @param {{create: Function}|null} rule The rule that the config is being validated for
99
+ * @param {string} ruleId The rule's unique name.
100
100
  * @param {array|number} options The given options for the rule.
101
101
  * @param {string} source The name of the configuration source to report in any errors.
102
- * @param {Rules} rulesContext Rule context
103
102
  * @returns {void}
104
103
  */
105
- function validateRuleOptions(id, options, source, rulesContext) {
104
+ function validateRuleOptions(rule, ruleId, options, source) {
105
+ if (!rule) {
106
+ return;
107
+ }
106
108
  try {
107
109
  const severity = validateRuleSeverity(options);
108
110
 
109
111
  if (severity !== 0 && !(typeof severity === "string" && severity.toLowerCase() === "off")) {
110
- validateRuleSchema(id, Array.isArray(options) ? options.slice(1) : [], rulesContext);
112
+ validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
111
113
  }
112
114
  } catch (err) {
113
- throw new Error(`${source}:\n\tConfiguration for rule "${id}" is invalid:\n${err.message}`);
115
+ throw new Error(`${source}:\n\tConfiguration for rule "${ruleId}" is invalid:\n${err.message}`);
114
116
  }
115
117
  }
116
118
 
@@ -141,16 +143,16 @@ function validateEnvironment(environment, source, envContext) {
141
143
  * Validates a rules config object
142
144
  * @param {Object} rulesConfig The rules config object to validate.
143
145
  * @param {string} source The name of the configuration source to report in any errors.
144
- * @param {Rules} rulesContext Rule context
146
+ * @param {function(string): {create: Function}} ruleMapper A mapper function from strings to loaded rules
145
147
  * @returns {void}
146
148
  */
147
- function validateRules(rulesConfig, source, rulesContext) {
149
+ function validateRules(rulesConfig, source, ruleMapper) {
148
150
  if (!rulesConfig) {
149
151
  return;
150
152
  }
151
153
 
152
154
  Object.keys(rulesConfig).forEach(id => {
153
- validateRuleOptions(id, rulesConfig[id], source, rulesContext);
155
+ validateRuleOptions(ruleMapper(id), id, rulesConfig[id], source);
154
156
  });
155
157
  }
156
158
 
@@ -221,13 +223,13 @@ function validateConfigSchema(config, source) {
221
223
  * Validates an entire config object.
222
224
  * @param {Object} config The config object to validate.
223
225
  * @param {string} source The name of the configuration source to report in any errors.
224
- * @param {Rules} rulesContext The rules context
226
+ * @param {function(string): {create: Function}} ruleMapper A mapper function from rule IDs to defined rules
225
227
  * @param {Environments} envContext The env context
226
228
  * @returns {void}
227
229
  */
228
- function validate(config, source, rulesContext, envContext) {
230
+ function validate(config, source, ruleMapper, envContext) {
229
231
  validateConfigSchema(config, source);
230
- validateRules(config.rules, source, rulesContext);
232
+ validateRules(config.rules, source, ruleMapper);
231
233
  validateEnvironment(config.env, source, envContext);
232
234
  }
233
235
 
@@ -9,13 +9,13 @@
9
9
  //------------------------------------------------------------------------------
10
10
 
11
11
  const debug = require("debug")("eslint:plugins");
12
+ const naming = require("../util/naming");
12
13
 
13
14
  //------------------------------------------------------------------------------
14
15
  // Private
15
16
  //------------------------------------------------------------------------------
16
17
 
17
- const PLUGIN_NAME_PREFIX = "eslint-plugin-",
18
- NAMESPACE_REGEX = /^@.*\//i;
18
+ const PLUGIN_NAME_PREFIX = "eslint-plugin-";
19
19
 
20
20
  //------------------------------------------------------------------------------
21
21
  // Public Interface
@@ -37,33 +37,6 @@ class Plugins {
37
37
  this._rules = rulesContext;
38
38
  }
39
39
 
40
- /**
41
- * Removes the prefix `eslint-plugin-` from a plugin name.
42
- * @param {string} pluginName The name of the plugin which may have the prefix.
43
- * @returns {string} The name of the plugin without prefix.
44
- */
45
- static removePrefix(pluginName) {
46
- return pluginName.startsWith(PLUGIN_NAME_PREFIX) ? pluginName.slice(PLUGIN_NAME_PREFIX.length) : pluginName;
47
- }
48
-
49
- /**
50
- * Gets the scope (namespace) of a plugin.
51
- * @param {string} pluginName The name of the plugin which may have the prefix.
52
- * @returns {string} The name of the plugins namepace if it has one.
53
- */
54
- static getNamespace(pluginName) {
55
- return pluginName.match(NAMESPACE_REGEX) ? pluginName.match(NAMESPACE_REGEX)[0] : "";
56
- }
57
-
58
- /**
59
- * Removes the namespace from a plugin name.
60
- * @param {string} pluginName The name of the plugin which may have the prefix.
61
- * @returns {string} The name of the plugin without the namespace.
62
- */
63
- static removeNamespace(pluginName) {
64
- return pluginName.replace(NAMESPACE_REGEX, "");
65
- }
66
-
67
40
  /**
68
41
  * Defines a plugin with a given name rather than loading from disk.
69
42
  * @param {string} pluginName The name of the plugin to load.
@@ -71,9 +44,9 @@ class Plugins {
71
44
  * @returns {void}
72
45
  */
73
46
  define(pluginName, plugin) {
74
- const pluginNamespace = Plugins.getNamespace(pluginName),
75
- pluginNameWithoutNamespace = Plugins.removeNamespace(pluginName),
76
- pluginNameWithoutPrefix = Plugins.removePrefix(pluginNameWithoutNamespace),
47
+ const pluginNamespace = naming.getNamespaceFromTerm(pluginName),
48
+ pluginNameWithoutNamespace = naming.removeNamespaceFromTerm(pluginName),
49
+ pluginNameWithoutPrefix = naming.removePrefixFromTerm(PLUGIN_NAME_PREFIX, pluginNameWithoutNamespace),
77
50
  shortName = pluginNamespace + pluginNameWithoutPrefix;
78
51
 
79
52
  // load up environments and rules
@@ -106,9 +79,9 @@ class Plugins {
106
79
  * @throws {Error} If the plugin cannot be loaded.
107
80
  */
108
81
  load(pluginName) {
109
- const pluginNamespace = Plugins.getNamespace(pluginName),
110
- pluginNameWithoutNamespace = Plugins.removeNamespace(pluginName),
111
- pluginNameWithoutPrefix = Plugins.removePrefix(pluginNameWithoutNamespace),
82
+ const pluginNamespace = naming.getNamespaceFromTerm(pluginName),
83
+ pluginNameWithoutNamespace = naming.removeNamespaceFromTerm(pluginName),
84
+ pluginNameWithoutPrefix = naming.removePrefixFromTerm(PLUGIN_NAME_PREFIX, pluginNameWithoutNamespace),
112
85
  shortName = pluginNamespace + pluginNameWithoutPrefix,
113
86
  longName = pluginNamespace + PLUGIN_NAME_PREFIX + pluginNameWithoutPrefix;
114
87
  let plugin = null;
package/lib/config.js CHANGED
@@ -120,10 +120,10 @@ class Config {
120
120
  }
121
121
 
122
122
  /**
123
- * Loads the config options from a config specified on the command line.
124
- * @param {string} [config] A shareable named config or path to a config file.
125
- * @returns {void}
126
- */
123
+ * Loads the config options from a config specified on the command line.
124
+ * @param {string} [config] A shareable named config or path to a config file.
125
+ * @returns {void}
126
+ */
127
127
  loadSpecificConfig(config) {
128
128
  if (config) {
129
129
  debug(`Using command line config ${config}`);
@@ -216,8 +216,10 @@ class Config {
216
216
  return localConfigHierarchy;
217
217
  }
218
218
 
219
- // Don't consider the personal config file in the home directory,
220
- // except if the home directory is the same as the current working directory
219
+ /*
220
+ * Don't consider the personal config file in the home directory,
221
+ * except if the home directory is the same as the current working directory
222
+ */
221
223
  if (localConfigDirectory === PERSONAL_CONFIG_DIR && localConfigFile !== projectConfigPath) {
222
224
  continue;
223
225
  }
@@ -343,8 +345,10 @@ class Config {
343
345
  this.plugins.loadAll(this.cliConfig.plugins);
344
346
  }
345
347
 
346
- // Step 3: Override parser only if it is passed explicitly through the command line
347
- // or if it's not defined yet (because the final object will at least have the parser key)
348
+ /*
349
+ * Step 3: Override parser only if it is passed explicitly through the command line
350
+ * or if it's not defined yet (because the final object will at least have the parser key)
351
+ */
348
352
  if (this.parser || !config.parser) {
349
353
  config = ConfigOps.merge(config, { parser: this.parser });
350
354
  }
@@ -39,22 +39,28 @@ module.exports = function(results) {
39
39
 
40
40
  const messages = result.messages;
41
41
 
42
- output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
43
- messages.forEach(message => {
44
- const type = message.fatal ? "error" : "failure";
42
+ if (messages.length > 0) {
43
+ output += `<testsuite package="org.eslint" time="0" tests="${messages.length}" errors="${messages.length}" name="${result.filePath}">\n`;
44
+ messages.forEach(message => {
45
+ const type = message.fatal ? "error" : "failure";
45
46
 
46
- output += `<testcase time="0" name="org.eslint.${message.ruleId || "unknown"}">`;
47
- output += `<${type} message="${xmlEscape(message.message || "")}">`;
48
- output += "<![CDATA[";
49
- output += `line ${message.line || 0}, col `;
50
- output += `${message.column || 0}, ${getMessageType(message)}`;
51
- output += ` - ${xmlEscape(message.message || "")}`;
52
- output += (message.ruleId ? ` (${message.ruleId})` : "");
53
- output += "]]>";
54
- output += `</${type}>`;
55
- output += "</testcase>\n";
56
- });
57
- output += "</testsuite>\n";
47
+ output += `<testcase time="0" name="org.eslint.${message.ruleId || "unknown"}">`;
48
+ output += `<${type} message="${xmlEscape(message.message || "")}">`;
49
+ output += "<![CDATA[";
50
+ output += `line ${message.line || 0}, col `;
51
+ output += `${message.column || 0}, ${getMessageType(message)}`;
52
+ output += ` - ${xmlEscape(message.message || "")}`;
53
+ output += (message.ruleId ? ` (${message.ruleId})` : "");
54
+ output += "]]>";
55
+ output += `</${type}>`;
56
+ output += "</testcase>\n";
57
+ });
58
+ output += "</testsuite>\n";
59
+ } else {
60
+ output += `<testsuite package="org.eslint" time="0" tests="1" errors="0" name="${result.filePath}">\n`;
61
+ output += `<testcase time="0" name="${result.filePath}" />\n`;
62
+ output += "</testsuite>\n";
63
+ }
58
64
 
59
65
  });
60
66
 
@@ -63,9 +63,11 @@ module.exports = function(results) {
63
63
  }
64
64
  };
65
65
 
66
- // If we have multiple messages place them under a messages key
67
- // The first error will be logged as message key
68
- // This is to adhere to TAP 13 loosely defined specification of having a message key
66
+ /*
67
+ * If we have multiple messages place them under a messages key
68
+ * The first error will be logged as message key
69
+ * This is to adhere to TAP 13 loosely defined specification of having a message key
70
+ */
69
71
  if ("message" in diagnostics) {
70
72
  if (typeof diagnostics.messages === "undefined") {
71
73
  diagnostics.messages = [];
@@ -114,8 +114,10 @@ class IgnoredPaths {
114
114
  default: ignore()
115
115
  };
116
116
 
117
- // Add a way to keep track of ignored files. This was present in node-ignore
118
- // 2.x, but dropped for now as of 3.0.10.
117
+ /*
118
+ * Add a way to keep track of ignored files. This was present in node-ignore
119
+ * 2.x, but dropped for now as of 3.0.10.
120
+ */
119
121
  this.ig.custom.ignoreFiles = [];
120
122
  this.ig.default.ignoreFiles = [];
121
123
 
package/lib/linter.js CHANGED
@@ -111,8 +111,10 @@ function parseJsonConfig(string, location) {
111
111
  // ignore to parse the string by a fallback.
112
112
  }
113
113
 
114
- // Optionator cannot parse commaless notations.
115
- // But we are supporting that. So this is a fallback for that.
114
+ /*
115
+ * Optionator cannot parse commaless notations.
116
+ * But we are supporting that. So this is a fallback for that.
117
+ */
116
118
  items = {};
117
119
  string = string.replace(/([a-zA-Z0-9\-/]+):/g, "\"$1\":").replace(/(]|[0-9])\s+(?=")/, "$1,");
118
120
  try {
@@ -276,7 +278,7 @@ function createDisableDirectives(type, loc, value) {
276
278
  * @param {string} filename The file being checked.
277
279
  * @param {ASTNode} ast The top node of the AST.
278
280
  * @param {Object} config The existing configuration data.
279
- * @param {Linter} linterContext Linter context object
281
+ * @param {function(string): {create: Function}} ruleMapper A map from rule IDs to defined rules
280
282
  * @returns {{
281
283
  * config: Object,
282
284
  * problems: Problem[],
@@ -289,7 +291,7 @@ function createDisableDirectives(type, loc, value) {
289
291
  * }} Modified config object, along with any problems encountered
290
292
  * while parsing config comments
291
293
  */
292
- function modifyConfigsFromComments(filename, ast, config, linterContext) {
294
+ function modifyConfigsFromComments(filename, ast, config, ruleMapper) {
293
295
 
294
296
  const commentConfig = {
295
297
  exported: {},
@@ -335,7 +337,7 @@ function modifyConfigsFromComments(filename, ast, config, linterContext) {
335
337
  Object.keys(parseResult.config).forEach(name => {
336
338
  const ruleValue = parseResult.config[name];
337
339
 
338
- validator.validateRuleOptions(name, ruleValue, `${filename} line ${comment.loc.start.line}`, linterContext.rules);
340
+ validator.validateRuleOptions(ruleMapper(name), name, ruleValue, `${filename} line ${comment.loc.start.line}`);
339
341
  commentRules[name] = ruleValue;
340
342
  });
341
343
  } else {
@@ -379,8 +381,10 @@ function normalizeEcmaVersion(ecmaVersion, isModule) {
379
381
  ecmaVersion = 6;
380
382
  }
381
383
 
382
- // Calculate ECMAScript edition number from official year version starting with
383
- // ES2015, which corresponds with ES6 (or a difference of 2009).
384
+ /*
385
+ * Calculate ECMAScript edition number from official year version starting with
386
+ * ES2015, which corresponds with ES6 (or a difference of 2009).
387
+ */
384
388
  if (ecmaVersion >= 2015) {
385
389
  ecmaVersion -= 2009;
386
390
  }
@@ -802,7 +806,7 @@ module.exports = class Linter {
802
806
 
803
807
  // parse global comments and modify config
804
808
  if (allowInlineConfig !== false) {
805
- const modifyConfigResult = modifyConfigsFromComments(filename, sourceCode.ast, config, this);
809
+ const modifyConfigResult = modifyConfigsFromComments(filename, sourceCode.ast, config, ruleId => this.rules.get(ruleId));
806
810
 
807
811
  config = modifyConfigResult.config;
808
812
  modifyConfigResult.problems.forEach(problem => problems.push(problem));
@@ -1076,8 +1080,10 @@ module.exports = class Linter {
1076
1080
  debug(`Generating fixed text for ${debugTextDescription} (pass ${passNumber})`);
1077
1081
  fixedResult = SourceCodeFixer.applyFixes(text, messages, shouldFix);
1078
1082
 
1079
- // stop if there are any syntax errors.
1080
- // 'fixedResult.output' is a empty string.
1083
+ /*
1084
+ * stop if there are any syntax errors.
1085
+ * 'fixedResult.output' is a empty string.
1086
+ */
1081
1087
  if (messages.length === 1 && messages[0].fatal) {
1082
1088
  break;
1083
1089
  }
@@ -1,3 +1,3 @@
1
1
  rules:
2
- internal-no-invalid-meta: "error"
3
- internal-consistent-docs-description: "error"
2
+ rulesdir/no-invalid-meta: "error"
3
+ rulesdir/consistent-docs-description: "error"
@@ -96,11 +96,11 @@ module.exports = {
96
96
  }
97
97
 
98
98
  /**
99
- * Reports that there shouldn't be a linebreak after the first token
100
- * @param {ASTNode} node - The node to report in the event of an error.
101
- * @param {Token} token - The token to use for the report.
102
- * @returns {void}
103
- */
99
+ * Reports that there shouldn't be a linebreak after the first token
100
+ * @param {ASTNode} node - The node to report in the event of an error.
101
+ * @param {Token} token - The token to use for the report.
102
+ * @returns {void}
103
+ */
104
104
  function reportNoBeginningLinebreak(node, token) {
105
105
  context.report({
106
106
  node,
@@ -119,11 +119,11 @@ module.exports = {
119
119
  }
120
120
 
121
121
  /**
122
- * Reports that there shouldn't be a linebreak before the last token
123
- * @param {ASTNode} node - The node to report in the event of an error.
124
- * @param {Token} token - The token to use for the report.
125
- * @returns {void}
126
- */
122
+ * Reports that there shouldn't be a linebreak before the last token
123
+ * @param {ASTNode} node - The node to report in the event of an error.
124
+ * @param {Token} token - The token to use for the report.
125
+ * @returns {void}
126
+ */
127
127
  function reportNoEndingLinebreak(node, token) {
128
128
  context.report({
129
129
  node,
@@ -142,11 +142,11 @@ module.exports = {
142
142
  }
143
143
 
144
144
  /**
145
- * Reports that there should be a linebreak after the first token
146
- * @param {ASTNode} node - The node to report in the event of an error.
147
- * @param {Token} token - The token to use for the report.
148
- * @returns {void}
149
- */
145
+ * Reports that there should be a linebreak after the first token
146
+ * @param {ASTNode} node - The node to report in the event of an error.
147
+ * @param {Token} token - The token to use for the report.
148
+ * @returns {void}
149
+ */
150
150
  function reportRequiredBeginningLinebreak(node, token) {
151
151
  context.report({
152
152
  node,
@@ -159,11 +159,11 @@ module.exports = {
159
159
  }
160
160
 
161
161
  /**
162
- * Reports that there should be a linebreak before the last token
163
- * @param {ASTNode} node - The node to report in the event of an error.
164
- * @param {Token} token - The token to use for the report.
165
- * @returns {void}
166
- */
162
+ * Reports that there should be a linebreak before the last token
163
+ * @param {ASTNode} node - The node to report in the event of an error.
164
+ * @param {Token} token - The token to use for the report.
165
+ * @returns {void}
166
+ */
167
167
  function reportRequiredEndingLinebreak(node, token) {
168
168
  context.report({
169
169
  node,