Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 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 @@ -215,12 +215,15 @@ impl Rule for NoUnusedVars {
}

fn should_run(&self, ctx: &ContextHost) -> bool {
// ignore .d.ts and vue/svelte files.
// ignore .d.ts and vue/svelte/astro files.
// 1. declarations have side effects (they get merged together)
// 2. vue/svelte scripts declare variables that get used in the template, which
// 2. vue/svelte/astro 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" || ext == "svelte")
&& !ctx
.file_path()
.extension()
.is_some_and(|ext| ext == "vue" || ext == "svelte" || ext == "astro")
}
}

Expand Down
39 changes: 39 additions & 0 deletions crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Test cases created by oxc maintainers

use std::path::PathBuf;

use serde_json::json;

use super::NoUnusedVars;
Expand Down Expand Up @@ -1310,6 +1312,43 @@ fn test_report_vars_only_used_as_types() {
.test();
}

#[test]
fn test_should_run() {
let pass = vec![
(
r#"<script setup lang="ts"> import * as vue from 'vue' </script>"#,
None,
None,
Some(PathBuf::from("src/foo/bar.vue")),
),
(
r"---
import Welcome from '../components/Welcome.astro';
import Layout from '../layouts/Layout.astro';
---
<Layout>
<Welcome />
</Layout>",
None,
None,
Some(PathBuf::from("src/foo/bar.astro")),
),
(
r"<script>
import Nested from './Nested.svelte';
</script>
<Nested answer={42} />",
None,
None,
Some(PathBuf::from("src/foo/bar.svelte")),
),
];

Tester::new(NoUnusedVars::NAME, NoUnusedVars::PLUGIN, pass, vec![])
.intentionally_allow_no_fix_tests()
.test();
}

// #[test]
// fn test_template() {
// let pass = vec![];
Expand Down
Loading