From a897a4230b8db946239d1d11e4691aed08687a88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=94=AF=E7=84=B6?= Date: Wed, 6 Dec 2023 10:45:50 +0800 Subject: [PATCH] fix: do not use `context.getScope()` --- lib/rules/no-unsupported-features.js | 1 - lib/util/check-prefer-global.js | 8 +++++--- lib/util/check-unsupported-builtins.js | 4 +--- package.json | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/rules/no-unsupported-features.js b/lib/rules/no-unsupported-features.js index b4db557f..4fca31d3 100644 --- a/lib/rules/no-unsupported-features.js +++ b/lib/rules/no-unsupported-features.js @@ -1098,7 +1098,6 @@ module.exports = { * @returns {void} */ function* getReferences(names) { - // TODO: ??? const globalScope = sourceCode.getScope?.(sourceCode.ast) ?? context.getScope() //TODO: remove context.getScope() when dropping support for ESLint < v9 diff --git a/lib/util/check-prefer-global.js b/lib/util/check-prefer-global.js index d2a75cc1..4db299a3 100644 --- a/lib/util/check-prefer-global.js +++ b/lib/util/check-prefer-global.js @@ -32,9 +32,8 @@ class Verifier { verifyToPreferGlobals() { const { context, trackMap } = this const sourceCode = context.sourceCode ?? context.getSourceCode() - // TODO: sourceCode.ast is the correct node? const scope = - sourceCode.getScope?.(context.sourceCode.ast) ?? context.getScope() + sourceCode.getScope?.(sourceCode.ast) ?? context.getScope() const tracker = new ReferenceTracker(scope, { mode: "legacy", }) @@ -55,7 +54,10 @@ class Verifier { */ verifyToPreferModules() { const { context, trackMap } = this - const tracker = new ReferenceTracker(context.getScope()) + const sourceCode = context.sourceCode ?? context.getSourceCode() + const scope = + sourceCode.getScope?.(sourceCode.ast) ?? context.getScope() + const tracker = new ReferenceTracker(scope) for (const { node } of tracker.iterateGlobalReferences( trackMap.globals diff --git a/lib/util/check-unsupported-builtins.js b/lib/util/check-unsupported-builtins.js index d8d3dcf7..592f0447 100644 --- a/lib/util/check-unsupported-builtins.js +++ b/lib/util/check-unsupported-builtins.js @@ -86,9 +86,7 @@ module.exports.checkUnsupportedBuiltins = function checkUnsupportedBuiltins( ) { const options = parseOptions(context) const sourceCode = context.sourceCode ?? context.getSourceCode() - // TODO: context.sourceCode.ast is the correct node? - const scope = - sourceCode.getScope?.(context.sourceCode.ast) ?? context.getScope() + const scope = sourceCode.getScope?.(sourceCode.ast) ?? context.getScope() const tracker = new ReferenceTracker(scope, { mode: "legacy" }) const references = [ ...tracker.iterateCjsReferences(trackMap.modules || {}), diff --git a/package.json b/package.json index d63ce26b..641e25ea 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "builtins": "^5.0.1", - "eslint-plugin-es-x": "^7.1.0", + "eslint-plugin-es-x": "^7.5.0", "get-tsconfig": "^4.7.0", "ignore": "^5.2.4", "is-builtin-module": "^3.2.1",