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
2 changes: 1 addition & 1 deletion .changeset/forced-files-forget.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Deprecated the option `files.experimentalScannerIgnores` in favour of **force-ig

`files.includes` supports ignoring files by prefixing globs with an exclamation mark (`!`). With this change, it also supports _force_-ignoring globs by prefixing them with a double exclamation mark (`!!`).

The effect of force-ignoring is that the scanner will not index files matching the glob, even in project mode, and even if those files are imported by other files.
The effect of force-ignoring is that the scanner will not index files matching the glob, even in project mode, even if those files are imported by other files, and even if they are files that receive special treatment by Biome, such as nested `biome.json` files.

#### Example

Expand Down
76 changes: 74 additions & 2 deletions crates/biome_cli/tests/cases/included_files.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::run_cli;
use crate::snap_test::{SnapshotPayload, assert_cli_snapshot, assert_file_contents};
use crate::{run_cli, run_cli_with_dyn_fs};
use biome_console::BufferConsole;
use biome_fs::MemoryFileSystem;
use biome_fs::{MemoryFileSystem, TemporaryFs};
use bpaf::Args;
use camino::Utf8Path;

Expand Down Expand Up @@ -166,6 +166,78 @@ fn does_not_handle_files_inside_force_ignored_folders() {
));
}

#[test]
fn errors_on_ignored_nested_biome_json() {
let mut console = BufferConsole::default();
let mut fs = TemporaryFs::new("errors_on_ignored_nested_biome_json");
fs.create_file(
"biome.json",
r#"{ "files": { "includes": ["**/*.js", "!nested/biome.json"] } }"#,
);
fs.create_file(
"nested/biome.json",
r#"{ "formatter": { "enabled": false } }"#,
);

let root_a = "a.js";
fs.create_file(root_a, UNFORMATTED);

let nested_a = "nested/a.js";
fs.create_file(nested_a, UNFORMATTED);

let result = run_cli_with_dyn_fs(
Box::new(fs.create_os()),
&mut console,
Args::from(["format", fs.cli_path()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"errors_on_ignored_nested_biome_json",
fs.create_mem(),
console,
result,
));
}

#[test]
fn can_force_ignore_biome_json() {
let mut console = BufferConsole::default();
let mut fs = TemporaryFs::new("can_force_ignore_biome_json");
fs.create_file(
"biome.json",
r#"{ "files": { "includes": ["**/*.js", "!!nested/biome.json"] } }"#,
);
fs.create_file(
"nested/biome.json",
r#"{ "formatter": { "enabled": false } }"#,
);

let root_a = "a.js";
fs.create_file(root_a, UNFORMATTED);

let nested_a = "nested/a.js";
fs.create_file(nested_a, UNFORMATTED);

let result = run_cli_with_dyn_fs(
Box::new(fs.create_os()),
&mut console,
Args::from(["format", fs.cli_path()].as_slice()),
);

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"can_force_ignore_biome_json",
fs.create_mem(),
console,
result,
));
}
Comment on lines +205 to +239
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Assertion contradicts the test name and changeset semantics.

Force-ignoring nested biome.json should be allowed; this test should pass, not error.

