Skip to content

Commit fba31fa

Browse files
authored
fix(linter): patch @typescript-eslint/scope manager (#15214)
- Part of #14827 - Fixes the bug noticed in a review in #14890 (comment) - Originally reported as typescript-eslint/typescript-eslint#11714 - Originally fixed in typescript-eslint/typescript-eslint#11715 - Patching in oxlint because neither the bug nor the fix has been reviewed in the `typescript-eslint` org.
1 parent b4b0ed8 commit fba31fa

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

apps/oxlint/test/fixtures/sourceCode_scope_methods/output.snap.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
8 | };
107107
`----
108108
109-
x scope-plugin(scope): isGlobalReference(Math): false
109+
x scope-plugin(scope): isGlobalReference(Math): true
110110
,-[files/index.js:7:28]
111111
6 | return function innerFunction() {
112112
7 | return localConstant + Math.PI;
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
diff --git a/dist/scope/ScopeBase.js b/dist/scope/ScopeBase.js
2+
index 5e07a7c3fb4670b2ce4fa405798d2f27c0084fef..b773c16431a860580dd9408c6127b06256c41c3b 100644
3+
--- a/dist/scope/ScopeBase.js
4+
+++ b/dist/scope/ScopeBase.js
5+
@@ -8,6 +8,7 @@ const ID_1 = require("../ID");
6+
const Reference_1 = require("../referencer/Reference");
7+
const variable_1 = require("../variable");
8+
const ScopeType_1 = require("./ScopeType");
9+
+const ImplicitLibVariable_1 = require("../variable/ImplicitLibVariable");
10+
/**
11+
* Test if scope is strict
12+
*/
13+
@@ -254,6 +255,10 @@ class ScopeBase {
14+
return false;
15+
}
16+
// variable exists on the scope
17+
+ // implicit lib variables should always be resolved statically
18+
+ if (variable instanceof ImplicitLibVariable_1.ImplicitLibVariable) {
19+
+ return true;
20+
+ }
21+
// in module mode, we can statically resolve everything, regardless of its decl type
22+
if (scopeManager.isModule()) {
23+
return true;
24+
@@ -306,6 +311,11 @@ class ScopeBase {
25+
set.set(name, variable);
26+
variables.push(variable);
27+
}
28+
+ else if (variable instanceof ImplicitLibVariable_1.ImplicitLibVariable &&
29+
+ nameOrVariable instanceof ImplicitLibVariable_1.ImplicitLibVariable) {
30+
+ variable.isTypeVariable ||= nameOrVariable.isTypeVariable;
31+
+ variable.isValueVariable ||= nameOrVariable.isValueVariable;
32+
+ }
33+
if (def) {
34+
variable.defs.push(def);
35+
this.addDeclaredVariablesOfNode(variable, def.node);
36+
diff --git a/dist/variable/ImplicitLibVariable.d.ts b/dist/variable/ImplicitLibVariable.d.ts
37+
index 6c967519e4bf1ce20c0fc5dd60e5bde2e3ae9ef2..2c4ef8ffb2aba72467d6e7679f042cffabdb03ab 100644
38+
--- a/dist/variable/ImplicitLibVariable.d.ts
39+
+++ b/dist/variable/ImplicitLibVariable.d.ts
40+
@@ -18,10 +18,10 @@ export declare class ImplicitLibVariable extends ESLintScopeVariable implements
41+
/**
42+
* `true` if the variable is valid in a type context, false otherwise
43+
*/
44+
- readonly isTypeVariable: boolean;
45+
+ isTypeVariable: boolean;
46+
/**
47+
* `true` if the variable is valid in a value context, false otherwise
48+
*/
49+
- readonly isValueVariable: boolean;
50+
+ isValueVariable: boolean;
51+
constructor(scope: Scope, name: string, { eslintImplicitGlobalSetting, isTypeVariable, isValueVariable, writeable, }: ImplicitLibVariableOptions);
52+
}

pnpm-lock.yaml

Lines changed: 7 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pnpm-workspace.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,7 @@ onlyBuiltDependencies:
2121
- '@vscode/vsce-sign@2.0.8'
2222
- esbuild@0.25.11
2323

24+
patchedDependencies:
25+
'@typescript-eslint/scope-manager': patches/@typescript-eslint__scope-manager.patch
26+
2427
verifyDepsBeforeRun: install

0 commit comments

Comments
 (0)