eslint 8.5.0 → 8.9.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/README.md +6 -6
- package/bin/eslint.js +7 -1
- package/lib/cli-engine/cli-engine.js +10 -1
- package/lib/config/flat-config-array.js +5 -1
- package/lib/config/flat-config-helpers.js +37 -1
- package/lib/config/rule-validator.js +5 -35
- package/lib/eslint/eslint.js +6 -0
- package/lib/linter/apply-disable-directives.js +55 -60
- package/lib/linter/linter.js +90 -27
- package/lib/rule-tester/flat-rule-tester.js +1039 -0
- package/lib/rule-tester/rule-tester.js +5 -5
- package/lib/rules/camelcase.js +7 -1
- package/lib/rules/function-paren-newline.js +5 -1
- package/lib/rules/id-match.js +12 -1
- package/lib/rules/keyword-spacing.js +32 -0
- package/lib/rules/no-constant-condition.js +23 -4
- package/lib/rules/no-invalid-this.js +50 -53
- package/lib/rules/no-restricted-exports.js +9 -3
- package/lib/rules/no-restricted-imports.js +24 -7
- package/lib/rules/no-restricted-modules.js +2 -1
- package/lib/rules/no-self-assign.js +1 -1
- package/lib/rules/no-useless-rename.js +8 -4
- package/lib/rules/quotes.js +12 -1
- package/lib/rules/utils/ast-utils.js +21 -1
- package/lib/shared/types.js +15 -0
- package/messages/no-config-found.js +1 -1
- package/package.json +9 -9
- package/lib/init/autoconfig.js +0 -351
- package/lib/init/config-file.js +0 -144
- package/lib/init/config-initializer.js +0 -709
- package/lib/init/config-rule.js +0 -316
- package/lib/init/npm-utils.js +0 -179
- package/lib/init/source-code-utils.js +0 -110
package/README.md
CHANGED
@@ -48,24 +48,24 @@ Prerequisites: [Node.js](https://nodejs.org/) (`^12.22.0`, `^14.17.0`, or `>=16.
|
|
48
48
|
You can install ESLint using npm:
|
49
49
|
|
50
50
|
```sh
|
51
|
-
|
51
|
+
npm install eslint --save-dev
|
52
52
|
```
|
53
53
|
|
54
54
|
You should then set up a configuration file:
|
55
55
|
|
56
56
|
```sh
|
57
|
-
|
57
|
+
npm init @eslint/config
|
58
58
|
```
|
59
59
|
|
60
60
|
After that, you can run ESLint on any file or directory like this:
|
61
61
|
|
62
62
|
```sh
|
63
|
-
|
63
|
+
./node_modules/.bin/eslint yourfile.js
|
64
64
|
```
|
65
65
|
|
66
66
|
## <a name="configuration"></a>Configuration
|
67
67
|
|
68
|
-
After running `
|
68
|
+
After running `npm init @eslint/config`, you'll have a `.eslintrc` file in your directory. In it, you'll see some rules configured like this:
|
69
69
|
|
70
70
|
```json
|
71
71
|
{
|
@@ -292,9 +292,9 @@ The following companies, organizations, and individuals support ESLint's ongoing
|
|
292
292
|
<!--sponsorsstart-->
|
293
293
|
<h3>Platinum Sponsors</h3>
|
294
294
|
<p><a href="https://automattic.com"><img src="https://images.opencollective.com/automattic/d0ef3e1/logo.png" alt="Automattic" height="undefined"></a></p><h3>Gold Sponsors</h3>
|
295
|
-
<p><a href="https://contra.com"><img src="https://images.opencollective.com/contra1/c70f93f/logo.png" alt="Contra" height="96"></a> <a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="96"></a> <a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://
|
295
|
+
<p><a href="https://contra.com"><img src="https://images.opencollective.com/contra1/c70f93f/logo.png" alt="Contra" height="96"></a> <a href="https://nx.dev"><img src="https://images.opencollective.com/nx/0efbe42/logo.png" alt="Nx (by Nrwl)" height="96"></a> <a href="https://google.com/chrome"><img src="https://images.opencollective.com/chrome/dc55bd4/logo.png" alt="Chrome's Web Framework & Tools Performance Fund" height="96"></a> <a href="https://www.salesforce.com"><img src="https://images.opencollective.com/salesforce/ca8f997/logo.png" alt="Salesforce" height="96"></a> <a href="https://www.airbnb.com/"><img src="https://images.opencollective.com/airbnb/d327d66/logo.png" alt="Airbnb" height="96"></a> <a href="https://americanexpress.io"><img src="https://avatars.githubusercontent.com/u/3853301?v=4" alt="American Express" height="96"></a> <a href="https://substack.com/"><img src="https://avatars.githubusercontent.com/u/53023767?v=4" alt="Substack" height="96"></a></p><h3>Silver Sponsors</h3>
|
296
296
|
<p><a href="https://liftoff.io/"><img src="https://images.opencollective.com/liftoff/5c4fa84/logo.png" alt="Liftoff" height="64"></a></p><h3>Bronze Sponsors</h3>
|
297
|
-
<p><a href="https://
|
297
|
+
<p><a href="https://launchdarkly.com"><img src="https://images.opencollective.com/launchdarkly/574bb9e/logo.png" alt="launchdarkly" height="32"></a> <a href="https://www.crosswordsolver.org/anagram-solver/"><img src="https://images.opencollective.com/anagram-solver/2666271/logo.png" alt="Anagram Solver" height="32"></a> <a href="https://www.vpsserver.com"><img src="https://images.opencollective.com/vpsservercom/logo.png" alt="VPS Server" height="32"></a> <a href="https://icons8.com"><img src="https://images.opencollective.com/icons8/7fa1641/logo.png" alt="Icons8: free icons, photos, illustrations, and music" height="32"></a> <a href="https://discord.com"><img src="https://images.opencollective.com/discordapp/f9645d9/logo.png" alt="Discord" height="32"></a> <a href="https://themeisle.com"><img src="https://images.opencollective.com/themeisle/d5592fe/logo.png" alt="ThemeIsle" height="32"></a> <a href="https://www.practiceignition.com"><img src="https://avatars.githubusercontent.com/u/5753491?v=4" alt="Practice Ignition" height="32"></a></p>
|
298
298
|
<!--sponsorsend-->
|
299
299
|
|
300
300
|
## <a name="technology-sponsors"></a>Technology Sponsors
|
package/bin/eslint.js
CHANGED
@@ -124,7 +124,13 @@ ${message}`);
|
|
124
124
|
|
125
125
|
// Call the config initializer if `--init` is present.
|
126
126
|
if (process.argv.includes("--init")) {
|
127
|
-
|
127
|
+
|
128
|
+
// `eslint --init` has been moved to `@eslint/create-config`
|
129
|
+
console.warn("You can also run this command directly using 'npm init @eslint/config'.");
|
130
|
+
|
131
|
+
const spawn = require("cross-spawn");
|
132
|
+
|
133
|
+
spawn.sync("npm", ["init", "@eslint/config"], { encoding: "utf8", stdio: "inherit" });
|
128
134
|
return;
|
129
135
|
}
|
130
136
|
|
@@ -51,6 +51,7 @@ const validFixTypes = new Set(["directive", "problem", "suggestion", "layout"]);
|
|
51
51
|
/** @typedef {import("../shared/types").ConfigData} ConfigData */
|
52
52
|
/** @typedef {import("../shared/types").DeprecatedRuleInfo} DeprecatedRuleInfo */
|
53
53
|
/** @typedef {import("../shared/types").LintMessage} LintMessage */
|
54
|
+
/** @typedef {import("../shared/types").SuppressedLintMessage} SuppressedLintMessage */
|
54
55
|
/** @typedef {import("../shared/types").ParserOptions} ParserOptions */
|
55
56
|
/** @typedef {import("../shared/types").Plugin} Plugin */
|
56
57
|
/** @typedef {import("../shared/types").RuleConf} RuleConf */
|
@@ -91,7 +92,9 @@ const validFixTypes = new Set(["directive", "problem", "suggestion", "layout"]);
|
|
91
92
|
* @typedef {Object} LintResult
|
92
93
|
* @property {string} filePath The path to the file that was linted.
|
93
94
|
* @property {LintMessage[]} messages All of the messages for the result.
|
95
|
+
* @property {SuppressedLintMessage[]} suppressedMessages All of the suppressed messages for the result.
|
94
96
|
* @property {number} errorCount Number of errors for the result.
|
97
|
+
* @property {number} fatalErrorCount Number of fatal errors for the result.
|
95
98
|
* @property {number} warningCount Number of warnings for the result.
|
96
99
|
* @property {number} fixableErrorCount Number of fixable errors for the result.
|
97
100
|
* @property {number} fixableWarningCount Number of fixable warnings for the result.
|
@@ -104,6 +107,7 @@ const validFixTypes = new Set(["directive", "problem", "suggestion", "layout"]);
|
|
104
107
|
* @typedef {Object} LintReport
|
105
108
|
* @property {LintResult[]} results All of the result.
|
106
109
|
* @property {number} errorCount Number of errors for the result.
|
110
|
+
* @property {number} fatalErrorCount Number of fatal errors for the result.
|
107
111
|
* @property {number} warningCount Number of warnings for the result.
|
108
112
|
* @property {number} fixableErrorCount Number of fixable errors for the result.
|
109
113
|
* @property {number} fixableWarningCount Number of fixable warnings for the result.
|
@@ -261,6 +265,7 @@ function verifyText({
|
|
261
265
|
const result = {
|
262
266
|
filePath,
|
263
267
|
messages,
|
268
|
+
suppressedMessages: linter.getSuppressedMessages(),
|
264
269
|
...calculateStatsPerFile(messages)
|
265
270
|
};
|
266
271
|
|
@@ -307,7 +312,9 @@ function createIgnoreResult(filePath, baseDir) {
|
|
307
312
|
message
|
308
313
|
}
|
309
314
|
],
|
315
|
+
suppressedMessages: [],
|
310
316
|
errorCount: 0,
|
317
|
+
fatalErrorCount: 0,
|
311
318
|
warningCount: 1,
|
312
319
|
fixableErrorCount: 0,
|
313
320
|
fixableWarningCount: 0
|
@@ -408,7 +415,7 @@ function isErrorMessage(message) {
|
|
408
415
|
* a directory or looks like a directory (ends in `path.sep`), in which case the file
|
409
416
|
* name will be the `cacheFile/.cache_hashOfCWD`
|
410
417
|
*
|
411
|
-
* if cacheFile points to a file or looks like a file then
|
418
|
+
* if cacheFile points to a file or looks like a file then it will just use that file
|
412
419
|
* @param {string} cacheFile The name of file to be used to store the cache
|
413
420
|
* @param {string} cwd Current working directory
|
414
421
|
* @returns {string} the resolved path to the cache file
|
@@ -680,11 +687,13 @@ class CLIEngine {
|
|
680
687
|
|
681
688
|
results.forEach(result => {
|
682
689
|
const filteredMessages = result.messages.filter(isErrorMessage);
|
690
|
+
const filteredSuppressedMessages = result.suppressedMessages.filter(isErrorMessage);
|
683
691
|
|
684
692
|
if (filteredMessages.length > 0) {
|
685
693
|
filtered.push({
|
686
694
|
...result,
|
687
695
|
messages: filteredMessages,
|
696
|
+
suppressedMessages: filteredSuppressedMessages,
|
688
697
|
errorCount: filteredMessages.length,
|
689
698
|
warningCount: 0,
|
690
699
|
fixableErrorCount: result.fixableErrorCount,
|
@@ -58,7 +58,11 @@ class FlatConfigArray extends ConfigArray {
|
|
58
58
|
schema: flatConfigSchema
|
59
59
|
});
|
60
60
|
|
61
|
-
|
61
|
+
if (baseConfig[Symbol.iterator]) {
|
62
|
+
this.unshift(...baseConfig);
|
63
|
+
} else {
|
64
|
+
this.unshift(baseConfig);
|
65
|
+
}
|
62
66
|
}
|
63
67
|
|
64
68
|
/* eslint-disable class-methods-use-this -- Desired as instance method */
|
@@ -57,11 +57,47 @@ function getRuleFromConfig(ruleId, config) {
|
|
57
57
|
return rule;
|
58
58
|
}
|
59
59
|
|
60
|
+
/**
|
61
|
+
* Gets a complete options schema for a rule.
|
62
|
+
* @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
|
63
|
+
* @returns {Object} JSON Schema for the rule's options.
|
64
|
+
*/
|
65
|
+
function getRuleOptionsSchema(rule) {
|
66
|
+
|
67
|
+
if (!rule) {
|
68
|
+
return null;
|
69
|
+
}
|
70
|
+
|
71
|
+
const schema = rule.schema || rule.meta && rule.meta.schema;
|
72
|
+
|
73
|
+
if (Array.isArray(schema)) {
|
74
|
+
if (schema.length) {
|
75
|
+
return {
|
76
|
+
type: "array",
|
77
|
+
items: schema,
|
78
|
+
minItems: 0,
|
79
|
+
maxItems: schema.length
|
80
|
+
};
|
81
|
+
}
|
82
|
+
return {
|
83
|
+
type: "array",
|
84
|
+
minItems: 0,
|
85
|
+
maxItems: 0
|
86
|
+
};
|
87
|
+
|
88
|
+
}
|
89
|
+
|
90
|
+
// Given a full schema, leave it alone
|
91
|
+
return schema || null;
|
92
|
+
}
|
93
|
+
|
94
|
+
|
60
95
|
//-----------------------------------------------------------------------------
|
61
96
|
// Exports
|
62
97
|
//-----------------------------------------------------------------------------
|
63
98
|
|
64
99
|
module.exports = {
|
65
100
|
parseRuleId,
|
66
|
-
getRuleFromConfig
|
101
|
+
getRuleFromConfig,
|
102
|
+
getRuleOptionsSchema
|
67
103
|
};
|
@@ -10,7 +10,11 @@
|
|
10
10
|
//-----------------------------------------------------------------------------
|
11
11
|
|
12
12
|
const ajv = require("../shared/ajv")();
|
13
|
-
const {
|
13
|
+
const {
|
14
|
+
parseRuleId,
|
15
|
+
getRuleFromConfig,
|
16
|
+
getRuleOptionsSchema
|
17
|
+
} = require("./flat-config-helpers");
|
14
18
|
const ruleReplacements = require("../../conf/replacements.json");
|
15
19
|
|
16
20
|
//-----------------------------------------------------------------------------
|
@@ -61,40 +65,6 @@ function throwRuleNotFoundError({ pluginName, ruleName }, config) {
|
|
61
65
|
throw new TypeError(errorMessage);
|
62
66
|
}
|
63
67
|
|
64
|
-
/**
|
65
|
-
* Gets a complete options schema for a rule.
|
66
|
-
* @param {{create: Function, schema: (Array|null)}} rule A new-style rule object
|
67
|
-
* @returns {Object} JSON Schema for the rule's options.
|
68
|
-
*/
|
69
|
-
function getRuleOptionsSchema(rule) {
|
70
|
-
|
71
|
-
if (!rule) {
|
72
|
-
return null;
|
73
|
-
}
|
74
|
-
|
75
|
-
const schema = rule.schema || rule.meta && rule.meta.schema;
|
76
|
-
|
77
|
-
if (Array.isArray(schema)) {
|
78
|
-
if (schema.length) {
|
79
|
-
return {
|
80
|
-
type: "array",
|
81
|
-
items: schema,
|
82
|
-
minItems: 0,
|
83
|
-
maxItems: schema.length
|
84
|
-
};
|
85
|
-
}
|
86
|
-
return {
|
87
|
-
type: "array",
|
88
|
-
minItems: 0,
|
89
|
-
maxItems: 0
|
90
|
-
};
|
91
|
-
|
92
|
-
}
|
93
|
-
|
94
|
-
// Given a full schema, leave it alone
|
95
|
-
return schema || null;
|
96
|
-
}
|
97
|
-
|
98
68
|
//-----------------------------------------------------------------------------
|
99
69
|
// Exports
|
100
70
|
//-----------------------------------------------------------------------------
|
package/lib/eslint/eslint.js
CHANGED
@@ -32,6 +32,7 @@ const { version } = require("../../package.json");
|
|
32
32
|
/** @typedef {import("../shared/types").DeprecatedRuleInfo} DeprecatedRuleInfo */
|
33
33
|
/** @typedef {import("../shared/types").ConfigData} ConfigData */
|
34
34
|
/** @typedef {import("../shared/types").LintMessage} LintMessage */
|
35
|
+
/** @typedef {import("../shared/types").SuppressedLintMessage} SuppressedLintMessage */
|
35
36
|
/** @typedef {import("../shared/types").Plugin} Plugin */
|
36
37
|
/** @typedef {import("../shared/types").Rule} Rule */
|
37
38
|
|
@@ -78,7 +79,9 @@ const { version } = require("../../package.json");
|
|
78
79
|
* @typedef {Object} LintResult
|
79
80
|
* @property {string} filePath The path to the file that was linted.
|
80
81
|
* @property {LintMessage[]} messages All of the messages for the result.
|
82
|
+
* @property {SuppressedLintMessage[]} suppressedMessages All of the suppressed messages for the result.
|
81
83
|
* @property {number} errorCount Number of errors for the result.
|
84
|
+
* @property {number} fatalErrorCount Number of fatal errors for the result.
|
82
85
|
* @property {number} warningCount Number of warnings for the result.
|
83
86
|
* @property {number} fixableErrorCount Number of fixable errors for the result.
|
84
87
|
* @property {number} fixableWarningCount Number of fixable warnings for the result.
|
@@ -525,6 +528,9 @@ class ESLint {
|
|
525
528
|
for (const { ruleId } of result.messages) {
|
526
529
|
resultRuleIds.add(ruleId);
|
527
530
|
}
|
531
|
+
for (const { ruleId } of result.suppressedMessages) {
|
532
|
+
resultRuleIds.add(ruleId);
|
533
|
+
}
|
528
534
|
}
|
529
535
|
|
530
536
|
// create a map of all rules in the results
|
@@ -43,7 +43,7 @@ function groupByParentComment(directives) {
|
|
43
43
|
* Creates removal details for a set of directives within the same comment.
|
44
44
|
* @param {Directive[]} directives Unused directives to be removed.
|
45
45
|
* @param {Token} commentToken The backing Comment token.
|
46
|
-
* @returns {{ description, fix,
|
46
|
+
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
|
47
47
|
*/
|
48
48
|
function createIndividualDirectivesRemoval(directives, commentToken) {
|
49
49
|
|
@@ -138,7 +138,7 @@ function createIndividualDirectivesRemoval(directives, commentToken) {
|
|
138
138
|
],
|
139
139
|
text: ""
|
140
140
|
},
|
141
|
-
|
141
|
+
unprocessedDirective: directive.unprocessedDirective
|
142
142
|
};
|
143
143
|
});
|
144
144
|
}
|
@@ -147,7 +147,7 @@ function createIndividualDirectivesRemoval(directives, commentToken) {
|
|
147
147
|
* Creates a description of deleting an entire unused disable comment.
|
148
148
|
* @param {Directive[]} directives Unused directives to be removed.
|
149
149
|
* @param {Token} commentToken The backing Comment token.
|
150
|
-
* @returns {{ description, fix,
|
150
|
+
* @returns {{ description, fix, unprocessedDirective }} Details for later creation of an output Problem.
|
151
151
|
*/
|
152
152
|
function createCommentRemoval(directives, commentToken) {
|
153
153
|
const { range } = commentToken;
|
@@ -161,14 +161,14 @@ function createCommentRemoval(directives, commentToken) {
|
|
161
161
|
range,
|
162
162
|
text: " "
|
163
163
|
},
|
164
|
-
|
164
|
+
unprocessedDirective: directives[0].unprocessedDirective
|
165
165
|
};
|
166
166
|
}
|
167
167
|
|
168
168
|
/**
|
169
169
|
* Parses details from directives to create output Problems.
|
170
170
|
* @param {Directive[]} allDirectives Unused directives to be removed.
|
171
|
-
* @returns {{ description, fix,
|
171
|
+
* @returns {{ description, fix, unprocessedDirective }[]} Details for later creation of output Problems.
|
172
172
|
*/
|
173
173
|
function processUnusedDisableDirectives(allDirectives) {
|
174
174
|
const directiveGroups = groupByParentComment(allDirectives);
|
@@ -197,62 +197,52 @@ function processUnusedDisableDirectives(allDirectives) {
|
|
197
197
|
* for the exported function, except that `reportUnusedDisableDirectives` is not supported
|
198
198
|
* (this function always reports unused disable directives).
|
199
199
|
* @returns {{problems: Problem[], unusedDisableDirectives: Problem[]}} An object with a list
|
200
|
-
* of
|
200
|
+
* of problems (including suppressed ones) and unused eslint-disable directives
|
201
201
|
*/
|
202
202
|
function applyDirectives(options) {
|
203
203
|
const problems = [];
|
204
|
-
let nextDirectiveIndex = 0;
|
205
|
-
let currentGlobalDisableDirective = null;
|
206
|
-
const disabledRuleMap = new Map();
|
207
|
-
|
208
|
-
// enabledRules is only used when there is a current global disable directive.
|
209
|
-
const enabledRules = new Set();
|
210
204
|
const usedDisableDirectives = new Set();
|
211
205
|
|
212
206
|
for (const problem of options.problems) {
|
207
|
+
let disableDirectivesForProblem = [];
|
208
|
+
let nextDirectiveIndex = 0;
|
209
|
+
|
213
210
|
while (
|
214
211
|
nextDirectiveIndex < options.directives.length &&
|
215
212
|
compareLocations(options.directives[nextDirectiveIndex], problem) <= 0
|
216
213
|
) {
|
217
214
|
const directive = options.directives[nextDirectiveIndex++];
|
218
215
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
break;
|
232
|
-
|
233
|
-
case "enable":
|
234
|
-
if (directive.ruleId === null) {
|
235
|
-
currentGlobalDisableDirective = null;
|
236
|
-
disabledRuleMap.clear();
|
237
|
-
} else if (currentGlobalDisableDirective) {
|
238
|
-
enabledRules.add(directive.ruleId);
|
239
|
-
disabledRuleMap.delete(directive.ruleId);
|
240
|
-
} else {
|
241
|
-
disabledRuleMap.delete(directive.ruleId);
|
242
|
-
}
|
243
|
-
break;
|
244
|
-
|
245
|
-
// no default
|
216
|
+
if (directive.ruleId === null || directive.ruleId === problem.ruleId) {
|
217
|
+
switch (directive.type) {
|
218
|
+
case "disable":
|
219
|
+
disableDirectivesForProblem.push(directive);
|
220
|
+
break;
|
221
|
+
|
222
|
+
case "enable":
|
223
|
+
disableDirectivesForProblem = [];
|
224
|
+
break;
|
225
|
+
|
226
|
+
// no default
|
227
|
+
}
|
246
228
|
}
|
247
229
|
}
|
248
230
|
|
249
|
-
if (
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
231
|
+
if (disableDirectivesForProblem.length > 0) {
|
232
|
+
const suppressions = disableDirectivesForProblem.map(directive => ({
|
233
|
+
kind: "directive",
|
234
|
+
justification: directive.unprocessedDirective.justification
|
235
|
+
}));
|
236
|
+
|
237
|
+
if (problem.suppressions) {
|
238
|
+
problem.suppressions = problem.suppressions.concat(suppressions);
|
239
|
+
} else {
|
240
|
+
problem.suppressions = suppressions;
|
241
|
+
usedDisableDirectives.add(disableDirectivesForProblem[disableDirectivesForProblem.length - 1]);
|
242
|
+
}
|
255
243
|
}
|
244
|
+
|
245
|
+
problems.push(problem);
|
256
246
|
}
|
257
247
|
|
258
248
|
const unusedDisableDirectivesToReport = options.directives
|
@@ -261,30 +251,35 @@ function applyDirectives(options) {
|
|
261
251
|
const processed = processUnusedDisableDirectives(unusedDisableDirectivesToReport);
|
262
252
|
|
263
253
|
const unusedDisableDirectives = processed
|
264
|
-
.map(({ description, fix,
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
:
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
254
|
+
.map(({ description, fix, unprocessedDirective }) => {
|
255
|
+
const { parentComment, type, line, column } = unprocessedDirective;
|
256
|
+
|
257
|
+
return {
|
258
|
+
ruleId: null,
|
259
|
+
message: description
|
260
|
+
? `Unused eslint-disable directive (no problems were reported from ${description}).`
|
261
|
+
: "Unused eslint-disable directive (no problems were reported).",
|
262
|
+
line: type === "disable-next-line" ? parentComment.commentToken.loc.start.line : line,
|
263
|
+
column: type === "disable-next-line" ? parentComment.commentToken.loc.start.column + 1 : column,
|
264
|
+
severity: options.reportUnusedDisableDirectives === "warn" ? 1 : 2,
|
265
|
+
nodeType: null,
|
266
|
+
...options.disableFixes ? {} : { fix }
|
267
|
+
};
|
268
|
+
});
|
275
269
|
|
276
270
|
return { problems, unusedDisableDirectives };
|
277
271
|
}
|
278
272
|
|
279
273
|
/**
|
280
274
|
* Given a list of directive comments (i.e. metadata about eslint-disable and eslint-enable comments) and a list
|
281
|
-
* of reported problems,
|
275
|
+
* of reported problems, adds the suppression information to the problems.
|
282
276
|
* @param {Object} options Information about directives and problems
|
283
277
|
* @param {{
|
284
278
|
* type: ("disable"|"enable"|"disable-line"|"disable-next-line"),
|
285
279
|
* ruleId: (string|null),
|
286
280
|
* line: number,
|
287
|
-
* column: number
|
281
|
+
* column: number,
|
282
|
+
* justification: string
|
288
283
|
* }} options.directives Directive comments found in the file, with one-based columns.
|
289
284
|
* Two directive comments can only have the same location if they also have the same type (e.g. a single eslint-disable
|
290
285
|
* comment for two different rules is represented as two directives).
|
@@ -292,8 +287,8 @@ function applyDirectives(options) {
|
|
292
287
|
* A list of problems reported by rules, sorted by increasing location in the file, with one-based columns.
|
293
288
|
* @param {"off" | "warn" | "error"} options.reportUnusedDisableDirectives If `"warn"` or `"error"`, adds additional problems for unused directives
|
294
289
|
* @param {boolean} options.disableFixes If true, it doesn't make `fix` properties.
|
295
|
-
* @returns {{ruleId: (string|null), line: number, column: number}[]}
|
296
|
-
*
|
290
|
+
* @returns {{ruleId: (string|null), line: number, column: number, suppressions?: {kind: string, justification: string}}[]}
|
291
|
+
* An object with a list of reported problems, the suppressed of which contain the suppression information.
|
297
292
|
*/
|
298
293
|
module.exports = ({ directives, disableFixes, problems, reportUnusedDisableDirectives = "off" }) => {
|
299
294
|
const blockDirectives = directives
|