Skip to content

Commit fbe7eb4

Browse files
committed
fix(linter/filename-case): fix default config when no config is provided (oxc-project#12389)
fixes oxc-project#12276
1 parent fa2d3f1 commit fbe7eb4

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crates/oxc_linter/src/rules/unicorn/filename_case.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl std::ops::Deref for FilenameCase {
2323
}
2424
}
2525

26-
#[derive(Debug, Clone, Default)]
26+
#[derive(Debug, Clone)]
2727
pub struct FilenameCaseConfig {
2828
/// Whether kebab case is allowed.
2929
kebab_case: bool,
@@ -37,6 +37,19 @@ pub struct FilenameCaseConfig {
3737
multi_extensions: bool,
3838
}
3939

40+
impl Default for FilenameCaseConfig {
41+
fn default() -> Self {
42+
Self {
43+
kebab_case: true,
44+
camel_case: false,
45+
snake_case: false,
46+
pascal_case: false,
47+
ignore: None,
48+
multi_extensions: true,
49+
}
50+
}
51+
}
52+
4053
declare_oxc_lint!(
4154
/// ### What it does
4255
///
@@ -141,6 +154,7 @@ impl Rule for FilenameCase {
141154
let mut config = FilenameCaseConfig { multi_extensions: true, ..Default::default() };
142155

143156
if let Some(value) = value.get(0) {
157+
config.kebab_case = false;
144158
if let Some(Value::String(val)) = value.get("ignore") {
145159
config.ignore = RegexBuilder::new(val).build().ok();
146160
}
@@ -380,6 +394,7 @@ fn test() {
380394
"src/foo/foo_bar.test_utils.js",
381395
serde_json::json!([{ "case": "snakeCase", "multipleFileExtensions": false }]),
382396
),
397+
("", None, None, Some(PathBuf::from("foo-bar.tsx"))),
383398
];
384399

385400
let fail = vec![
@@ -425,6 +440,7 @@ fn test() {
425440
"src/foo/foo_bar.test-utils.js",
426441
serde_json::json!([{ "case": "snakeCase", "multipleFileExtensions": false }]),
427442
),
443+
("", None, None, Some(PathBuf::from("FooBar.tsx"))),
428444
];
429445

430446
Tester::new(FilenameCase::NAME, FilenameCase::PLUGIN, pass, fail).test_and_snapshot();

crates/oxc_linter/src/snapshots/unicorn_filename_case.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,3 +155,8 @@ source: crates/oxc_linter/src/tester.rs
155155
╭─[filename_case.tsx:1:1]
156156
╰────
157157
help: Rename the file to 'foo_bar.test_utils.js'
158+
159+
eslint-plugin-unicorn(filename-case): Filename should be in kebab case
160+
╭─[filename_case.tsx:1:1]
161+
╰────
162+
help: Rename the file to 'foo-bar.tsx'

0 commit comments

Comments
 (0)