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
5 changes: 5 additions & 0 deletions crates/oxc_linter/src/context/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ impl<'a> ContextHost<'a> {
&mut self.sub_hosts[self.current_sub_host_index.get()]
}

// Whether the current sub host is the first one.
pub fn is_first_sub_host(&self) -> bool {
self.current_sub_host_index.get() == 0
}

/// Shared reference to the [`Semantic`] analysis of current script block.
#[inline]
pub fn semantic(&self) -> &Semantic<'a> {
Expand Down
11 changes: 10 additions & 1 deletion crates/oxc_linter/src/rules/unicorn/filename_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use serde_json::Value;

use crate::{context::LintContext, rule::Rule};
use crate::{
context::{ContextHost, LintContext},
rule::Rule,
};

fn filename_case_diagnostic(message: String, help_message: String) -> OxcDiagnostic {
OxcDiagnostic::warn(message).with_label(Span::default()).with_help(help_message)
Expand Down Expand Up @@ -258,6 +261,10 @@ impl Rule for FilenameCase {

ctx.diagnostic(filename_case_diagnostic(message, help_message));
}

fn should_run(&self, ctx: &ContextHost<'_>) -> bool {
ctx.is_first_sub_host()
}
}

#[test]
Expand Down Expand Up @@ -441,6 +448,8 @@ fn test() {
serde_json::json!([{ "case": "snakeCase", "multipleFileExtensions": false }]),
),
("", None, None, Some(PathBuf::from("FooBar.tsx"))),
// should only report once
("<script></script><script setup></script>", None, None, Some(PathBuf::from("FooBar.vue"))),
];

Tester::new(FilenameCase::NAME, FilenameCase::PLUGIN, pass, fail).test_and_snapshot();
Expand Down
7 changes: 7 additions & 0 deletions crates/oxc_linter/src/snapshots/unicorn_filename_case.snap
Original file line number Diff line number Diff line change
Expand Up @@ -160,3 +160,10 @@ source: crates/oxc_linter/src/tester.rs
╭─[filename_case.tsx:1:1]
╰────
help: Rename the file to 'foo-bar.tsx'

⚠ eslint-plugin-unicorn(filename-case): Filename should be in kebab case
╭─[filename_case.tsx:1:9]
1 │ <script></script><script setup></script>
· ▲
╰────
help: Rename the file to 'foo-bar.vue'
Loading