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.
- package/CHANGELOG.md +36 -22
- package/conf/default-cli-options.js +5 -3
- package/lib/ast-utils.js +81 -41
- package/lib/cli-engine.js +27 -12
- package/lib/code-path-analysis/code-path-analyzer.js +8 -4
- package/lib/code-path-analysis/code-path-segment.js +4 -2
- package/lib/code-path-analysis/code-path-state.js +4 -2
- package/lib/config/autoconfig.js +14 -12
- package/lib/config/config-file.js +8 -51
- package/lib/config/config-initializer.js +10 -6
- package/lib/config/config-ops.js +21 -21
- package/lib/config/config-rule.js +24 -24
- package/lib/config/config-validator.js +38 -36
- package/lib/config/plugins.js +8 -35
- package/lib/config.js +12 -8
- package/lib/formatters/junit.js +21 -15
- package/lib/formatters/tap.js +5 -3
- package/lib/ignored-paths.js +4 -2
- package/lib/linter.js +16 -10
- package/lib/rules/.eslintrc.yml +2 -2
- package/lib/rules/array-bracket-newline.js +20 -20
- package/lib/rules/array-bracket-spacing.js +28 -28
- package/lib/rules/array-callback-return.js +13 -9
- package/lib/rules/array-element-newline.js +8 -8
- package/lib/rules/arrow-body-style.js +12 -6
- package/lib/rules/arrow-parens.js +4 -2
- package/lib/rules/brace-style.js +14 -14
- package/lib/rules/computed-property-spacing.js +22 -22
- package/lib/rules/consistent-return.js +4 -4
- package/lib/rules/consistent-this.js +4 -2
- package/lib/rules/curly.js +13 -9
- package/lib/rules/dot-notation.js +5 -5
- package/lib/rules/func-call-spacing.js +4 -2
- package/lib/rules/getter-return.js +2 -1
- package/lib/rules/indent-legacy.js +20 -12
- package/lib/rules/indent.js +77 -73
- package/lib/rules/key-spacing.js +5 -3
- package/lib/rules/lines-around-directive.js +16 -12
- package/lib/rules/max-statements-per-line.js +5 -3
- package/lib/rules/newline-after-var.js +8 -6
- package/lib/rules/newline-before-return.js +9 -7
- package/lib/rules/no-await-in-loop.js +17 -9
- package/lib/rules/no-bitwise.js +5 -3
- package/lib/rules/no-catch-shadow.js +4 -2
- package/lib/rules/no-console.js +2 -1
- package/lib/rules/no-else-return.js +17 -11
- package/lib/rules/no-empty-character-class.js +11 -11
- package/lib/rules/no-extra-parens.js +16 -8
- package/lib/rules/no-extra-semi.js +5 -3
- package/lib/rules/no-global-assign.js +4 -2
- package/lib/rules/no-implicit-coercion.js +6 -6
- package/lib/rules/no-implied-eval.js +2 -1
- package/lib/rules/no-label-var.js +4 -2
- package/lib/rules/no-lone-blocks.js +3 -3
- package/lib/rules/no-loop-func.js +8 -4
- package/lib/rules/no-native-reassign.js +4 -2
- package/lib/rules/no-param-reassign.js +4 -2
- package/lib/rules/no-regex-spaces.js +1 -1
- package/lib/rules/no-restricted-properties.js +10 -10
- package/lib/rules/no-return-await.js +6 -6
- package/lib/rules/no-self-assign.js +4 -2
- package/lib/rules/no-sequences.js +6 -4
- package/lib/rules/no-trailing-spaces.js +13 -7
- package/lib/rules/no-unreachable.js +4 -2
- package/lib/rules/no-use-before-define.js +13 -11
- package/lib/rules/no-useless-call.js +1 -25
- package/lib/rules/no-useless-escape.js +23 -22
- package/lib/rules/no-useless-return.js +14 -8
- package/lib/rules/no-whitespace-before-property.js +4 -2
- package/lib/rules/object-curly-newline.js +9 -2
- package/lib/rules/object-curly-spacing.js +20 -20
- package/lib/rules/object-shorthand.js +41 -33
- package/lib/rules/operator-assignment.js +9 -9
- package/lib/rules/operator-linebreak.js +12 -10
- package/lib/rules/padding-line-between-statements.js +4 -2
- package/lib/rules/prefer-arrow-callback.js +12 -10
- package/lib/rules/prefer-const.js +18 -10
- package/lib/rules/prefer-destructuring.js +4 -2
- package/lib/rules/prefer-numeric-literals.js +4 -2
- package/lib/rules/prefer-promise-reject-errors.js +16 -16
- package/lib/rules/prefer-rest-params.js +4 -2
- package/lib/rules/prefer-spread.js +1 -25
- package/lib/rules/prefer-template.js +33 -29
- package/lib/rules/quote-props.js +8 -8
- package/lib/rules/semi-style.js +44 -19
- package/lib/rules/semi.js +5 -3
- package/lib/rules/sort-imports.js +5 -3
- package/lib/rules/space-unary-ops.js +61 -61
- package/lib/rules/strict.js +8 -8
- package/lib/rules/valid-typeof.js +4 -4
- package/lib/rules/wrap-iife.js +4 -4
- package/lib/rules/yoda.js +9 -7
- package/lib/testers/rule-tester.js +43 -34
- package/lib/token-store/backward-token-cursor.js +5 -3
- package/lib/token-store/forward-token-cursor.js +5 -3
- package/lib/token-store/utils.js +8 -4
- package/lib/util/glob.js +1 -1
- package/lib/util/naming.js +112 -0
- package/lib/util/node-event-generator.js +10 -10
- package/lib/util/safe-emitter.js +1 -1
- package/lib/util/source-code-fixer.js +4 -2
- package/lib/util/source-code.js +2 -1
- package/package.json +6 -5
@@ -187,19 +187,19 @@ class RuleConfigSet {
|
|
187
187
|
constructor(configs) {
|
188
188
|
|
189
189
|
/**
|
190
|
-
|
191
|
-
|
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
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
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
|
-
|
217
|
-
|
218
|
-
|
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
|
-
|
226
|
-
|
227
|
-
|
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
|
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 {
|
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(
|
33
|
-
const
|
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 {
|
76
|
-
* @param {array} localOptions The options for the rule, excluding severity
|
77
|
-
* @
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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 =
|
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(
|
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 {
|
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(
|
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(
|
112
|
+
validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
|
111
113
|
}
|
112
114
|
} catch (err) {
|
113
|
-
throw new Error(`${source}:\n\tConfiguration for rule "${
|
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 {
|
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,
|
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
|
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 {
|
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,
|
230
|
+
function validate(config, source, ruleMapper, envContext) {
|
229
231
|
validateConfigSchema(config, source);
|
230
|
-
validateRules(config.rules, source,
|
232
|
+
validateRules(config.rules, source, ruleMapper);
|
231
233
|
validateEnvironment(config.env, source, envContext);
|
232
234
|
}
|
233
235
|
|
package/lib/config/plugins.js
CHANGED
@@ -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 =
|
75
|
-
pluginNameWithoutNamespace =
|
76
|
-
pluginNameWithoutPrefix =
|
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 =
|
110
|
-
pluginNameWithoutNamespace =
|
111
|
-
pluginNameWithoutPrefix =
|
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
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
220
|
-
|
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
|
-
|
347
|
-
|
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
|
}
|
package/lib/formatters/junit.js
CHANGED
@@ -39,22 +39,28 @@ module.exports = function(results) {
|
|
39
39
|
|
40
40
|
const messages = result.messages;
|
41
41
|
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
|
package/lib/formatters/tap.js
CHANGED
@@ -63,9 +63,11 @@ module.exports = function(results) {
|
|
63
63
|
}
|
64
64
|
};
|
65
65
|
|
66
|
-
|
67
|
-
|
68
|
-
|
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 = [];
|
package/lib/ignored-paths.js
CHANGED
@@ -114,8 +114,10 @@ class IgnoredPaths {
|
|
114
114
|
default: ignore()
|
115
115
|
};
|
116
116
|
|
117
|
-
|
118
|
-
|
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
|
-
|
115
|
-
|
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 {
|
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,
|
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}
|
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
|
-
|
383
|
-
|
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
|
-
|
1080
|
-
|
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
|
}
|
package/lib/rules/.eslintrc.yml
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
rules:
|
2
|
-
|
3
|
-
|
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
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
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
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
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
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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,
|