diff --git a/.changeset/forced-files-forget.md b/.changeset/forced-files-forget.md index 805379c3df8e..94f73ac7c2f5 100644 --- a/.changeset/forced-files-forget.md +++ b/.changeset/forced-files-forget.md @@ -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 diff --git a/crates/biome_cli/tests/cases/included_files.rs b/crates/biome_cli/tests/cases/included_files.rs index 2723a12edd28..fdab0afdb22f 100644 --- a/crates/biome_cli/tests/cases/included_files.rs +++ b/crates/biome_cli/tests/cases/included_files.rs @@ -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; @@ -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, + )); +} + #[test] fn does_not_handle_files_in_ignored_folder() { let mut console = BufferConsole::default(); diff --git a/crates/biome_cli/tests/snapshots/main_cases_included_files/can_force_ignore_biome_json.snap b/crates/biome_cli/tests/snapshots/main_cases_included_files/can_force_ignore_biome_json.snap new file mode 100644 index 000000000000..70b2ae077c89 --- /dev/null +++ b/crates/biome_cli/tests/snapshots/main_cases_included_files/can_force_ignore_biome_json.snap @@ -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