From 1ac85ee538b2b27e8f945d7a7733cc21d53fbcb0 Mon Sep 17 00:00:00 2001 From: Yosuke Ota Date: Wed, 3 May 2023 09:29:00 +0900 Subject: [PATCH] Fix false positives for type def with script setup in ts no-unused-vars (#191) --- src/script-setup/scope-analyzer.ts | 6 ++++++ .../no-unused-vars/.eslintrc.json | 5 +++++ .../no-unused-vars/valid/type-def.vue | 14 ++++++++++++++ 3 files changed, 25 insertions(+) create mode 100644 test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/.eslintrc.json create mode 100644 test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/valid/type-def.vue diff --git a/src/script-setup/scope-analyzer.ts b/src/script-setup/scope-analyzer.ts index e4f892a..1c078fa 100644 --- a/src/script-setup/scope-analyzer.ts +++ b/src/script-setup/scope-analyzer.ts @@ -205,6 +205,12 @@ function analyzeUsedInTemplateVariables( variable.references.push(reference) reference.resolved = variable + + if (reference.isTypeReference) { + // @typescript-eslint/no-unused-vars treats type references at the same position as recursive references, + // so without this flag it will be marked as unused. + ;(variable as any).eslintUsed = true + } } function processVExpressionContainer(node: VExpressionContainer) { diff --git a/test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/.eslintrc.json b/test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/.eslintrc.json new file mode 100644 index 0000000..7592b0b --- /dev/null +++ b/test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/.eslintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "@typescript-eslint/no-unused-vars": "error" + } +} diff --git a/test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/valid/type-def.vue b/test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/valid/type-def.vue new file mode 100644 index 0000000..ba631bf --- /dev/null +++ b/test/fixtures/integrations/script-setup-with-typescript-eslint/no-unused-vars/valid/type-def.vue @@ -0,0 +1,14 @@ + + + \ No newline at end of file