Skip to content

Commit f0c19eb

Browse files
autofix-ci[bot]leaysgur
authored andcommitted
[autofix.ci] apply automated fixes (attempt 2/3)
1 parent f0c743a commit f0c19eb

10 files changed

+51
-28
lines changed

apps/oxfmt/src/format.rs

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl FormatRunner {
175175
}
176176
}
177177

178-
const DEFAULT_CONFIG_NAMES: &[&str] = &[".oxfmtrc.json", ".oxfmtrc.jsonc"];
178+
const DEFAULT_OXFMTRC: &str = ".oxfmtrc.json";
179179

180180
/// # Errors
181181
///
@@ -185,30 +185,23 @@ const DEFAULT_CONFIG_NAMES: &[&str] = &[".oxfmtrc.json", ".oxfmtrc.jsonc"];
185185
fn load_config(cwd: &Path, config: Option<&PathBuf>) -> Result<FormatOptions, String> {
186186
// If `--config` is explicitly specified, use that path directly
187187
if let Some(config_path) = config {
188-
let full_path =
189-
if config_path.is_absolute() { config_path.clone() } else { cwd.join(config_path) };
188+
let full_path = if config_path.is_absolute() {
189+
PathBuf::from(config_path)
190+
} else {
191+
cwd.join(config_path)
192+
};
190193

191194
// This will error if the file does not exist or is invalid
192195
let oxfmtrc = Oxfmtrc::from_file(&full_path)?;
193196
return oxfmtrc.into_format_options();
194197
}
195198

196199
// If `--config` is not specified, search the nearest config file from cwd upwards
197-
let mut current_dir = cwd;
198-
loop {
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-
}
206-
}
207-
208-
if let Some(parent) = current_dir.parent() {
209-
current_dir = parent;
210-
} else {
211-
break;
200+
for dir in cwd.ancestors() {
201+
let config_path = dir.join(DEFAULT_OXFMTRC);
202+
if config_path.exists() {
203+
let oxfmtrc = Oxfmtrc::from_file(&config_path)?;
204+
return oxfmtrc.into_format_options();
212205
}
213206
}
214207

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"semicorons": false
2+
"semicolons": "always"
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"semicorons": false
2+
"semicolons": "always"
33
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
// Supports JSONC!
3-
"semicorons": false
3+
"semicolons": "always"
44
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"semicorons": false
2+
"semicolons": "always"
33
}

apps/oxfmt/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ fn config_file_explicit() {
7171
&[
7272
&["--check", "--config", "./fmt.json"],
7373
&["--check", "--config", "./fmt.jsonc"],
74-
&[ "--check", "--config", "NOT_EXISTS.json" ],
74+
&["--check", "--config", "NOT_EXISTS.json"],
7575
],
7676
);
7777
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ arguments: --check --config NOT_EXISTS.json
3232
working directory: tests/fixtures/config_file
3333
----------
3434
Failed to load configuration file.
35-
Failed to read config <cwd>/tests/fixtures/config_file/NOT_EXISTS.json: Os { code: 2, kind: NotFound, message: "No such file or directory" }
35+
Failed to read config <cwd>/tests/fixtures/config_file/NOT_EXISTS.json: No such file or directory (os error 2)
3636
----------
3737
CLI result: InvalidOptionConfig
3838
----------
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: apps/oxfmt/tests/tester.rs
3+
---
4+
##########
5+
arguments: --check
6+
working directory: tests/fixtures/config_file/nested
7+
----------
8+
Checking formatting...
9+
deep/test.js (<variable>ms)
10+
11+
Format issues found in above 1 files. Run without `--check` to fix.
12+
Finished in <variable>ms on 1 files using 1 threads.
13+
----------
14+
CLI result: FormatMismatch
15+
----------
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
source: apps/oxfmt/tests/tester.rs
3+
---
4+
##########
5+
arguments: --check
6+
working directory: tests/fixtures/config_file/nested/deep
7+
----------
8+
Checking formatting...
9+
test.js (<variable>ms)
10+
11+
Format issues found in above 1 files. Run without `--check` to fix.
12+
Finished in <variable>ms on 1 files using 1 threads.
13+
----------
14+
CLI result: FormatMismatch
15+
----------

crates/oxc_formatter/src/service/oxfmtrc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,17 @@ impl Oxfmtrc {
8686
pub fn from_file(path: &Path) -> Result<Self, String> {
8787
// TODO: Use `simdutf8` like `oxc_linter`?
8888
let mut string = std::fs::read_to_string(path)
89-
.map_err(|e| format!("Failed to read config {}: {e:?}", path.display()))?;
89+
.map_err(|err| format!("Failed to read config {}: {err}", path.display()))?;
9090

9191
// JSONC support - strip comments
9292
json_strip_comments::strip(&mut string)
93-
.map_err(|e| format!("Failed to strip comments from {}: {e:?}", path.display()))?;
93+
.map_err(|err| format!("Failed to strip comments from {}: {err}", path.display()))?;
9494

9595
let json = serde_json::from_str::<serde_json::Value>(&string)
96-
.map_err(|e| format!("Failed to parse config {}: {e}", path.display()))?;
96+
.map_err(|err| format!("Failed to parse config {}: {err}", path.display()))?;
9797

9898
Self::deserialize(&json)
99-
.map_err(|e| format!("Failed to deserialize config {}: {e:?}", path.display()))
99+
.map_err(|err| format!("Failed to deserialize config {}: {err}", path.display()))
100100
}
101101

102102
/// # Errors

0 commit comments

Comments
 (0)