fix(linter): exclude svelte files from no_unused_vars rule (#8170)

This commit is contained in:
Yuichiro Yamashita 2024-12-30 02:10:33 +09:00 committed by GitHub
parent cfb51f2551
commit f3050d4f31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -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);
}

View file

@ -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")
}
}