@@ -245,10 +245,12 @@ function wrapContextToOverrideTokenMethods(context, tokenStore, options) {
245245 tokenStore
246246 )
247247
248+ /** @type {WeakMap<ASTNode, import('eslint').Scope.ScopeManager> } */
248249 const containerScopes = new WeakMap ( )
249250
250251 /**
251252 * @param {ASTNode } node
253+ * @returns {import('eslint').Scope.ScopeManager|null }
252254 */
253255 function getContainerScope ( node ) {
254256 const exprContainer = getVExpressionContainer ( node )
@@ -260,9 +262,11 @@ function wrapContextToOverrideTokenMethods(context, tokenStore, options) {
260262 return cache
261263 }
262264 const programNode = eslintSourceCode . ast
263- const parserOptions = context . parserOptions || { }
265+ const parserOptions =
266+ context . languageOptions ?. parserOptions ?? context . parserOptions ?? { }
264267 const ecmaFeatures = parserOptions . ecmaFeatures || { }
265- const ecmaVersion = parserOptions . ecmaVersion || 2020
268+ const ecmaVersion =
269+ context . languageOptions ?. ecmaVersion ?? parserOptions . ecmaVersion ?? 2020
266270 const sourceType = programNode . sourceType
267271 try {
268272 const eslintScope = createRequire ( require . resolve ( 'eslint' ) ) (
@@ -297,7 +301,6 @@ function wrapContextToOverrideTokenMethods(context, tokenStore, options) {
297301 getSourceCode ( ) {
298302 return sourceCode
299303 } ,
300- // @ts -expect-error -- Added in ESLint v8.40
301304 get sourceCode ( ) {
302305 return sourceCode
303306 } ,
@@ -310,11 +313,11 @@ function wrapContextToOverrideTokenMethods(context, tokenStore, options) {
310313 */
311314 function getDeclaredVariables ( node ) {
312315 const scope = getContainerScope ( node )
313- if ( scope ) {
314- return scope . getDeclaredVariables ( node )
315- }
316-
317- return context . getDeclaredVariables ( node )
316+ return (
317+ scope ? .getDeclaredVariables ?. ( node ) ??
318+ context . getDeclaredVariables ?. ( node ) ??
319+ [ ]
320+ )
318321 }
319322}
320323
@@ -1939,6 +1942,10 @@ module.exports = {
19391942 withinTypeNode,
19401943 findVariableByIdentifier,
19411944 getScope,
1945+ /**
1946+ * Marks a variable with the given name in the current scope as used. This affects the no-unused-vars rule.
1947+ */
1948+ markVariableAsUsed,
19421949 /**
19431950 * Checks whether the given node is in export default.
19441951 * @param {ASTNode } node
@@ -2562,6 +2569,26 @@ function isTypeScriptFile(path) {
25622569 return path . endsWith ( '.ts' ) || path . endsWith ( '.tsx' ) || path . endsWith ( '.mts' )
25632570}
25642571
2572+ // ------------------------------------------------------------------------------
2573+ // ESLint Helpers
2574+ // ------------------------------------------------------------------------------
2575+ /**
2576+ * Marks a variable with the given name in the current scope as used. This affects the no-unused-vars rule.
2577+ * @param {RuleContext } context
2578+ * @param {string } name
2579+ * @param {ASTNode } node The node to get the current scope.
2580+ */
2581+ function markVariableAsUsed ( context , name , node ) {
2582+ const sourceCode = context . getSourceCode ( )
2583+ if ( sourceCode . markVariableAsUsed ) {
2584+ sourceCode . markVariableAsUsed ( name , node )
2585+ } else {
2586+ // This function does not use the given node, but the currently visited node.
2587+ // If we need to determine the scope of a given node, we need to implement it yourself.
2588+ context . markVariableAsUsed ?. ( name )
2589+ }
2590+ }
2591+
25652592// ------------------------------------------------------------------------------
25662593// Vue Helpers
25672594// ------------------------------------------------------------------------------
0 commit comments