Skip to content

Commit

Permalink
fix(linter): exclude svelte files from no_unused_vars rule (#8170)
Browse files Browse the repository at this point in the history
  • Loading branch information
baseballyama authored Dec 29, 2024
1 parent cfb51f2 commit f3050d4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion apps/oxlint/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down

0 comments on commit f3050d4

Please sign in to comment.