Skip to content

Commit f1d0252

Browse files
authored
Update ESLint and use the new isGlobalReference to make rule stricter (#2682)
1 parent e56ff96 commit f1d0252

9 files changed

+62
-224
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"dependencies": {
5959
"@babel/helper-validator-identifier": "^7.27.1",
6060
"@eslint-community/eslint-utils": "^4.7.0",
61-
"@eslint/plugin-kit": "^0.3.1",
61+
"@eslint/plugin-kit": "^0.3.2",
6262
"change-case": "^5.4.4",
6363
"ci-info": "^4.2.0",
6464
"clean-regexp": "^1.0.0",
@@ -85,7 +85,7 @@
8585
"ava": "^6.4.0",
8686
"c8": "^10.1.3",
8787
"enquirer": "^2.4.1",
88-
"eslint": "^9.28.0",
88+
"eslint": "^9.29.0",
8989
"eslint-ava-rule-tester": "^5.0.1",
9090
"eslint-config-xo": "^0.47.0",
9191
"eslint-doc-generator": "^2.1.2",
@@ -110,7 +110,7 @@
110110
"yaml": "^2.8.0"
111111
},
112112
"peerDependencies": {
113-
"eslint": ">=9.28.0"
113+
"eslint": ">=9.29.0"
114114
},
115115
"ava": {
116116
"files": [

rules/no-useless-error-capture-stack-trace.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,11 @@ const messages = {
1010
[MESSAGE_ID_ERROR]: 'Unnecessary `Error.captureStackTrace(…)` call.',
1111
};
1212

13-
// TODO: Make sure the super class is global
14-
// https://github.com/eslint/eslint/pull/19695
15-
const isSubclassOfBuiltinErrors = node =>
13+
const isSubclassOfBuiltinErrors = (node, context) =>
1614
node?.superClass
1715
&& node.superClass.type === 'Identifier'
18-
&& builtinErrors.includes(node.superClass.name);
16+
&& builtinErrors.includes(node.superClass.name)
17+
&& context.sourceCode.isGlobalReference(node.superClass);
1918

2019
const isClassReference = (node, classNode, context) => {
2120
// `new.target`
@@ -88,15 +87,15 @@ const create = context => {
8887
const errorClass = classStack.at(-1);
8988

9089
if (!(
91-
isSubclassOfBuiltinErrors(errorClass)
90+
isSubclassOfBuiltinErrors(errorClass, context)
9291
&& isClassConstructor(thisScopeStack.at(-1), errorClass)
9392
&& isMethodCall(callExpression, {
9493
object: 'Error',
9594
method: 'captureStackTrace',
9695
argumentsLength: 2,
9796
optionalMember: false,
9897
})
99-
// TODO: Make sure the `object` is global
98+
&& context.sourceCode.isGlobalReference(callExpression.callee.object)
10099
)) {
101100
return;
102101
}

rules/shared/builtin-errors.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const builtinErrors = [
77
'SyntaxError',
88
'TypeError',
99
'URIError',
10-
'InternalError',
1110
'AggregateError',
1211
'SuppressedError',
1312
];

test/no-instanceof-builtins.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ const strictStrategyInvalid = [
2323
'foo instanceof SyntaxError',
2424
'foo instanceof TypeError',
2525
'foo instanceof URIError',
26-
'foo instanceof InternalError',
2726
'foo instanceof AggregateError',
2827
'foo instanceof SuppressedError',
2928

@@ -101,7 +100,6 @@ test.snapshot({
101100
'err instanceof SyntaxError',
102101
'err instanceof TypeError',
103102
'err instanceof URIError',
104-
'err instanceof InternalError',
105103
'err instanceof AggregateError',
106104
'err instanceof SuppressedError',
107105
].map(code => ({code, options: [{useErrorIsError: true, strategy: 'strict'}]})),

test/no-useless-error-capture-stack-trace.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,22 @@ test.snapshot({
8383
}
8484
}
8585
`,
86+
outdent`
87+
class Error {}
88+
class MyError extends Error {
89+
constructor() {
90+
Error.captureStackTrace(this, MyError)
91+
}
92+
}
93+
`,
94+
outdent`
95+
class Error {}
96+
class MyError extends RangeError {
97+
constructor() {
98+
Error.captureStackTrace(this, MyError)
99+
}
100+
}
101+
`,
86102
],
87103
invalid: [
88104
...[
@@ -154,24 +170,6 @@ test.snapshot({
154170
}
155171
)
156172
`,
157-
// This will be fixed when we add global reference check
158-
outdent`
159-
const Error = () => {}
160-
class MyError extends Error {
161-
constructor() {
162-
Error.captureStackTrace(this, MyError)
163-
}
164-
}
165-
`,
166-
// This will be fixed when we add global reference check
167-
outdent`
168-
const Error = () => {}
169-
class MyError extends RangeError {
170-
constructor() {
171-
Error.captureStackTrace(this, MyError)
172-
}
173-
}
174-
`,
175173
],
176174
});
177175

0 commit comments

Comments
 (0)