eslint 9.39.1 → 10.0.0-alpha.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 +3 -3
- package/bin/eslint.js +1 -2
- package/lib/api.js +4 -15
- package/lib/cli.js +14 -56
- package/lib/config/config-loader.js +6 -154
- package/lib/eslint/eslint-helpers.js +5 -8
- package/lib/eslint/eslint.js +1 -1
- package/lib/eslint/index.js +0 -2
- package/lib/languages/js/source-code/source-code.js +39 -87
- package/lib/languages/js/source-code/token-store/utils.js +29 -8
- package/lib/linter/apply-disable-directives.js +0 -1
- package/lib/linter/file-context.js +0 -56
- package/lib/linter/file-report.js +0 -4
- package/lib/linter/linter.js +45 -1086
- package/lib/linter/rule-fixer.js +30 -0
- package/lib/options.js +62 -182
- package/lib/rule-tester/rule-tester.js +255 -194
- package/lib/rules/dot-notation.js +2 -2
- package/lib/rules/func-names.js +2 -0
- package/lib/rules/no-eval.js +1 -1
- package/lib/rules/no-invalid-regexp.js +1 -0
- package/lib/rules/no-shadow-restricted-names.js +1 -1
- package/lib/rules/no-unassigned-vars.js +1 -1
- package/lib/rules/no-useless-assignment.js +1 -1
- package/lib/rules/preserve-caught-error.js +1 -1
- package/lib/rules/radix.js +25 -48
- package/lib/services/parser-service.js +0 -1
- package/lib/services/processor-service.js +0 -1
- package/lib/services/warning-service.js +0 -11
- package/lib/shared/flags.js +0 -19
- package/lib/shared/translate-cli-options.js +106 -164
- package/lib/types/index.d.ts +7 -60
- package/lib/types/rules.d.ts +11 -2
- package/lib/types/use-at-your-own-risk.d.ts +1 -54
- package/lib/unsupported-api.js +3 -6
- package/package.json +14 -19
- package/conf/default-cli-options.js +0 -32
- package/lib/cli-engine/cli-engine.js +0 -1109
- package/lib/cli-engine/file-enumerator.js +0 -541
- package/lib/cli-engine/index.js +0 -7
- package/lib/cli-engine/load-rules.js +0 -46
- package/lib/eslint/legacy-eslint.js +0 -786
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"use strict";
|
|
6
6
|
|
|
7
7
|
//------------------------------------------------------------------------------
|
|
8
|
-
//
|
|
8
|
+
// Helpers
|
|
9
9
|
//------------------------------------------------------------------------------
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* @param {number} location The location to search.
|
|
16
16
|
* @returns {number} The found index or `tokens.length`.
|
|
17
17
|
*/
|
|
18
|
-
|
|
18
|
+
function search(tokens, location) {
|
|
19
19
|
for (
|
|
20
20
|
let minIndex = 0, maxIndex = tokens.length - 1;
|
|
21
21
|
minIndex <= maxIndex;
|
|
@@ -41,7 +41,7 @@ exports.search = function search(tokens, location) {
|
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
return tokens.length;
|
|
44
|
-
}
|
|
44
|
+
}
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Gets the index of the `startLoc` in `tokens`.
|
|
@@ -51,7 +51,10 @@ exports.search = function search(tokens, location) {
|
|
|
51
51
|
* @param {number} startLoc The location to get an index.
|
|
52
52
|
* @returns {number} The index.
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
function getFirstIndex(tokens, indexMap, startLoc) {
|
|
55
|
+
if (startLoc === -1) {
|
|
56
|
+
return 0;
|
|
57
|
+
}
|
|
55
58
|
if (startLoc in indexMap) {
|
|
56
59
|
return indexMap[startLoc];
|
|
57
60
|
}
|
|
@@ -73,9 +76,13 @@ exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
|
|
|
73
76
|
}
|
|
74
77
|
return index + 1;
|
|
75
78
|
}
|
|
76
|
-
return 0;
|
|
77
|
-
};
|
|
78
79
|
|
|
80
|
+
// Program node that doesn't start/end with a token or comment
|
|
81
|
+
if (startLoc === 0) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
return tokens.length;
|
|
85
|
+
}
|
|
79
86
|
/**
|
|
80
87
|
* Gets the index of the `endLoc` in `tokens`.
|
|
81
88
|
* The information of end locations are recorded at `endLoc - 1` in `indexMap`, so this checks about `endLoc - 1` as well.
|
|
@@ -84,7 +91,10 @@ exports.getFirstIndex = function getFirstIndex(tokens, indexMap, startLoc) {
|
|
|
84
91
|
* @param {number} endLoc The location to get an index.
|
|
85
92
|
* @returns {number} The index.
|
|
86
93
|
*/
|
|
87
|
-
|
|
94
|
+
function getLastIndex(tokens, indexMap, endLoc) {
|
|
95
|
+
if (endLoc === -1) {
|
|
96
|
+
return tokens.length - 1;
|
|
97
|
+
}
|
|
88
98
|
if (endLoc in indexMap) {
|
|
89
99
|
return indexMap[endLoc] - 1;
|
|
90
100
|
}
|
|
@@ -106,5 +116,16 @@ exports.getLastIndex = function getLastIndex(tokens, indexMap, endLoc) {
|
|
|
106
116
|
}
|
|
107
117
|
return index;
|
|
108
118
|
}
|
|
119
|
+
|
|
120
|
+
// Program node that doesn't start/end with a token or comment
|
|
121
|
+
if (endLoc === 0) {
|
|
122
|
+
return -1;
|
|
123
|
+
}
|
|
109
124
|
return tokens.length - 1;
|
|
110
|
-
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
//------------------------------------------------------------------------------
|
|
128
|
+
// Exports
|
|
129
|
+
//------------------------------------------------------------------------------
|
|
130
|
+
|
|
131
|
+
module.exports = { search, getFirstIndex, getLastIndex };
|
|
@@ -33,20 +33,6 @@ class FileContext {
|
|
|
33
33
|
*/
|
|
34
34
|
sourceCode;
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
* The parser options for the file being linted.
|
|
38
|
-
* @type {Record<string, unknown>}
|
|
39
|
-
* @deprecated Use `languageOptions` instead.
|
|
40
|
-
*/
|
|
41
|
-
parserOptions;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* The path to the parser used to parse this file.
|
|
45
|
-
* @type {string}
|
|
46
|
-
* @deprecated No longer supported.
|
|
47
|
-
*/
|
|
48
|
-
parserPath;
|
|
49
|
-
|
|
50
36
|
/**
|
|
51
37
|
* The language options used when parsing this file.
|
|
52
38
|
* @type {Record<string, unknown>}
|
|
@@ -66,8 +52,6 @@ class FileContext {
|
|
|
66
52
|
* @param {string} config.filename The filename of the file being linted.
|
|
67
53
|
* @param {string} config.physicalFilename The physical filename of the file being linted.
|
|
68
54
|
* @param {SourceCode} config.sourceCode The source code of the file being linted.
|
|
69
|
-
* @param {Record<string, unknown>} config.parserOptions The parser options for the file being linted.
|
|
70
|
-
* @param {string} config.parserPath The path to the parser used to parse this file.
|
|
71
55
|
* @param {Record<string, unknown>} config.languageOptions The language options used when parsing this file.
|
|
72
56
|
* @param {Record<string, unknown>} config.settings The settings for the file being linted.
|
|
73
57
|
*/
|
|
@@ -76,8 +60,6 @@ class FileContext {
|
|
|
76
60
|
filename,
|
|
77
61
|
physicalFilename,
|
|
78
62
|
sourceCode,
|
|
79
|
-
parserOptions,
|
|
80
|
-
parserPath,
|
|
81
63
|
languageOptions,
|
|
82
64
|
settings,
|
|
83
65
|
}) {
|
|
@@ -85,50 +67,12 @@ class FileContext {
|
|
|
85
67
|
this.filename = filename;
|
|
86
68
|
this.physicalFilename = physicalFilename;
|
|
87
69
|
this.sourceCode = sourceCode;
|
|
88
|
-
this.parserOptions = parserOptions;
|
|
89
|
-
this.parserPath = parserPath;
|
|
90
70
|
this.languageOptions = languageOptions;
|
|
91
71
|
this.settings = settings;
|
|
92
72
|
|
|
93
73
|
Object.freeze(this);
|
|
94
74
|
}
|
|
95
75
|
|
|
96
|
-
/**
|
|
97
|
-
* Gets the current working directory.
|
|
98
|
-
* @returns {string} The current working directory.
|
|
99
|
-
* @deprecated Use `cwd` instead.
|
|
100
|
-
*/
|
|
101
|
-
getCwd() {
|
|
102
|
-
return this.cwd;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Gets the filename of the file being linted.
|
|
107
|
-
* @returns {string} The filename of the file being linted.
|
|
108
|
-
* @deprecated Use `filename` instead.
|
|
109
|
-
*/
|
|
110
|
-
getFilename() {
|
|
111
|
-
return this.filename;
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Gets the physical filename of the file being linted.
|
|
116
|
-
* @returns {string} The physical filename of the file being linted.
|
|
117
|
-
* @deprecated Use `physicalFilename` instead.
|
|
118
|
-
*/
|
|
119
|
-
getPhysicalFilename() {
|
|
120
|
-
return this.physicalFilename;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Gets the source code of the file being linted.
|
|
125
|
-
* @returns {SourceCode} The source code of the file being linted.
|
|
126
|
-
* @deprecated Use `sourceCode` instead.
|
|
127
|
-
*/
|
|
128
|
-
getSourceCode() {
|
|
129
|
-
return this.sourceCode;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
76
|
/**
|
|
133
77
|
* Creates a new object with the current object as the prototype and
|
|
134
78
|
* the specified properties as its own properties.
|
|
@@ -124,7 +124,6 @@ function createLintingProblem(options, severity, language) {
|
|
|
124
124
|
language,
|
|
125
125
|
),
|
|
126
126
|
severity,
|
|
127
|
-
nodeType: null,
|
|
128
127
|
};
|
|
129
128
|
}
|
|
130
129
|
|
|
@@ -340,7 +339,6 @@ function mapSuggestions(descriptor, sourceCode, messages) {
|
|
|
340
339
|
* @param {Object} options Information about the problem
|
|
341
340
|
* @param {string} options.ruleId Rule ID
|
|
342
341
|
* @param {(0|1|2)} options.severity Rule severity
|
|
343
|
-
* @param {(ASTNode|null)} options.node Node
|
|
344
342
|
* @param {string} options.message Error message
|
|
345
343
|
* @param {string} [options.messageId] The error message ID.
|
|
346
344
|
* @param {{start: SourceLocation, end: (SourceLocation|null)}} options.loc Start and end location
|
|
@@ -362,7 +360,6 @@ function createProblem(options) {
|
|
|
362
360
|
message: options.message,
|
|
363
361
|
line: options.loc.start.line + lineOffset,
|
|
364
362
|
column: options.loc.start.column + columnOffset,
|
|
365
|
-
nodeType: (options.node && options.node.type) || null,
|
|
366
363
|
};
|
|
367
364
|
|
|
368
365
|
/*
|
|
@@ -548,7 +545,6 @@ class FileReport {
|
|
|
548
545
|
createProblem({
|
|
549
546
|
ruleId,
|
|
550
547
|
severity,
|
|
551
|
-
node: descriptor.node,
|
|
552
548
|
message: interpolate(computedMessage, descriptor.data),
|
|
553
549
|
messageId: descriptor.messageId,
|
|
554
550
|
loc: descriptor.loc
|