From f3050d4f310c748f1ffc7a4c5122c68a702dad8d Mon Sep 17 00:00:00 2001 From: Yuichiro Yamashita Date: Mon, 30 Dec 2024 02:10:33 +0900 Subject: [PATCH] fix(linter): exclude svelte files from `no_unused_vars` rule (#8170) --- apps/oxlint/src/lint.rs | 2 +- crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/oxlint/src/lint.rs b/apps/oxlint/src/lint.rs index ffe842a861374..0e1b55444292e 100644 --- a/apps/oxlint/src/lint.rs +++ b/apps/oxlint/src/lint.rs @@ -628,7 +628,7 @@ mod test { let args = &["fixtures/svelte/debugger.svelte"]; let result = test(args); assert_eq!(result.number_of_files, 1); - assert_eq!(result.number_of_warnings, 2); + assert_eq!(result.number_of_warnings, 1); assert_eq!(result.number_of_errors, 0); } diff --git a/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs b/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs index 6ae3bb022f932..9a5f605ca6ec7 100644 --- a/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs +++ b/crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs @@ -214,12 +214,12 @@ impl Rule for NoUnusedVars { } fn should_run(&self, ctx: &ContextHost) -> bool { - // ignore .d.ts and vue files. + // ignore .d.ts and vue/svelte files. // 1. declarations have side effects (they get merged together) - // 2. vue scripts declare variables that get used in the template, which + // 2. vue/svelte scripts declare variables that get used in the template, which // we can't detect !ctx.source_type().is_typescript_definition() - && !ctx.file_path().extension().is_some_and(|ext| ext == "vue") + && !ctx.file_path().extension().is_some_and(|ext| ext == "vue" || ext == "svelte") } }