eslint 9.37.0 → 9.39.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 +12 -2
- package/lib/eslint/eslint-helpers.js +1 -1
- package/lib/eslint/eslint.js +17 -1
- package/lib/eslint/worker.js +12 -1
- package/lib/linter/file-report.js +1 -1
- package/lib/linter/source-code-traverser.js +11 -5
- package/lib/linter/timing.js +38 -1
- package/lib/rules/callback-return.js +1 -1
- package/lib/rules/complexity.js +5 -0
- package/lib/rules/for-direction.js +4 -1
- package/lib/rules/global-require.js +1 -1
- package/lib/rules/handle-callback-err.js +1 -1
- package/lib/rules/id-blacklist.js +1 -1
- package/lib/rules/no-buffer-constructor.js +1 -1
- package/lib/rules/no-catch-shadow.js +1 -1
- package/lib/rules/no-dupe-args.js +12 -1
- package/lib/rules/no-dupe-class-members.js +1 -1
- package/lib/rules/no-loss-of-precision.js +206 -208
- package/lib/rules/no-mixed-requires.js +1 -1
- package/lib/rules/no-native-reassign.js +1 -1
- package/lib/rules/no-negated-in-lhs.js +1 -1
- package/lib/rules/no-new-object.js +1 -1
- package/lib/rules/no-new-require.js +1 -1
- package/lib/rules/no-new-symbol.js +1 -1
- package/lib/rules/no-path-concat.js +1 -1
- package/lib/rules/no-process-env.js +1 -1
- package/lib/rules/no-process-exit.js +1 -1
- package/lib/rules/no-restricted-modules.js +1 -1
- package/lib/rules/no-sync.js +1 -1
- package/lib/rules/object-shorthand.js +105 -80
- package/lib/rules/utils/ast-utils.js +1 -0
- package/lib/shared/serialization.js +1 -1
- package/lib/types/config-api.d.ts +6 -2
- package/lib/types/index.d.ts +169 -995
- package/package.json +11 -10
|
@@ -19,6 +19,86 @@ const OPTIONS = {
|
|
|
19
19
|
//------------------------------------------------------------------------------
|
|
20
20
|
const astUtils = require("./utils/ast-utils");
|
|
21
21
|
|
|
22
|
+
//--------------------------------------------------------------------------
|
|
23
|
+
// Helpers
|
|
24
|
+
//--------------------------------------------------------------------------
|
|
25
|
+
const CTOR_PREFIX_REGEX = /[^_$0-9]/u;
|
|
26
|
+
const JSDOC_COMMENT_REGEX = /^\s*\*/u;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Determines if the first character of the name is a capital letter.
|
|
30
|
+
* @param {string} name The name of the node to evaluate.
|
|
31
|
+
* @returns {boolean} True if the first character of the property name is a capital letter, false if not.
|
|
32
|
+
* @private
|
|
33
|
+
*/
|
|
34
|
+
function isConstructor(name) {
|
|
35
|
+
const match = CTOR_PREFIX_REGEX.exec(name);
|
|
36
|
+
|
|
37
|
+
// Not a constructor if name has no characters apart from '_', '$' and digits e.g. '_', '$$', '_8'
|
|
38
|
+
if (!match) {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const firstChar = name.charAt(match.index);
|
|
43
|
+
|
|
44
|
+
return firstChar === firstChar.toUpperCase();
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Determines if the property can have a shorthand form.
|
|
49
|
+
* @param {ASTNode} property Property AST node
|
|
50
|
+
* @returns {boolean} True if the property can have a shorthand form
|
|
51
|
+
* @private
|
|
52
|
+
*/
|
|
53
|
+
function canHaveShorthand(property) {
|
|
54
|
+
return (
|
|
55
|
+
property.kind !== "set" &&
|
|
56
|
+
property.kind !== "get" &&
|
|
57
|
+
property.type !== "SpreadElement" &&
|
|
58
|
+
property.type !== "SpreadProperty" &&
|
|
59
|
+
property.type !== "ExperimentalSpreadProperty"
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Checks whether a node is a string literal.
|
|
65
|
+
* @param {ASTNode} node Any AST node.
|
|
66
|
+
* @returns {boolean} `true` if it is a string literal.
|
|
67
|
+
*/
|
|
68
|
+
function isStringLiteral(node) {
|
|
69
|
+
return node.type === "Literal" && typeof node.value === "string";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Determines if the property is a shorthand or not.
|
|
74
|
+
* @param {ASTNode} property Property AST node
|
|
75
|
+
* @returns {boolean} True if the property is considered shorthand, false if not.
|
|
76
|
+
* @private
|
|
77
|
+
*/
|
|
78
|
+
function isShorthand(property) {
|
|
79
|
+
// property.method is true when `{a(){}}`.
|
|
80
|
+
return property.shorthand || property.method;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Determines if the property's key and method or value are named equally.
|
|
85
|
+
* @param {ASTNode} property Property AST node
|
|
86
|
+
* @returns {boolean} True if the key and value are named equally, false if not.
|
|
87
|
+
* @private
|
|
88
|
+
*/
|
|
89
|
+
function isRedundant(property) {
|
|
90
|
+
const value = property.value;
|
|
91
|
+
|
|
92
|
+
if (value.type === "FunctionExpression") {
|
|
93
|
+
return !value.id; // Only anonymous should be shorthand method.
|
|
94
|
+
}
|
|
95
|
+
if (value.type === "Identifier") {
|
|
96
|
+
return astUtils.getStaticPropertyName(property) === value.name;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
|
|
22
102
|
//------------------------------------------------------------------------------
|
|
23
103
|
// Rule Definition
|
|
24
104
|
//------------------------------------------------------------------------------
|
|
@@ -139,86 +219,6 @@ module.exports = {
|
|
|
139
219
|
const AVOID_EXPLICIT_RETURN_ARROWS = !!PARAMS.avoidExplicitReturnArrows;
|
|
140
220
|
const sourceCode = context.sourceCode;
|
|
141
221
|
|
|
142
|
-
//--------------------------------------------------------------------------
|
|
143
|
-
// Helpers
|
|
144
|
-
//--------------------------------------------------------------------------
|
|
145
|
-
|
|
146
|
-
const CTOR_PREFIX_REGEX = /[^_$0-9]/u;
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* Determines if the first character of the name is a capital letter.
|
|
150
|
-
* @param {string} name The name of the node to evaluate.
|
|
151
|
-
* @returns {boolean} True if the first character of the property name is a capital letter, false if not.
|
|
152
|
-
* @private
|
|
153
|
-
*/
|
|
154
|
-
function isConstructor(name) {
|
|
155
|
-
const match = CTOR_PREFIX_REGEX.exec(name);
|
|
156
|
-
|
|
157
|
-
// Not a constructor if name has no characters apart from '_', '$' and digits e.g. '_', '$$', '_8'
|
|
158
|
-
if (!match) {
|
|
159
|
-
return false;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const firstChar = name.charAt(match.index);
|
|
163
|
-
|
|
164
|
-
return firstChar === firstChar.toUpperCase();
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Determines if the property can have a shorthand form.
|
|
169
|
-
* @param {ASTNode} property Property AST node
|
|
170
|
-
* @returns {boolean} True if the property can have a shorthand form
|
|
171
|
-
* @private
|
|
172
|
-
*/
|
|
173
|
-
function canHaveShorthand(property) {
|
|
174
|
-
return (
|
|
175
|
-
property.kind !== "set" &&
|
|
176
|
-
property.kind !== "get" &&
|
|
177
|
-
property.type !== "SpreadElement" &&
|
|
178
|
-
property.type !== "SpreadProperty" &&
|
|
179
|
-
property.type !== "ExperimentalSpreadProperty"
|
|
180
|
-
);
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* Checks whether a node is a string literal.
|
|
185
|
-
* @param {ASTNode} node Any AST node.
|
|
186
|
-
* @returns {boolean} `true` if it is a string literal.
|
|
187
|
-
*/
|
|
188
|
-
function isStringLiteral(node) {
|
|
189
|
-
return node.type === "Literal" && typeof node.value === "string";
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Determines if the property is a shorthand or not.
|
|
194
|
-
* @param {ASTNode} property Property AST node
|
|
195
|
-
* @returns {boolean} True if the property is considered shorthand, false if not.
|
|
196
|
-
* @private
|
|
197
|
-
*/
|
|
198
|
-
function isShorthand(property) {
|
|
199
|
-
// property.method is true when `{a(){}}`.
|
|
200
|
-
return property.shorthand || property.method;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Determines if the property's key and method or value are named equally.
|
|
205
|
-
* @param {ASTNode} property Property AST node
|
|
206
|
-
* @returns {boolean} True if the key and value are named equally, false if not.
|
|
207
|
-
* @private
|
|
208
|
-
*/
|
|
209
|
-
function isRedundant(property) {
|
|
210
|
-
const value = property.value;
|
|
211
|
-
|
|
212
|
-
if (value.type === "FunctionExpression") {
|
|
213
|
-
return !value.id; // Only anonymous should be shorthand method.
|
|
214
|
-
}
|
|
215
|
-
if (value.type === "Identifier") {
|
|
216
|
-
return astUtils.getStaticPropertyName(property) === value.name;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
222
|
/**
|
|
223
223
|
* Ensures that an object's properties are consistently shorthand, or not shorthand at all.
|
|
224
224
|
* @param {ASTNode} node Property AST node
|
|
@@ -582,6 +582,19 @@ module.exports = {
|
|
|
582
582
|
node.key.name === node.value.name &&
|
|
583
583
|
APPLY_TO_PROPS
|
|
584
584
|
) {
|
|
585
|
+
// Skip if there are JSDoc comments inside the property (e.g., JSDoc type annotations)
|
|
586
|
+
const comments = sourceCode.getCommentsInside(node);
|
|
587
|
+
if (
|
|
588
|
+
comments.some(
|
|
589
|
+
comment =>
|
|
590
|
+
comment.type === "Block" &&
|
|
591
|
+
JSDOC_COMMENT_REGEX.test(comment.value) &&
|
|
592
|
+
comment.value.includes("@type"),
|
|
593
|
+
)
|
|
594
|
+
) {
|
|
595
|
+
return;
|
|
596
|
+
}
|
|
597
|
+
|
|
585
598
|
// {x: x} should be written as {x}
|
|
586
599
|
context.report({
|
|
587
600
|
node,
|
|
@@ -606,6 +619,18 @@ module.exports = {
|
|
|
606
619
|
return;
|
|
607
620
|
}
|
|
608
621
|
|
|
622
|
+
const comments = sourceCode.getCommentsInside(node);
|
|
623
|
+
if (
|
|
624
|
+
comments.some(
|
|
625
|
+
comment =>
|
|
626
|
+
comment.type === "Block" &&
|
|
627
|
+
comment.value.startsWith("*") &&
|
|
628
|
+
comment.value.includes("@type"),
|
|
629
|
+
)
|
|
630
|
+
) {
|
|
631
|
+
return;
|
|
632
|
+
}
|
|
633
|
+
|
|
609
634
|
// {"x": x} should be written as {x}
|
|
610
635
|
context.report({
|
|
611
636
|
node,
|
|
@@ -56,7 +56,7 @@ function isSerializable(val, seenObjects = new Set()) {
|
|
|
56
56
|
/*
|
|
57
57
|
* We're creating a new Set of seen objects because we want to
|
|
58
58
|
* ensure that `val` doesn't appear again in this path, but it can appear
|
|
59
|
-
* in other paths. This allows for
|
|
59
|
+
* in other paths. This allows for reusing objects in the graph, as long as
|
|
60
60
|
* there are no cycles.
|
|
61
61
|
*/
|
|
62
62
|
!isSerializable(
|
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* @author Nicholas C. Zakas
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
type Config,
|
|
8
|
+
defineConfig,
|
|
9
|
+
globalIgnores,
|
|
10
|
+
} from "@eslint/config-helpers";
|
|
7
11
|
|
|
8
|
-
export { defineConfig, globalIgnores };
|
|
12
|
+
export { type Config, defineConfig, globalIgnores };
|