Skip to content

Commit 26c5f5a

Browse files
committed
feat(oxfmt): Ignore VCS directories by default (#14616)
Part of #13743
1 parent a9d50a7 commit 26c5f5a

File tree

9 files changed

+44
-3
lines changed

9 files changed

+44
-3
lines changed

apps/oxfmt/src/walk.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ impl ignore::ParallelVisitor for WalkVisitor {
3535
let Some(file_type) = entry.file_type() else {
3636
return ignore::WalkState::Continue;
3737
};
38+
3839
if file_type.is_dir() {
39-
// Skip traversing `.git` directories because `.git` is not a special case for `.hidden(false)`.
40-
// <https://github.com/BurntSushi/ripgrep/issues/3099#issuecomment-3052460027>
41-
if entry.file_name() == ".git" {
40+
// We are setting `.hidden(false)` on the `WalkBuilder` below,
41+
// it means we want to include hidden files and directories.
42+
// However, we (and also Prettier) still skip traversing VCS directories.
43+
// https://prettier.io/docs/ignore#ignoring-files-prettierignore
44+
let dir_name = entry.file_name();
45+
if matches!(dir_name.to_str(), Some(".git" | ".jj" | ".sl" | ".svn" | ".hg")) {
4246
return ignore::WalkState::Skip;
4347
}
4448
} else if let Some(source_type) = get_supported_source_type(entry.path()) {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file should be ignored
2+
const x = 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file should be ignored
2+
const x = 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file should be ignored
2+
const x = 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file should be ignored
2+
const x = 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file should NOT be ignored
2+
const x = 1;
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// This file should NOT be ignored
2+
const y = 2;

apps/oxfmt/tests/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,12 @@ fn config_file_explicit() {
7575
],
7676
);
7777
}
78+
79+
#[test]
80+
fn vcs_dirs_ignored() {
81+
// Test that VCS directories (.git, .jj, .sl, .svn, .hg) are ignored
82+
// but regular directories and root files are processed
83+
Tester::new()
84+
.with_cwd(PathBuf::from("tests/fixtures/vcs_dirs"))
85+
.test_and_snapshot_multiple(&[&["--check"]]);
86+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
source: apps/oxfmt/tests/tester.rs
3+
---
4+
##########
5+
arguments: --check
6+
working directory: tests/fixtures/vcs_dirs
7+
----------
8+
Checking formatting...
9+
regular_dir/test.js (<variable>ms)
10+
root.js (<variable>ms)
11+
12+
Format issues found in above 2 files. Run without `--check` to fix.
13+
Finished in <variable>ms on 2 files using 1 threads.
14+
----------
15+
CLI result: FormatMismatch
16+
----------

0 commit comments

Comments
 (0)