Skip to content

Commit 0f19be0

Browse files
committed
fix(oxfmt): Normalize path delimiter on Windows (#14463)
Fixes CI fails on `main` branch. 🙇🏻
1 parent 368829b commit 0f19be0

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

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: No such file or directory (os error 2)
35+
Failed to read config <cwd>/tests/fixtures/config_file/NOT_EXISTS.json: File not found
3636
----------
3737
CLI result: InvalidOptionConfig
3838
----------

apps/oxfmt/tests/tester.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,15 @@ impl Tester {
7979
let regex = Regex::new(r"\d+(?:\.\d+)?s|\d+ms").unwrap();
8080
let output_string = regex.replace_all(output_string, "<variable>ms").into_owned();
8181

82+
// Normalize all backslashes to forward slashes first (for Windows paths)
83+
let output_string = output_string.cow_replace('\\', "/").to_string();
84+
8285
// do not output the current working directory, each machine has a different one
83-
let current_cwd_string = current_cwd.to_str().unwrap();
84-
let current_cwd_string = current_cwd_string.cow_replace('\\', "/").to_string(); // for windows
86+
let current_cwd_string = current_cwd.to_str().unwrap().cow_replace('\\', "/").to_string();
8587
let output_string = output_string.cow_replace(&current_cwd_string, "<cwd>");
8688

8789
// Also replace the test cwd path
88-
let test_cwd_string = self.cwd.to_str().unwrap();
89-
let test_cwd_string = test_cwd_string.cow_replace('\\', "/").to_string(); // for windows
90+
let test_cwd_string = self.cwd.to_str().unwrap().cow_replace('\\', "/").to_string();
9091
let output_string = output_string.cow_replace(&test_cwd_string, "<cwd>");
9192

9293
let full_args_list =

crates/oxc_formatter/src/service/oxfmtrc.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ impl Oxfmtrc {
8787
pub fn from_file(path: &Path) -> Result<Self, String> {
8888
// TODO: Use `simdutf8` like `oxc_linter`?
8989
let mut string = std::fs::read_to_string(path)
90-
.map_err(|err| format!("Failed to read config {}: {err}", path.display()))?;
90+
// Do not include OS error, it differs between platforms
91+
.map_err(|_| format!("Failed to read config {}: File not found", path.display()))?;
9192

9293
// JSONC support - strip comments
9394
json_strip_comments::strip(&mut string)

0 commit comments

Comments
 (0)