Skip to content

Commit

Permalink
refactor: don't check dir and symlink against include (#1995)
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos authored Mar 8, 2024
1 parent 446b45c commit b96600f
Show file tree
Hide file tree
Showing 9 changed files with 420 additions and 16 deletions.
33 changes: 32 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,38 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

Previously, Biome processed all files in the traversed hierarchy,
even the files under an ignored directory.
Now, it completly skip the content of ignored directories.
Now, it completely skips the content of ignored directories.

For now, directories cannot be ignored using `files.include` in the configuration file.
This is a known limitation that we want to address in a future release.

For instance, if you have a project with a folder `src` and a folder `test`,
the following configuration doesn't completely ignore `test`.

```json
{
"files": {
"include": ["src"]
}
}
```

Biome will traverse `test`,
however all files of the directory are correctly ignored.
This can result in file system errors,
if Biome encounters dangling symbolic links or files with higher permissions.

To avoid traversing the `test` directory,
you should ignore the directory using `ignore`:

```json
{
"files": {
"include": ["src"],
"ignore": ["test"]
}
}
```

- Fix [#1508](https://github.com/biomejs/biome/issues/1508) by excluding deleted files from being processed. Contributed
by @ematipico
Expand Down
159 changes: 159 additions & 0 deletions crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1137,6 +1137,165 @@ fn fs_files_ignore_symlink() {
));
}

#[test]
fn include_files_in_subdir() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
let config = r#"{
"files": {
"include": ["./**/*.js"]
}
}"#;

let root_path = temp_dir().join("include_files_in_subdir");
let _ = remove_dir_all(&root_path);
create_dir(&root_path).unwrap();
File::create(root_path.join("biome.json"))
.unwrap()
.write_all(config.as_bytes())
.unwrap();
let subdir = root_path.join("subdir");
create_dir(&subdir).unwrap();
File::create(subdir.join("file.js"))
.unwrap()
.write_all(APPLY_SUGGESTED_BEFORE.as_bytes())
.unwrap();

let result = run_cli(
DynRef::Owned(Box::new(OsFileSystem::new(root_path.clone()))),
&mut console,
Args::from([("lint"), root_path.display().to_string().as_str()].as_slice()),
);

remove_dir_all(root_path).unwrap();

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"include_files_in_subdir",
fs,
console,
result,
));
}

#[test]
fn include_files_in_symlinked_subdir() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
let config = r#"{
"files": {
"include": ["./**/*.js"]
}
}"#;

let root_path = temp_dir().join("include_files_in_symlinked_subdir");
let _ = remove_dir_all(&root_path);
create_dir(&root_path).unwrap();

let symlinked = root_path.join("symlinked");
create_dir(&symlinked).unwrap();
File::create(symlinked.join("file.js"))
.unwrap()
.write_all(APPLY_SUGGESTED_BEFORE.as_bytes())
.unwrap();

let subroot_path = root_path.join("subroot");
create_dir(&subroot_path).unwrap();
File::create(subroot_path.join("biome.json"))
.unwrap()
.write_all(config.as_bytes())
.unwrap();

#[cfg(target_family = "unix")]
{
symlink(root_path.join("symlinked"), subroot_path.join("symlink")).unwrap();
}

#[cfg(target_os = "windows")]
{
check_windows_symlink!(symlink_file(
root_path.join("symlinked"),
subroot_path.join("symlink")
));
}

let result = run_cli(
DynRef::Owned(Box::new(OsFileSystem::new(subroot_path.clone()))),
&mut console,
Args::from([("lint"), subroot_path.display().to_string().as_str()].as_slice()),
);

remove_dir_all(root_path).unwrap();

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"include_files_in_symlinked_subdir",
fs,
console,
result,
));
}

#[test]
fn ignore_file_in_subdir_in_symlinked_dir() {
let fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
let config = r#"{
"files": {
"ignore": ["./symlink/subdir/file.js"]
}
}"#;

let root_path = temp_dir().join("ignore_file_in_subdir_in_symlinked_dir");
let _ = remove_dir_all(&root_path);
create_dir(&root_path).unwrap();

