Skip to content

Commit

Permalink
fix(linter): false positive for filename_case where filename doesn't …
Browse files Browse the repository at this point in the history
…have a proper casing (#2032)
  • Loading branch information
Boshen authored Jan 15, 2024
1 parent 68606c4 commit 3b40fbd
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions crates/oxc_linter/src/rules/unicorn/filename_case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Rule for FilenameCase {
fn run_once<'a>(&self, ctx: &LintContext<'_>) {
let Some(filename) = ctx.file_path().file_stem().and_then(|s| s.to_str()) else { return };

let mut case_name = "";
let mut case_name = None;

let cases = [
(Case::Kebab, "kebab", self.kebab_case),
Expand All @@ -113,11 +113,13 @@ impl Rule for FilenameCase {
if condition {
return;
}
case_name = name;
case_name.replace(name);
}
}

ctx.diagnostic(FilenameCaseDiagnostic(Span::default(), case_name));
if let Some(case_name) = case_name {
ctx.diagnostic(FilenameCaseDiagnostic(Span::default(), case_name));
}
}
}

Expand All @@ -131,6 +133,7 @@ fn test() {
("", None, None, Some(PathBuf::from("foo/bar/baz/Que.tsx"))),
// should pass - camel_case, pascal_case both allowed
("", None, None, Some(PathBuf::from("foo/bar/baz/QueAbc.tsx"))),
("", None, None, Some(PathBuf::from("ansiHTML.tsx"))),
];
let fail = vec![
// should pass - by default kebab_case is not allowed
Expand Down

0 comments on commit 3b40fbd

Please sign in to comment.