Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions apps/oxfmt/src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ impl ignore::ParallelVisitor for WalkVisitor {
let Some(file_type) = entry.file_type() else {
return ignore::WalkState::Continue;
};

if file_type.is_dir() {
// Skip traversing `.git` directories because `.git` is not a special case for `.hidden(false)`.
// <https://github.com/BurntSushi/ripgrep/issues/3099#issuecomment-3052460027>
if entry.file_name() == ".git" {
// We are setting `.hidden(false)` on the `WalkBuilder` below,
// it means we want to include hidden files and directories.
// However, we (and also Prettier) still skip traversing VCS directories.
// https://prettier.io/docs/ignore#ignoring-files-prettierignore
let dir_name = entry.file_name();
if matches!(dir_name.to_str(), Some(".git" | ".jj" | ".sl" | ".svn" | ".hg")) {
return ignore::WalkState::Skip;
}
} else if let Some(source_type) = get_supported_source_type(entry.path()) {
Expand Down
2 changes: 2 additions & 0 deletions apps/oxfmt/tests/fixtures/vcs_dirs/.hg/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should be ignored
const x = 1;
2 changes: 2 additions & 0 deletions apps/oxfmt/tests/fixtures/vcs_dirs/.jj/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should be ignored
const x = 1;
2 changes: 2 additions & 0 deletions apps/oxfmt/tests/fixtures/vcs_dirs/.sl/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should be ignored
const x = 1;
2 changes: 2 additions & 0 deletions apps/oxfmt/tests/fixtures/vcs_dirs/.svn/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should be ignored
const x = 1;
2 changes: 2 additions & 0 deletions apps/oxfmt/tests/fixtures/vcs_dirs/regular_dir/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should NOT be ignored
const x = 1;
2 changes: 2 additions & 0 deletions apps/oxfmt/tests/fixtures/vcs_dirs/root.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This file should NOT be ignored
const y = 2;
9 changes: 9 additions & 0 deletions apps/oxfmt/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,12 @@ fn config_file_explicit() {
],
);
}

#[test]
fn vcs_dirs_ignored() {
// Test that VCS directories (.git, .jj, .sl, .svn, .hg) are ignored
// but regular directories and root files are processed
Tester::new()
.with_cwd(PathBuf::from("tests/fixtures/vcs_dirs"))
.test_and_snapshot_multiple(&[&["--check"]]);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
source: apps/oxfmt/tests/tester.rs
---
##########
arguments: --check
working directory: tests/fixtures/vcs_dirs
----------
Checking formatting...
regular_dir/test.js (<variable>ms)
root.js (<variable>ms)

Format issues found in above 2 files. Run without `--check` to fix.
Finished in <variable>ms on 2 files using 1 threads.
----------
CLI result: FormatMismatch
----------
Loading