let symlinked = root_path.join("symlinked");
create_dir(&symlinked).unwrap();
let sundir_path = symlinked.join("subdir");
create_dir(&sundir_path).unwrap();
File::create(sundir_path.join("file.js"))
.unwrap()
.write_all(APPLY_SUGGESTED_BEFORE.as_bytes())
.unwrap();

let subroot_path = root_path.join("subroot");
create_dir(&subroot_path).unwrap();
File::create(subroot_path.join("biome.json"))
.unwrap()
.write_all(config.as_bytes())
.unwrap();

#[cfg(target_family = "unix")]
{
symlink(root_path.join("symlinked"), subroot_path.join("symlink")).unwrap();
}

#[cfg(target_os = "windows")]
{
check_windows_symlink!(symlink_file(
root_path.join("symlinked"),
subroot_path.join("symlink")
));
}

let result = run_cli(
DynRef::Owned(Box::new(OsFileSystem::new(subroot_path.clone()))),
&mut console,
Args::from([("lint"), subroot_path.display().to_string().as_str()].as_slice()),
);

remove_dir_all(root_path).unwrap();

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"ignore_file_in_subdir_in_symlinked_dir",
fs,
console,
result,
));
}

#[test]
fn file_too_large() {
let mut fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
# Emitted Messages

```block
Checked 1 file in <TIME>. No fixes needed.
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
# Termination Message

```block
lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Some errors were emitted while running checks.
```

# Emitted Messages

```block
<TEMP_DIR>/include_files_in_subdir/subdir/file.js:2:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━━━━━━━━━━━
× This is an unexpected use of the debugger statement.
1 │ let a = 4;
> 2 │ debugger;
│ ^^^^^^^^^
3 │ console.log(a);
4 │
i Unsafe fix: Remove debugger statement
1 1 │ let a = 4;
2 │ - debugger;
3 2 │ console.log(a);
4 3 │
```

```block
<TEMP_DIR>/include_files_in_subdir/subdir/file.js:1:1 lint/style/useConst FIXABLE ━━━━━━━━━━━━━━━━━━━━
× This let declares a variable which is never re-assigned.
> 1 │ let a = 4;
│ ^^^
2 │ debugger;
3 │ console.log(a);
i 'a' is never re-assigned.
> 1 │ let a = 4;
│ ^
2 │ debugger;
3 │ console.log(a);
i Safe fix: Use const instead.
1 │ - let·a·=·4;
1 │ + const·a·=·4;
2 2 │ debugger;
3 3 │ console.log(a);
```

```block
Checked 2 files in <TIME>. No fixes needed.
Found 3 errors.
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
# Termination Message

```block
lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Some errors were emitted while running checks.
```

# Emitted Messages

```block
<TEMP_DIR>/include_files_in_symlinked_subdir/symlinked/file.js:2:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━━━━━━━━━━━
× This is an unexpected use of the debugger statement.
1 │ let a = 4;
> 2 │ debugger;
│ ^^^^^^^^^
3 │ console.log(a);
4 │
i Unsafe fix: Remove debugger statement
1 1 │ let a = 4;
2 │ - debugger;
3 2 │ console.log(a);
4 3 │
```

```block
<TEMP_DIR>/include_files_in_symlinked_subdir/symlinked/file.js:1:1 lint/style/useConst FIXABLE ━━━━━━━━━━━━━━━━━━━━
× This let declares a variable which is never re-assigned.
> 1 │ let a = 4;
│ ^^^
2 │ debugger;
3 │ console.log(a);
i 'a' is never re-assigned.
> 1 │ let a = 4;
│ ^
2 │ debugger;
3 │ console.log(a);
i Safe fix: Use const instead.
1 │ - let·a·=·4;
1 │ + const·a·=·4;
2 2 │ debugger;
3 3 │ console.log(a);
```

```block
Checked 2 files in <TIME>. No fixes needed.
Found 3 errors.
```


Loading

0 comments on commit b96600f

Please sign in to comment.