Skip to content

Commit c9eaca4

Browse files
authored
fix(core): .gitignore is discovered in more scenarios (#6752)
1 parent 31e4396 commit c9eaca4

File tree

5 files changed

+120
-4
lines changed

5 files changed

+120
-4
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@biomejs/biome": minor
3+
---
4+
5+
Fixed [#6646](https://github.com/biomejs/biome/issues/6646): `.gitignore` files
6+
are now picked up even when running Biome from a nested directory, or when the
7+
ignore file itself is ignored through `files.includes`.

crates/biome_cli/tests/cases/vcs_ignored_files.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,43 @@ fn ignores_file_inside_directory() {
190190
result,
191191
));
192192
}
193+
194+
#[test]
195+
fn use_root_gitignore_when_running_from_subdirectory() {
196+
let mut fs = TemporaryFs::new("use_root_gitignore_when_running_from_subdirectory");
197+
let mut console = BufferConsole::default();
198+
199+
fs.create_file(".gitignore", r#"dist/"#);
200+
fs.create_file(
201+
"biome.json",
202+
r#"{
203+
"files": {
204+
"includes": ["packages/**"]
205+
},
206+
"vcs": {
207+
"enabled": true,
208+
"clientKind": "git",
209+
"useIgnoreFile": true
210+
}
211+
}"#,
212+
);
213+
214+
fs.create_file("packages/lib/dist/out.js", r#"foo.call(); bar.call();"#);
215+
fs.create_file("packages/lib/src/in.js", r#"foo.call(); bar.call();"#);
216+
217+
fs.append_to_working_directory("packages/lib");
218+
219+
let result = run_cli_with_dyn_fs(
220+
Box::new(fs.create_os()),
221+
&mut console,
222+
Args::from(["format"].as_slice()),
223+
);
224+
225+
assert_cli_snapshot(SnapshotPayload::new(
226+
module_path!(),
227+
"use_root_gitignore_when_running_from_subdirectory",
228+
fs.create_mem(),
229+
console,
230+
result,
231+
));
232+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `biome.json`
6+
7+
```json
8+
{
9+
"files": {
10+
"includes": ["packages/**"]
11+
},
12+
"vcs": {
13+
"enabled": true,
14+
"clientKind": "git",
15+
"useIgnoreFile": true
16+
}
17+
}
18+
```
19+
20+
## `.gitignore`
21+
22+
```gitignore
23+
dist/
24+
```
25+
26+
## `packages/lib/dist/out.js`
27+
28+
```js
29+
foo.call(); bar.call();
30+
```
31+
32+
## `packages/lib/src/in.js`
33+
34+
```js
35+
foo.call(); bar.call();
36+
```
37+
38+
# Termination Message
39+
40+
```block
41+
format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
42+
43+
× Some errors were emitted while running checks.
44+
45+
46+
47+
```
48+
49+
# Emitted Messages
50+
51+
```block
52+
src/in.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
53+
54+
× Formatter would have printed the following content:
55+
56+
1 │ - foo.call();·bar.call();
57+
1 │ + foo.call();
58+
2 │ + bar.call();
59+
3 │ +
60+
61+
62+
```
63+
64+
```block
65+
Checked 1 file in <TIME>. No fixes applied.
66+
Found 1 error.
67+
```

crates/biome_fs/src/path.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl BiomePath {
170170
pub fn is_dependency(&self) -> bool {
171171
self.path
172172
.components()
173-
.any(|component| component.as_str() == "node_modules")
173+
.any(|component| component.as_str().as_bytes() == b"node_modules")
174174
}
175175

176176
/// Whether this is a file named `package.json`

crates/biome_service/src/workspace/scanner.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,12 +329,14 @@ impl TraversalContext for ScanContext<'_> {
329329
}
330330
Ok(PathKind::File { .. }) => match &self.scan_kind {
331331
ScanKind::KnownFiles | ScanKind::TargetedKnownFiles { .. } => {
332-
path.is_required_during_scan()
333-
&& !path.is_dependency()
334-
&& !self
332+
if path.is_config() {
333+
!self
335334
.workspace
336335
.projects
337336
.is_ignored_by_top_level_config(self.project_key, path)
337+
} else {
338+
path.is_ignore() || path.is_manifest()
339+
}
338340
}
339341
ScanKind::Project => {
340342
if path.is_dependency() {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy