Skip to content

Commit 6dfcd80

Browse files
committed
feat(oxfmt): Search both .json and .jsonc config file (#14848)
Fixes #14575
1 parent a6f720b commit 6dfcd80

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

apps/oxfmt/src/format.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,15 @@ fn load_config(cwd: &Path, config_path: Option<&PathBuf>) -> Result<FormatOption
181181
})
182182
} else {
183183
// If `--config` is not specified, search the nearest config file from cwd upwards
184+
// Support both `.json` and `.jsonc`, but prefer `.json` if both exist
184185
cwd.ancestors().find_map(|dir| {
185-
let config_path = dir.join(".oxfmtrc.json");
186-
if config_path.exists() { Some(config_path) } else { None }
186+
for filename in [".oxfmtrc.json", ".oxfmtrc.jsonc"] {
187+
let config_path = dir.join(filename);
188+
if config_path.exists() {
189+
return Some(config_path);
190+
}
191+
}
192+
None
187193
})
188194
};
189195

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"semi": false
3+
}

apps/oxfmt/tests/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ fn write_mode() {
6161

6262
#[test]
6363
fn config_file_auto_discovery() {
64+
// Tests .json takes priority over .jsonc when both exist
65+
// config_file/ has both .oxfmtrc.json (semi: true) and .oxfmtrc.jsonc (semi: false)
6466
Tester::new()
6567
.with_cwd(PathBuf::from("tests/fixtures/config_file"))
6668
.test_and_snapshot_multiple("config_file_auto_discovery", &[&["--check"]]);

0 commit comments

Comments
 (0)