Skip to content

Commit 6f17392

Browse files
autofix-ci[bot]leaysgur
authored andcommitted
[autofix.ci] apply automated fixes
1 parent 63b0acd commit 6f17392

12 files changed

+40
-112
lines changed

apps/oxfmt/src/format.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ pub struct FormatRunner {
2525
cwd: PathBuf,
2626
}
2727

28-
const DEFAULT_CONFIG_NAME: &str = ".oxfmtrc.json";
29-
3028
impl FormatRunner {
3129
/// Creates a new FormatRunner instance.
3230
///
@@ -177,34 +175,36 @@ impl FormatRunner {
177175
}
178176
}
179177

180-
/// Load configuration file
181-
///
178+
const DEFAULT_CONFIG_NAMES: &[&str] = &[".oxfmtrc.json", ".oxfmtrc.jsonc"];
179+
182180
/// # Errors
183181
///
184182
/// Returns error if:
185183
/// - Config file is specified but not found or invalid
186184
/// - Config file parsing fails
187185
fn load_config(cwd: &Path, config: Option<&PathBuf>) -> Result<FormatOptions, String> {
188-
// If --config is explicitly specified, use that path directly
186+
// If `--config` is explicitly specified, use that path directly
189187
if let Some(config_path) = config {
190188
let full_path =
191189
if config_path.is_absolute() { config_path.clone() } else { cwd.join(config_path) };
192190

191+
// This will error if the file does not exist or is invalid
193192
let oxfmtrc = Oxfmtrc::from_file(&full_path)?;
194193
return oxfmtrc.into_format_options();
195194
}
196195

197-
// If --config is not specified, search for default config file
198-
// starting from cwd and walking up to root
196+
// If `--config` is not specified, search the nearest config file from cwd upwards
199197
let mut current_dir = cwd;
200198
loop {
201-
let config_path = current_dir.join(DEFAULT_CONFIG_NAME);
202-
if config_path.exists() {
203-
let oxfmtrc = Oxfmtrc::from_file(&config_path)?;
204-
return oxfmtrc.into_format_options();
199+
// Try each config name in order
200+
for config_name in DEFAULT_CONFIG_NAMES {
201+
let config_path = current_dir.join(config_name);
202+
if config_path.exists() {
203+
let oxfmtrc = Oxfmtrc::from_file(&config_path)?;
204+
return oxfmtrc.into_format_options();
205+
}
205206
}
206207

207-
// Move to parent directory, or break if at root
208208
if let Some(parent) = current_dir.parent() {
209209
current_dir = parent;
210210
} else {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
// Supports JSONC!
3+
"semicorons": false
4+
}

apps/oxfmt/tests/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ fn config_file_auto_discovery() {
6868
#[test]
6969
fn config_file_explicit() {
7070
Tester::new().with_cwd(PathBuf::from("tests/fixtures/config_file")).test_and_snapshot_multiple(
71-
&[&["--check", "--config", "./fmt.json"], &["--check", "--config", "NOT_EXISTS.json"]],
71+
&[
72+
&["--check", "--config", "./fmt.json"],
73+
&["--check", "--config", "./fmt.jsonc"],
74+
&[ "--check", "--config", "NOT_EXISTS.json" ],
75+
],
7276
);
7377
}

apps/oxfmt/tests/snapshots/tests__fixtures__config_file_--check --config .__fmt.json --check --config .__NOT_EXISTS.json@oxfmt.snap

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ Finished in <variable>ms on 1 files using 1 threads.
1414
CLI result: FormatMismatch
1515
----------
1616

17+
##########
18+
arguments: --check --config ./fmt.jsonc
19+
working directory: tests/fixtures/config_file
20+
----------
21+
Checking formatting...
22+
nested/deep/test.js (<variable>ms)
23+
24+
Format issues found in above 1 files. Run without `--check` to fix.
25+
Finished in <variable>ms on 1 files using 1 threads.
26+
----------
27+
CLI result: FormatMismatch
28+
----------
29+
1730
##########
1831
arguments: --check --config NOT_EXISTS.json
1932
working directory: tests/fixtures/config_file

apps/oxfmt/tests/snapshots/tests__fixtures__config_file__root_--check test.js@oxfmt.snap

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/oxfmt/tests/snapshots/tests__fixtures__config_file__root_--check@oxfmt.snap

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/oxfmt/tests/snapshots/tests__fixtures__config_file__root__nested_--check test.js@oxfmt.snap

Lines changed: 0 additions & 14 deletions
This file was deleted.

apps/oxfmt/tests/snapshots/tests__fixtures__config_file__root__nested__deep_--check --config ..__..__.oxfmtrc.json test.js@oxfmt.snap

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)