diff --git a/packages/eslint-plugin/src/rules/no-unused-vars.ts b/packages/eslint-plugin/src/rules/no-unused-vars.ts index aac30b87a9e2..6b96151e959c 100644 --- a/packages/eslint-plugin/src/rules/no-unused-vars.ts +++ b/packages/eslint-plugin/src/rules/no-unused-vars.ts @@ -238,9 +238,17 @@ export default util.createRule({ } } - if (!hasRestSpreadSibling(variable)) { - unusedVariablesReturn.push(variable); + if (hasRestSpreadSibling(variable)) { + continue; + } + + // in case another rule has run and used the collectUnusedVariables, + // we want to ensure our selectors that marked variables as used are respected + if (variable.eslintUsed) { + continue; } + + unusedVariablesReturn.push(variable); } return unusedVariablesReturn; diff --git a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts index 15f19019239a..ea2eb03d7336 100644 --- a/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unused-vars/no-unused-vars.test.ts @@ -1,4 +1,5 @@ import rule from '../../../src/rules/no-unused-vars'; +import { collectUnusedVariables } from '../../../src/util'; import { noFormat, RuleTester } from '../../RuleTester'; const ruleTester = new RuleTester({ @@ -10,6 +11,12 @@ const ruleTester = new RuleTester({ parser: '@typescript-eslint/parser', }); +// this is used to ensure that the caching the utility does does not impact the results done by no-unused-vars +ruleTester.defineRule('collect-unused-vars', context => { + collectUnusedVariables(context); + return {}; +}); + ruleTester.run('no-unused-vars', rule, { valid: [ ` @@ -960,8 +967,17 @@ interface _Foo { // ignored by pattern, even though it's only self-referenced options: [{ varsIgnorePattern: '^_' }], }, - // https://github.com/ocavue/typescript-eslint-issue-2831/blob/master/index.ts - 'export const classes = [class C1 {}, class C2 {}, class C3 {}];', + // https://github.com/typescript-eslint/typescript-eslint/issues/2844 + ` +/* eslint collect-unused-vars: "error" */ +declare module 'next-auth' { + interface User { + id: string; + givenName: string; + familyName: string; + } +} + `, ], invalid: [ pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy