Skip to content

Commit af4b28d

Browse files
committed
feat(oxfmt): Search both .json and .jsonc config file
1 parent aa024d9 commit af4b28d

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-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: 3 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"]]);
@@ -86,6 +88,7 @@ fn config_file_explicit() {
8688
);
8789
}
8890

91+
8992
#[test]
9093
fn vcs_dirs_ignored() {
9194
// Test that VCS directories (.git, .jj, .sl, .svn, .hg) are ignored

0 commit comments

Comments
 (0)