eslint 9.28.0 → 9.30.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 +1 -1
- package/conf/ecma-version.js +1 -1
- package/conf/globals.js +10 -0
- package/lib/cli.js +6 -11
- package/lib/config/config-loader.js +2 -29
- package/lib/config/flat-config-array.js +1 -1
- package/lib/eslint/eslint.js +14 -18
- package/lib/languages/js/source-code/source-code.js +81 -27
- package/lib/linter/apply-disable-directives.js +2 -4
- package/lib/linter/code-path-analysis/code-path-analyzer.js +8 -9
- package/lib/linter/linter.js +4 -4
- package/lib/linter/source-code-traverser.js +64 -49
- package/lib/linter/source-code-visitor.js +81 -0
- package/lib/rules/array-bracket-newline.js +3 -3
- package/lib/rules/array-bracket-spacing.js +3 -3
- package/lib/rules/array-element-newline.js +3 -3
- package/lib/rules/arrow-parens.js +3 -3
- package/lib/rules/arrow-spacing.js +3 -3
- package/lib/rules/block-spacing.js +3 -3
- package/lib/rules/brace-style.js +3 -3
- package/lib/rules/class-methods-use-this.js +7 -0
- package/lib/rules/comma-dangle.js +3 -3
- package/lib/rules/comma-spacing.js +3 -3
- package/lib/rules/comma-style.js +3 -3
- package/lib/rules/computed-property-spacing.js +3 -3
- package/lib/rules/dot-location.js +3 -3
- package/lib/rules/eol-last.js +3 -3
- package/lib/rules/func-call-spacing.js +3 -3
- package/lib/rules/function-call-argument-newline.js +3 -3
- package/lib/rules/function-paren-newline.js +3 -3
- package/lib/rules/generator-star-spacing.js +3 -3
- package/lib/rules/implicit-arrow-linebreak.js +3 -3
- package/lib/rules/indent-legacy.js +3 -3
- package/lib/rules/indent.js +3 -3
- package/lib/rules/jsx-quotes.js +3 -3
- package/lib/rules/key-spacing.js +3 -3
- package/lib/rules/keyword-spacing.js +3 -3
- package/lib/rules/line-comment-position.js +3 -3
- package/lib/rules/linebreak-style.js +3 -3
- package/lib/rules/lines-around-comment.js +3 -3
- package/lib/rules/lines-around-directive.js +3 -3
- package/lib/rules/lines-between-class-members.js +3 -3
- package/lib/rules/max-len.js +3 -3
- package/lib/rules/max-statements-per-line.js +3 -3
- package/lib/rules/multiline-comment-style.js +3 -3
- package/lib/rules/multiline-ternary.js +3 -3
- package/lib/rules/new-parens.js +3 -3
- package/lib/rules/newline-after-var.js +3 -3
- package/lib/rules/newline-before-return.js +3 -3
- package/lib/rules/newline-per-chained-call.js +3 -3
- package/lib/rules/no-confusing-arrow.js +3 -3
- package/lib/rules/no-duplicate-imports.js +65 -7
- package/lib/rules/no-extra-parens.js +3 -3
- package/lib/rules/no-extra-semi.js +3 -3
- package/lib/rules/no-floating-decimal.js +3 -3
- package/lib/rules/no-mixed-operators.js +3 -3
- package/lib/rules/no-mixed-spaces-and-tabs.js +3 -3
- package/lib/rules/no-multi-spaces.js +3 -3
- package/lib/rules/no-multiple-empty-lines.js +3 -3
- package/lib/rules/no-promise-executor-return.js +4 -35
- package/lib/rules/no-restricted-globals.js +35 -2
- package/lib/rules/no-restricted-properties.js +35 -12
- package/lib/rules/no-setter-return.js +13 -48
- package/lib/rules/no-spaced-func.js +3 -3
- package/lib/rules/no-tabs.js +3 -3
- package/lib/rules/no-trailing-spaces.js +3 -3
- package/lib/rules/no-unused-vars.js +1 -1
- package/lib/rules/no-use-before-define.js +2 -0
- package/lib/rules/no-var.js +14 -2
- package/lib/rules/no-whitespace-before-property.js +3 -3
- package/lib/rules/nonblock-statement-body-position.js +3 -3
- package/lib/rules/object-curly-newline.js +3 -3
- package/lib/rules/object-curly-spacing.js +3 -3
- package/lib/rules/object-property-newline.js +3 -3
- package/lib/rules/one-var-declaration-per-line.js +3 -3
- package/lib/rules/operator-linebreak.js +3 -3
- package/lib/rules/padded-blocks.js +3 -3
- package/lib/rules/padding-line-between-statements.js +3 -3
- package/lib/rules/prefer-regex-literals.js +1 -18
- package/lib/rules/quote-props.js +3 -3
- package/lib/rules/quotes.js +3 -3
- package/lib/rules/rest-spread-spacing.js +3 -3
- package/lib/rules/semi-spacing.js +3 -3
- package/lib/rules/semi-style.js +3 -3
- package/lib/rules/semi.js +3 -3
- package/lib/rules/space-before-blocks.js +3 -3
- package/lib/rules/space-before-function-paren.js +3 -3
- package/lib/rules/space-in-parens.js +3 -3
- package/lib/rules/space-infix-ops.js +3 -3
- package/lib/rules/space-unary-ops.js +3 -3
- package/lib/rules/spaced-comment.js +3 -3
- package/lib/rules/switch-colon-spacing.js +3 -3
- package/lib/rules/template-curly-spacing.js +3 -3
- package/lib/rules/template-tag-spacing.js +3 -3
- package/lib/rules/utils/ast-utils.js +45 -0
- package/lib/rules/wrap-iife.js +3 -3
- package/lib/rules/wrap-regex.js +3 -3
- package/lib/rules/yield-star-spacing.js +3 -3
- package/lib/services/suppressions-service.js +8 -0
- package/lib/shared/flags.js +9 -1
- package/lib/shared/naming.js +109 -0
- package/lib/shared/relative-module-resolver.js +28 -0
- package/lib/shared/runtime-info.js +1 -1
- package/lib/types/index.d.ts +15 -2
- package/lib/types/rules.d.ts +83 -74
- package/package.json +8 -8
- package/lib/linter/safe-emitter.js +0 -52
@@ -24,12 +24,12 @@ module.exports = {
|
|
24
24
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
25
25
|
url: "https://eslint.style/guide/migration",
|
26
26
|
plugin: {
|
27
|
-
name: "@stylistic/eslint-plugin
|
28
|
-
url: "https://eslint.style
|
27
|
+
name: "@stylistic/eslint-plugin",
|
28
|
+
url: "https://eslint.style",
|
29
29
|
},
|
30
30
|
rule: {
|
31
31
|
name: "rest-spread-spacing",
|
32
|
-
url: "https://eslint.style/rules/
|
32
|
+
url: "https://eslint.style/rules/rest-spread-spacing",
|
33
33
|
},
|
34
34
|
},
|
35
35
|
],
|
@@ -26,12 +26,12 @@ module.exports = {
|
|
26
26
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
27
27
|
url: "https://eslint.style/guide/migration",
|
28
28
|
plugin: {
|
29
|
-
name: "@stylistic/eslint-plugin
|
30
|
-
url: "https://eslint.style
|
29
|
+
name: "@stylistic/eslint-plugin",
|
30
|
+
url: "https://eslint.style",
|
31
31
|
},
|
32
32
|
rule: {
|
33
33
|
name: "semi-spacing",
|
34
|
-
url: "https://eslint.style/rules/
|
34
|
+
url: "https://eslint.style/rules/semi-spacing",
|
35
35
|
},
|
36
36
|
},
|
37
37
|
],
|
package/lib/rules/semi-style.js
CHANGED
@@ -96,12 +96,12 @@ module.exports = {
|
|
96
96
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
97
97
|
url: "https://eslint.style/guide/migration",
|
98
98
|
plugin: {
|
99
|
-
name: "@stylistic/eslint-plugin
|
100
|
-
url: "https://eslint.style
|
99
|
+
name: "@stylistic/eslint-plugin",
|
100
|
+
url: "https://eslint.style",
|
101
101
|
},
|
102
102
|
rule: {
|
103
103
|
name: "semi-style",
|
104
|
-
url: "https://eslint.style/rules/
|
104
|
+
url: "https://eslint.style/rules/semi-style",
|
105
105
|
},
|
106
106
|
},
|
107
107
|
],
|
package/lib/rules/semi.js
CHANGED
@@ -30,12 +30,12 @@ module.exports = {
|
|
30
30
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
31
31
|
url: "https://eslint.style/guide/migration",
|
32
32
|
plugin: {
|
33
|
-
name: "@stylistic/eslint-plugin
|
34
|
-
url: "https://eslint.style
|
33
|
+
name: "@stylistic/eslint-plugin",
|
34
|
+
url: "https://eslint.style",
|
35
35
|
},
|
36
36
|
rule: {
|
37
37
|
name: "semi",
|
38
|
-
url: "https://eslint.style/rules/
|
38
|
+
url: "https://eslint.style/rules/semi",
|
39
39
|
},
|
40
40
|
},
|
41
41
|
],
|
@@ -49,12 +49,12 @@ module.exports = {
|
|
49
49
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
50
50
|
url: "https://eslint.style/guide/migration",
|
51
51
|
plugin: {
|
52
|
-
name: "@stylistic/eslint-plugin
|
53
|
-
url: "https://eslint.style
|
52
|
+
name: "@stylistic/eslint-plugin",
|
53
|
+
url: "https://eslint.style",
|
54
54
|
},
|
55
55
|
rule: {
|
56
56
|
name: "space-before-blocks",
|
57
|
-
url: "https://eslint.style/rules/
|
57
|
+
url: "https://eslint.style/rules/space-before-blocks",
|
58
58
|
},
|
59
59
|
},
|
60
60
|
],
|
@@ -29,12 +29,12 @@ module.exports = {
|
|
29
29
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
30
30
|
url: "https://eslint.style/guide/migration",
|
31
31
|
plugin: {
|
32
|
-
name: "@stylistic/eslint-plugin
|
33
|
-
url: "https://eslint.style
|
32
|
+
name: "@stylistic/eslint-plugin",
|
33
|
+
url: "https://eslint.style",
|
34
34
|
},
|
35
35
|
rule: {
|
36
36
|
name: "space-before-function-paren",
|
37
|
-
url: "https://eslint.style/rules/
|
37
|
+
url: "https://eslint.style/rules/space-before-function-paren",
|
38
38
|
},
|
39
39
|
},
|
40
40
|
],
|
@@ -25,12 +25,12 @@ module.exports = {
|
|
25
25
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
26
26
|
url: "https://eslint.style/guide/migration",
|
27
27
|
plugin: {
|
28
|
-
name: "@stylistic/eslint-plugin
|
29
|
-
url: "https://eslint.style
|
28
|
+
name: "@stylistic/eslint-plugin",
|
29
|
+
url: "https://eslint.style",
|
30
30
|
},
|
31
31
|
rule: {
|
32
32
|
name: "space-in-parens",
|
33
|
-
url: "https://eslint.style/rules/
|
33
|
+
url: "https://eslint.style/rules/space-in-parens",
|
34
34
|
},
|
35
35
|
},
|
36
36
|
],
|
@@ -25,12 +25,12 @@ module.exports = {
|
|
25
25
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
26
26
|
url: "https://eslint.style/guide/migration",
|
27
27
|
plugin: {
|
28
|
-
name: "@stylistic/eslint-plugin
|
29
|
-
url: "https://eslint.style
|
28
|
+
name: "@stylistic/eslint-plugin",
|
29
|
+
url: "https://eslint.style",
|
30
30
|
},
|
31
31
|
rule: {
|
32
32
|
name: "space-infix-ops",
|
33
|
-
url: "https://eslint.style/rules/
|
33
|
+
url: "https://eslint.style/rules/space-infix-ops",
|
34
34
|
},
|
35
35
|
},
|
36
36
|
],
|
@@ -29,12 +29,12 @@ module.exports = {
|
|
29
29
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
30
30
|
url: "https://eslint.style/guide/migration",
|
31
31
|
plugin: {
|
32
|
-
name: "@stylistic/eslint-plugin
|
33
|
-
url: "https://eslint.style
|
32
|
+
name: "@stylistic/eslint-plugin",
|
33
|
+
url: "https://eslint.style",
|
34
34
|
},
|
35
35
|
rule: {
|
36
36
|
name: "space-unary-ops",
|
37
|
-
url: "https://eslint.style/rules/
|
37
|
+
url: "https://eslint.style/rules/space-unary-ops",
|
38
38
|
},
|
39
39
|
},
|
40
40
|
],
|
@@ -154,12 +154,12 @@ module.exports = {
|
|
154
154
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
155
155
|
url: "https://eslint.style/guide/migration",
|
156
156
|
plugin: {
|
157
|
-
name: "@stylistic/eslint-plugin
|
158
|
-
url: "https://eslint.style
|
157
|
+
name: "@stylistic/eslint-plugin",
|
158
|
+
url: "https://eslint.style",
|
159
159
|
},
|
160
160
|
rule: {
|
161
161
|
name: "spaced-comment",
|
162
|
-
url: "https://eslint.style/rules/
|
162
|
+
url: "https://eslint.style/rules/spaced-comment",
|
163
163
|
},
|
164
164
|
},
|
165
165
|
],
|
@@ -30,12 +30,12 @@ module.exports = {
|
|
30
30
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
31
31
|
url: "https://eslint.style/guide/migration",
|
32
32
|
plugin: {
|
33
|
-
name: "@stylistic/eslint-plugin
|
34
|
-
url: "https://eslint.style
|
33
|
+
name: "@stylistic/eslint-plugin",
|
34
|
+
url: "https://eslint.style",
|
35
35
|
},
|
36
36
|
rule: {
|
37
37
|
name: "switch-colon-spacing",
|
38
|
-
url: "https://eslint.style/rules/
|
38
|
+
url: "https://eslint.style/rules/switch-colon-spacing",
|
39
39
|
},
|
40
40
|
},
|
41
41
|
],
|
@@ -30,12 +30,12 @@ module.exports = {
|
|
30
30
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
31
31
|
url: "https://eslint.style/guide/migration",
|
32
32
|
plugin: {
|
33
|
-
name: "@stylistic/eslint-plugin
|
34
|
-
url: "https://eslint.style
|
33
|
+
name: "@stylistic/eslint-plugin",
|
34
|
+
url: "https://eslint.style",
|
35
35
|
},
|
36
36
|
rule: {
|
37
37
|
name: "template-curly-spacing",
|
38
|
-
url: "https://eslint.style/rules/
|
38
|
+
url: "https://eslint.style/rules/template-curly-spacing",
|
39
39
|
},
|
40
40
|
},
|
41
41
|
],
|
@@ -24,12 +24,12 @@ module.exports = {
|
|
24
24
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
25
25
|
url: "https://eslint.style/guide/migration",
|
26
26
|
plugin: {
|
27
|
-
name: "@stylistic/eslint-plugin
|
28
|
-
url: "https://eslint.style
|
27
|
+
name: "@stylistic/eslint-plugin",
|
28
|
+
url: "https://eslint.style",
|
29
29
|
},
|
30
30
|
rule: {
|
31
31
|
name: "template-tag-spacing",
|
32
|
-
url: "https://eslint.style/rules/
|
32
|
+
url: "https://eslint.style/rules/template-tag-spacing",
|
33
33
|
},
|
34
34
|
},
|
35
35
|
],
|
@@ -1193,6 +1193,35 @@ let needsPrecedingSemicolon;
|
|
1193
1193
|
"WithStatement",
|
1194
1194
|
]);
|
1195
1195
|
|
1196
|
+
const TS_TYPE_NODE_TYPES = new Set([
|
1197
|
+
"TSAsExpression",
|
1198
|
+
"TSSatisfiesExpression",
|
1199
|
+
"TSTypeAliasDeclaration",
|
1200
|
+
"TSTypeAnnotation",
|
1201
|
+
]);
|
1202
|
+
|
1203
|
+
/**
|
1204
|
+
* Determines whether a specified node is inside a TypeScript type context.
|
1205
|
+
* @param {ASTNode} node The node to check.
|
1206
|
+
* @returns {boolean} Whether the node is inside a TypeScript type context.
|
1207
|
+
*/
|
1208
|
+
function isInType(node) {
|
1209
|
+
for (let currNode = node; ; ) {
|
1210
|
+
const { parent } = currNode;
|
1211
|
+
if (!parent) {
|
1212
|
+
break;
|
1213
|
+
}
|
1214
|
+
if (
|
1215
|
+
TS_TYPE_NODE_TYPES.has(parent.type) &&
|
1216
|
+
currNode === parent.typeAnnotation
|
1217
|
+
) {
|
1218
|
+
return true;
|
1219
|
+
}
|
1220
|
+
currNode = parent;
|
1221
|
+
}
|
1222
|
+
return false;
|
1223
|
+
}
|
1224
|
+
|
1196
1225
|
needsPrecedingSemicolon = function (sourceCode, node) {
|
1197
1226
|
const prevToken = sourceCode.getTokenBefore(node);
|
1198
1227
|
|
@@ -1206,6 +1235,16 @@ let needsPrecedingSemicolon;
|
|
1206
1235
|
|
1207
1236
|
const prevNode = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
|
1208
1237
|
|
1238
|
+
if (
|
1239
|
+
prevNode.type === "TSDeclareFunction" ||
|
1240
|
+
prevNode.parent.type === "TSImportEqualsDeclaration" ||
|
1241
|
+
prevNode.parent.parent?.type === "TSImportEqualsDeclaration" ||
|
1242
|
+
TS_TYPE_NODE_TYPES.has(prevNode.type) ||
|
1243
|
+
isInType(prevNode)
|
1244
|
+
) {
|
1245
|
+
return false;
|
1246
|
+
}
|
1247
|
+
|
1209
1248
|
if (isClosingParenToken(prevToken)) {
|
1210
1249
|
return !STATEMENTS.has(prevNode.type);
|
1211
1250
|
}
|
@@ -1222,6 +1261,12 @@ let needsPrecedingSemicolon;
|
|
1222
1261
|
}
|
1223
1262
|
|
1224
1263
|
if (IDENTIFIER_OR_KEYWORD.has(prevToken.type)) {
|
1264
|
+
if (
|
1265
|
+
prevNode.parent.type === "VariableDeclarator" &&
|
1266
|
+
!prevNode.parent.init
|
1267
|
+
) {
|
1268
|
+
return false;
|
1269
|
+
}
|
1225
1270
|
if (BREAK_OR_CONTINUE.has(prevNode.parent.type)) {
|
1226
1271
|
return false;
|
1227
1272
|
}
|
package/lib/rules/wrap-iife.js
CHANGED
@@ -51,12 +51,12 @@ module.exports = {
|
|
51
51
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
52
52
|
url: "https://eslint.style/guide/migration",
|
53
53
|
plugin: {
|
54
|
-
name: "@stylistic/eslint-plugin
|
55
|
-
url: "https://eslint.style
|
54
|
+
name: "@stylistic/eslint-plugin",
|
55
|
+
url: "https://eslint.style",
|
56
56
|
},
|
57
57
|
rule: {
|
58
58
|
name: "wrap-iife",
|
59
|
-
url: "https://eslint.style/rules/
|
59
|
+
url: "https://eslint.style/rules/wrap-iife",
|
60
60
|
},
|
61
61
|
},
|
62
62
|
],
|
package/lib/rules/wrap-regex.js
CHANGED
@@ -24,12 +24,12 @@ module.exports = {
|
|
24
24
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
25
25
|
url: "https://eslint.style/guide/migration",
|
26
26
|
plugin: {
|
27
|
-
name: "@stylistic/eslint-plugin
|
28
|
-
url: "https://eslint.style
|
27
|
+
name: "@stylistic/eslint-plugin",
|
28
|
+
url: "https://eslint.style",
|
29
29
|
},
|
30
30
|
rule: {
|
31
31
|
name: "wrap-regex",
|
32
|
-
url: "https://eslint.style/rules/
|
32
|
+
url: "https://eslint.style/rules/wrap-regex",
|
33
33
|
},
|
34
34
|
},
|
35
35
|
],
|
@@ -24,12 +24,12 @@ module.exports = {
|
|
24
24
|
"ESLint Stylistic now maintains deprecated stylistic core rules.",
|
25
25
|
url: "https://eslint.style/guide/migration",
|
26
26
|
plugin: {
|
27
|
-
name: "@stylistic/eslint-plugin
|
28
|
-
url: "https://eslint.style
|
27
|
+
name: "@stylistic/eslint-plugin",
|
28
|
+
url: "https://eslint.style",
|
29
29
|
},
|
30
30
|
rule: {
|
31
31
|
name: "yield-star-spacing",
|
32
|
-
url: "https://eslint.style/rules/
|
32
|
+
url: "https://eslint.style/rules/yield-star-spacing",
|
33
33
|
},
|
34
34
|
},
|
35
35
|
],
|
@@ -112,6 +112,14 @@ class SuppressionsService {
|
|
112
112
|
}
|
113
113
|
}
|
114
114
|
|
115
|
+
for (const file of Object.keys(suppressions)) {
|
116
|
+
const absolutePath = path.resolve(this.cwd, file);
|
117
|
+
|
118
|
+
if (!fs.existsSync(absolutePath)) {
|
119
|
+
delete suppressions[file];
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
115
123
|
return this.save(suppressions);
|
116
124
|
}
|
117
125
|
|
package/lib/shared/flags.js
CHANGED
@@ -29,7 +29,7 @@ const activeFlags = new Map([
|
|
29
29
|
["test_only", "Used only for testing."],
|
30
30
|
["test_only_2", "Used only for testing."],
|
31
31
|
[
|
32
|
-
"
|
32
|
+
"v10_config_lookup_from_file",
|
33
33
|
"Look up `eslint.config.js` from the file being linted.",
|
34
34
|
],
|
35
35
|
[
|
@@ -73,6 +73,14 @@ const inactiveFlags = new Map([
|
|
73
73
|
replacedBy: null,
|
74
74
|
},
|
75
75
|
],
|
76
|
+
[
|
77
|
+
"unstable_config_lookup_from_file",
|
78
|
+
{
|
79
|
+
description:
|
80
|
+
"Look up `eslint.config.js` from the file being linted.",
|
81
|
+
replacedBy: "v10_config_lookup_from_file",
|
82
|
+
},
|
83
|
+
],
|
76
84
|
]);
|
77
85
|
|
78
86
|
/**
|
@@ -0,0 +1,109 @@
|
|
1
|
+
/**
|
2
|
+
* @fileoverview Common helpers for naming of plugins, formatters and configs
|
3
|
+
*/
|
4
|
+
|
5
|
+
"use strict";
|
6
|
+
|
7
|
+
const NAMESPACE_REGEX = /^@.*\//iu;
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Brings package name to correct format based on prefix
|
11
|
+
* @param {string} name The name of the package.
|
12
|
+
* @param {string} prefix Can be either "eslint-plugin", "eslint-config" or "eslint-formatter"
|
13
|
+
* @returns {string} Normalized name of the package
|
14
|
+
* @private
|
15
|
+
*/
|
16
|
+
function normalizePackageName(name, prefix) {
|
17
|
+
let normalizedName = name;
|
18
|
+
|
19
|
+
/**
|
20
|
+
* On Windows, name can come in with Windows slashes instead of Unix slashes.
|
21
|
+
* Normalize to Unix first to avoid errors later on.
|
22
|
+
* https://github.com/eslint/eslint/issues/5644
|
23
|
+
*/
|
24
|
+
if (normalizedName.includes("\\")) {
|
25
|
+
normalizedName = normalizedName.replace(/\\/gu, "/");
|
26
|
+
}
|
27
|
+
|
28
|
+
if (normalizedName.charAt(0) === "@") {
|
29
|
+
/**
|
30
|
+
* it's a scoped package
|
31
|
+
* package name is the prefix, or just a username
|
32
|
+
*/
|
33
|
+
const scopedPackageShortcutRegex = new RegExp(
|
34
|
+
`^(@[^/]+)(?:/(?:${prefix})?)?$`,
|
35
|
+
"u",
|
36
|
+
),
|
37
|
+
scopedPackageNameRegex = new RegExp(`^${prefix}(-|$)`, "u");
|
38
|
+
|
39
|
+
if (scopedPackageShortcutRegex.test(normalizedName)) {
|
40
|
+
normalizedName = normalizedName.replace(
|
41
|
+
scopedPackageShortcutRegex,
|
42
|
+
`$1/${prefix}`,
|
43
|
+
);
|
44
|
+
} else if (!scopedPackageNameRegex.test(normalizedName.split("/")[1])) {
|
45
|
+
/**
|
46
|
+
* for scoped packages, insert the prefix after the first / unless
|
47
|
+
* the path is already @scope/eslint or @scope/eslint-xxx-yyy
|
48
|
+
*/
|
49
|
+
normalizedName = normalizedName.replace(
|
50
|
+
/^@([^/]+)\/(.*)$/u,
|
51
|
+
`@$1/${prefix}-$2`,
|
52
|
+
);
|
53
|
+
}
|
54
|
+
} else if (!normalizedName.startsWith(`${prefix}-`)) {
|
55
|
+
normalizedName = `${prefix}-${normalizedName}`;
|
56
|
+
}
|
57
|
+
|
58
|
+
return normalizedName;
|
59
|
+
}
|
60
|
+
|
61
|
+
/**
|
62
|
+
* Removes the prefix from a fullname.
|
63
|
+
* @param {string} fullname The term which may have the prefix.
|
64
|
+
* @param {string} prefix The prefix to remove.
|
65
|
+
* @returns {string} The term without prefix.
|
66
|
+
*/
|
67
|
+
function getShorthandName(fullname, prefix) {
|
68
|
+
if (fullname[0] === "@") {
|
69
|
+
let matchResult = new RegExp(`^(@[^/]+)/${prefix}$`, "u").exec(
|
70
|
+
fullname,
|
71
|
+
);
|
72
|
+
|
73
|
+
if (matchResult) {
|
74
|
+
return matchResult[1];
|
75
|
+
}
|
76
|
+
|
77
|
+
matchResult = new RegExp(`^(@[^/]+)/${prefix}-(.+)$`, "u").exec(
|
78
|
+
fullname,
|
79
|
+
);
|
80
|
+
if (matchResult) {
|
81
|
+
return `${matchResult[1]}/${matchResult[2]}`;
|
82
|
+
}
|
83
|
+
} else if (fullname.startsWith(`${prefix}-`)) {
|
84
|
+
return fullname.slice(prefix.length + 1);
|
85
|
+
}
|
86
|
+
|
87
|
+
return fullname;
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Gets the scope (namespace) of a term.
|
92
|
+
* @param {string} term The term which may have the namespace.
|
93
|
+
* @returns {string} The namespace of the term if it has one.
|
94
|
+
*/
|
95
|
+
function getNamespaceFromTerm(term) {
|
96
|
+
const match = term.match(NAMESPACE_REGEX);
|
97
|
+
|
98
|
+
return match ? match[0] : "";
|
99
|
+
}
|
100
|
+
|
101
|
+
//------------------------------------------------------------------------------
|
102
|
+
// Public Interface
|
103
|
+
//------------------------------------------------------------------------------
|
104
|
+
|
105
|
+
module.exports = {
|
106
|
+
normalizePackageName,
|
107
|
+
getShorthandName,
|
108
|
+
getNamespaceFromTerm,
|
109
|
+
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* Utility for resolving a module relative to another module
|
3
|
+
* @author Teddy Katz
|
4
|
+
*/
|
5
|
+
|
6
|
+
"use strict";
|
7
|
+
|
8
|
+
const Module = require("node:module");
|
9
|
+
|
10
|
+
/*
|
11
|
+
* `Module.createRequire` is added in v12.2.0. It supports URL as well.
|
12
|
+
* We only support the case where the argument is a filepath, not a URL.
|
13
|
+
*/
|
14
|
+
const createRequire = Module.createRequire;
|
15
|
+
|
16
|
+
/**
|
17
|
+
* Resolves a Node module relative to another module
|
18
|
+
* @param {string} moduleName The name of a Node module, or a path to a Node module.
|
19
|
+
* @param {string} relativeToPath An absolute path indicating the module that `moduleName` should be resolved relative to. This must be
|
20
|
+
* a file rather than a directory, but the file need not actually exist.
|
21
|
+
* @returns {string} The absolute path that would result from calling `require.resolve(moduleName)` in a file located at `relativeToPath`
|
22
|
+
* @throws {Error} When the module cannot be resolved.
|
23
|
+
*/
|
24
|
+
function resolve(moduleName, relativeToPath) {
|
25
|
+
return createRequire(relativeToPath).resolve(moduleName);
|
26
|
+
}
|
27
|
+
|
28
|
+
exports.resolve = resolve;
|
@@ -150,7 +150,7 @@ function environment() {
|
|
150
150
|
return [
|
151
151
|
"Environment Info:",
|
152
152
|
"",
|
153
|
-
`Node version: ${
|
153
|
+
`Node version: ${process.version}`,
|
154
154
|
`npm version: ${getBinVersion("npm")}`,
|
155
155
|
`Local ESLint version: ${getNpmPackageVersion("eslint", { global: false })}`,
|
156
156
|
`Global ESLint version: ${getNpmPackageVersion("eslint", { global: true })}`,
|
package/lib/types/index.d.ts
CHANGED
@@ -289,6 +289,8 @@ export class SourceCode
|
|
289
289
|
second: ESTree.Node | AST.Token,
|
290
290
|
): boolean;
|
291
291
|
|
292
|
+
isGlobalReference(node: ESTree.Identifier): boolean;
|
293
|
+
|
292
294
|
markVariableAsUsed(name: string, refNode?: ESTree.Node): boolean;
|
293
295
|
|
294
296
|
traverse(): Iterable<TraversalStep>;
|
@@ -1414,6 +1416,7 @@ export namespace Linter {
|
|
1414
1416
|
| 14
|
1415
1417
|
| 15
|
1416
1418
|
| 16
|
1419
|
+
| 17
|
1417
1420
|
| 2015
|
1418
1421
|
| 2016
|
1419
1422
|
| 2017
|
@@ -1425,6 +1428,7 @@ export namespace Linter {
|
|
1425
1428
|
| 2023
|
1426
1429
|
| 2024
|
1427
1430
|
| 2025
|
1431
|
+
| 2026
|
1428
1432
|
| "latest";
|
1429
1433
|
|
1430
1434
|
/**
|
@@ -1624,7 +1628,9 @@ export namespace Linter {
|
|
1624
1628
|
postprocess?:
|
1625
1629
|
| ((problemLists: LintMessage[][]) => LintMessage[])
|
1626
1630
|
| undefined;
|
1627
|
-
filterCodeBlock?:
|
1631
|
+
filterCodeBlock?:
|
1632
|
+
| ((filename: string, text: string) => boolean)
|
1633
|
+
| undefined;
|
1628
1634
|
disableFixes?: boolean | undefined;
|
1629
1635
|
allowInlineConfig?: boolean | undefined;
|
1630
1636
|
reportUnusedDisableDirectives?: boolean | undefined;
|
@@ -1770,6 +1776,13 @@ export namespace Linter {
|
|
1770
1776
|
*/
|
1771
1777
|
name?: string;
|
1772
1778
|
|
1779
|
+
/**
|
1780
|
+
* Path to the directory where the configuration object should apply.
|
1781
|
+
* `files` and `ignores` patterns in the configuration object are
|
1782
|
+
* interpreted as relative to this path.
|
1783
|
+
*/
|
1784
|
+
basePath?: string;
|
1785
|
+
|
1773
1786
|
/**
|
1774
1787
|
* An array of glob patterns indicating the files that the configuration
|
1775
1788
|
* object should apply to. If not specified, the configuration object applies
|
@@ -1829,7 +1842,7 @@ export namespace Linter {
|
|
1829
1842
|
}
|
1830
1843
|
|
1831
1844
|
/** @deprecated Use `Config` instead of `FlatConfig` */
|
1832
|
-
type FlatConfig = Config
|
1845
|
+
type FlatConfig<Rules extends RulesRecord = RulesRecord> = Config<Rules>;
|
1833
1846
|
|
1834
1847
|
type GlobalConf =
|
1835
1848
|
| boolean
|