@@
-    let root_a = "a.js";
-    fs.create_file(root_a, UNFORMATTED);
+    fs.create_file("a.js", UNFORMATTED);
@@
-    let nested_a = "nested/a.js";
-    fs.create_file(nested_a, UNFORMATTED);
+    fs.create_file("nested/a.js", UNFORMATTED);
@@
-    let result = run_cli_with_dyn_fs(
+    let result = run_cli_with_dyn_fs(
         Box::new(fs.create_os()),
         &mut console,
-        Args::from(["format", fs.cli_path()].as_slice()),
+        Args::from(["format", "--write", fs.cli_path()].as_slice()),
     );
@@
-    assert!(result.is_err(), "run_cli returned {result:?}");
+    assert!(result.is_ok(), "run_cli returned {result:?}");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
#[test]
fn can_force_ignore_biome_json() {
let mut console = BufferConsole::default();
let mut fs = TemporaryFs::new("can_force_ignore_biome_json");
fs.create_file(
"biome.json",
r#"{ "files": { "includes": ["**/*.js", "!!nested/biome.json"] } }"#,
);
fs.create_file(
"nested/biome.json",
r#"{ "formatter": { "enabled": false } }"#,
);
let root_a = "a.js";
fs.create_file(root_a, UNFORMATTED);
let nested_a = "nested/a.js";
fs.create_file(nested_a, UNFORMATTED);
let result = run_cli_with_dyn_fs(
Box::new(fs.create_os()),
&mut console,
Args::from(["format", fs.cli_path()].as_slice()),
);
assert!(result.is_err(), "run_cli returned {result:?}");
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"can_force_ignore_biome_json",
fs.create_mem(),
console,
result,
));
}
#[test]
fn can_force_ignore_biome_json() {
let mut console = BufferConsole::default();
let mut fs = TemporaryFs::new("can_force_ignore_biome_json");
fs.create_file(
"biome.json",
r#"{ "files": { "includes": ["**/*.js", "!!nested/biome.json"] } }"#,
);
fs.create_file(
"nested/biome.json",
r#"{ "formatter": { "enabled": false } }"#,
);
fs.create_file("a.js", UNFORMATTED);
fs.create_file("nested/a.js", UNFORMATTED);
let result = run_cli_with_dyn_fs(
Box::new(fs.create_os()),
&mut console,
Args::from(["format", "--write", fs.cli_path()].as_slice()),
);
assert!(result.is_ok(), "run_cli returned {result:?}");
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"can_force_ignore_biome_json",
fs.create_mem(),
console,
result,
));
}
🤖 Prompt for AI Agents
crates/biome_cli/tests/cases/included_files.rs around lines 205 to 239: the test
name and comment indicate force-ignoring nested biome.json should succeed, but
the test currently asserts result.is_err(), causing it to expect failure; change
the assertion to expect success (e.g., assert!(result.is_ok())) and adjust any
subsequent handling of result when passing to assert_cli_snapshot (pass the Ok
value or keep passing result but update snapshot expectations) so the test
reflects a successful run instead of an error.


#[test]
fn does_not_handle_files_in_ignored_folder() {
let mut console = BufferConsole::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{ "files": { "includes": ["**/*.js", "!!nested/biome.json"] } }
```

## `nested/biome.json`

```json
{ "formatter": { "enabled": false } }
```

## `a.js`

```js
statement( )
```

## `nested/a.js`

```js
statement( )
```

# Termination Message

```block
format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Some errors were emitted while running checks.



```

# Emitted Messages

```block
a.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Formatter would have printed the following content:

1 │ - ··statement(··)··
1 │ + statement();
2 │ +


```

```block
biome.json format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Formatter would have printed the following content:

1 │ - {·"files":·{·"includes":·["**/*.js",·"!!nested/biome.json"]·}·}
1 │ + {·"files":·{·"includes":·["**/*.js",·"!!nested/biome.json"]·}·}
2 │ +


```

```block
nested/a.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Formatter would have printed the following content:

1 │ - ··statement(··)··
1 │ + statement();
2 │ +


```

```block
Checked 3 files in <TIME>. No fixes applied.
Found 3 errors.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: redactor(content)
---
## `biome.json`

```json
{ "files": { "includes": ["**/*.js", "!nested/biome.json"] } }
```

## `nested/biome.json`

```json
{ "formatter": { "enabled": false } }
```

## `a.js`

```js
statement( )
```

## `nested/a.js`

```js
statement( )
```

# Termination Message

```block
configuration ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Biome exited because the configuration resulted in errors. Please fix them.



```

# Emitted Messages

```block
<TEMP_DIR>/errors_on_ignored_nested_biome_json/nested/biome.json configuration ━━━━━━━━━━━━━━━━━━━━

× Found a nested root configuration, but there's already a root configuration.

i The other configuration was found in <TEMP_DIR>/errors_on_ignored_nested_biome_json.

i Use the migration command from the root of the project to update the configuration.

$ biome migrate --write


```
Loading