Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(config): add the includes field #4899

Open
wants to merge 3 commits into
base: next
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions .changeset/introduce_includes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---
cli: minor
---

# Introduce `includes`

Biome allow users to `include` and `ignore` files in its configuration using glob patterns.

For example, in the following configuration, all files of the `src` directory are checked except the ones ending with the extension `.test.js`.

```json
{
"files": {
"include": ["src/**"],
"ignore": ["**/*.test.js"]
}
}
```

Some Biome users have requested the ability to ignore a set of files except some of the files.
With the current system, this is not possible because `include` is always applied before `ignore`.

Also, many Biome users [reported](https://github.com/biomejs/biome/issues/2421) [issues](https://github.com/biomejs/biome/issues/3345) with the behavior of the glob patterns.
Notably:

- `src/**` is interpreted as `**/src/**`
- `*.js` is interpreted as `**/*.js`

To solve all these issues, we introduce a new field `includes`, which replaces both `include` and `ignore`.
`includes` accepts an array of glob patterns with a stricter and more intuitive behavior than the previous glob pattern format.
A glob starting with a `!` is an exception.
This replaces `ignore` patterns.

The previous configuration must be updated as follows:

```json
{
"files": {
"includes": ["src/**", "!**/*.test.js"]
}
}
```
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions crates/biome_cli/src/commands/rage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ impl Display for RageConfiguration<'_> {
.collect::<Vec<_>>()
.join(", ")
});
let includes = formatter_configuration.includes.map(|list| {
list.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
.join(", ")
});
markup! (
{Section("Formatter")}
{KeyValuePair("Format with errors", markup!({DisplayOption(configuration.get_formatter_configuration().format_with_errors)}))}
Expand All @@ -265,6 +271,7 @@ impl Display for RageConfiguration<'_> {
{KeyValuePair("Bracket spacing", markup!({DisplayOption(formatter_configuration.bracket_spacing)}))}
{KeyValuePair("Ignore", markup!({DisplayOption(ignore)}))}
{KeyValuePair("Include", markup!({DisplayOption(include)}))}
{KeyValuePair("Includes", markup!({DisplayOption(includes)}))}
).fmt(fmt)?;

let javascript_formatter_configuration =
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/execute/migrate/prettier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ impl TryFrom<PrettierConfiguration> for biome_configuration::Configuration {
format_with_errors: Some(false.into()),
ignore: None,
include: None,
includes: None,
enabled: Some(true.into()),
// editorconfig support is intentionally set to true, because prettier always reads the editorconfig file
// see: https://github.com/prettier/prettier/issues/15255
Expand Down
12 changes: 6 additions & 6 deletions crates/biome_cli/tests/cases/biome_json_support.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,12 @@ fn biome_json_is_not_ignored() {
fs.insert(
Utf8PathBuf::from("biome.json"),
r#"{
"files": { "ignore": ["*.json"] },
"formatter": {
"enabled": false
}
}
"#
"files": { "includes": ["**", "!*.json"] },
"formatter": {
"enabled": false
}
}
"#
.as_bytes(),
);

Expand Down
4 changes: 2 additions & 2 deletions crates/biome_cli/tests/cases/config_extends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ fn extends_config_merge_overrides() {
shared.into(),
r#"{
"overrides": [{
"include": ["**/*.js"],
"includes": ["**/*.js"],
"linter": { "rules": { "suspicious": { "noDebugger": "off" } } }
}]
}"#,
Expand All @@ -344,7 +344,7 @@ fn extends_config_merge_overrides() {
r#"{
"extends": ["shared.json"],
"overrides": [{
"include": ["**/*.js"],
"includes": ["**/*.js"],
"linter": { "rules": { "correctness": { "noUnusedVariables": "error" } } }
}]
}"#,
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/cases/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fn logs_the_appropriate_messages_according_to_set_diagnostics_level() {
file_path.into(),
r#"{
"files": {
"include": ["test.js"]
"includes": ["test.js"]
},
"linter": {
"rules": {
Expand Down
27 changes: 8 additions & 19 deletions crates/biome_cli/tests/cases/included_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fn does_handle_only_included_files() {
fs.insert(
file_path.into(),
r#"{
"files": { "include": ["test.js"] }
"files": { "includes": ["test.js"] }
}
"#
.as_bytes(),
Expand Down Expand Up @@ -64,11 +64,7 @@ fn does_not_handle_included_files_if_overridden_by_ignore() {
let file_path = Utf8Path::new("biome.json");
fs.insert(
file_path.into(),
r#"{
"files": { "include": ["test.js", "test2.js"], "ignore": ["test.js"] }
}
"#
.as_bytes(),
r#"{ "files": { "includes": ["test.js", "test2.js", "!test.js"] } }"#.as_bytes(),
);

let test = Utf8Path::new("test.js");
Expand Down Expand Up @@ -105,11 +101,7 @@ fn does_not_handle_included_files_if_overridden_by_ignore_formatter() {
let file_path = Utf8Path::new("biome.json");
fs.insert(
file_path.into(),
r#"{
"formatter": { "include": ["test.js", "test2.js"], "ignore": ["test.js"] }
}
"#
.as_bytes(),
r#"{ "formatter": { "includes": ["test.js", "test2.js", "!test.js"] } }"#.as_bytes(),
);

let test = Utf8Path::new("test.js");
Expand Down Expand Up @@ -146,9 +138,7 @@ fn does_not_handle_included_files_if_overridden_by_ignore_linter() {
let file_path = Utf8Path::new("biome.json");
fs.insert(
file_path.into(),
r#"{
"linter": { "include": ["test.js", "test2.js"], "ignore": ["test.js"] }
}
r#"{ "linter": { "includes": ["test.js", "test2.js", "!test.js"] } }
"#
.as_bytes(),
);
Expand Down Expand Up @@ -188,11 +178,10 @@ fn does_not_handle_included_files_if_overridden_by_organize_imports() {
fs.insert(
file_path.into(),
r#"{
"formatter": { "enabled": false },
"linter": { "enabled": false },
"assist": { "include": ["test.js", "test2.js"], "ignore": ["test.js"] }
}
"#
"formatter": { "enabled": false },
"linter": { "enabled": false },
"assist": { "includes": ["test.js", "test2.js", "!test.js"] }
}"#
.as_bytes(),
);

Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/tests/cases/linter_domains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ fn enable_test_rules_via_overrides() {
}
},
"overrides": [{
"include": ["test1.js"],
"includes": ["test1.js"],
"linter": {
"domains": {
"test": "all"
Expand Down
54 changes: 27 additions & 27 deletions crates/biome_cli/tests/cases/overrides_formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ fn does_handle_included_file_and_disable_formatter() {
file_path.into(),
r#"{
"files": {
"include": ["test.js", "special/**"]
"includes": ["test.js", "special/**"]
},
"overrides": [{ "include": ["special/**"], "formatter": { "enabled": false } }]
"overrides": [{ "includes": ["special/**"], "formatter": { "enabled": false } }]
}

"#
Expand Down Expand Up @@ -80,7 +80,7 @@ fn does_include_file_with_different_formatting() {
fs.insert(
file_path.into(),
r#"{
"overrides": [{ "include": ["special/**"], "formatter": { "lineWidth": 20 } }]
"overrides": [{ "includes": ["special/**"], "formatter": { "lineWidth": 20 } }]
}

"#
Expand Down Expand Up @@ -122,8 +122,8 @@ fn does_include_file_with_different_formatting_and_all_of_them() {
file_path.into(),
r#"{
"overrides": [
{ "include": ["special/**"], "formatter": { "lineWidth": 130 } },
{ "include": ["special/**"], "formatter": { "lineWidth": 20 } }
{ "includes": ["special/**"], "formatter": { "lineWidth": 130 } },
{ "includes": ["special/**"], "formatter": { "lineWidth": 20 } }
]
}

Expand Down Expand Up @@ -166,8 +166,8 @@ fn does_include_file_with_different_overrides() {
file_path.into(),
r#"{
"overrides": [
{ "include": ["test.js"], "formatter": { "lineWidth": 20 } },
{ "include": ["test2.js"], "formatter": { "lineWidth": 20, "indentStyle": "space" } }
{ "includes": ["test.js"], "formatter": { "lineWidth": 20 } },
{ "includes": ["test2.js"], "formatter": { "lineWidth": 20, "indentStyle": "space" } }
]
}

Expand Down Expand Up @@ -219,9 +219,9 @@ fn complex_enable_disable_overrides() {
}
},
"overrides": [
{ "include": ["formatted.js"], "formatter": { "enabled": true } },
{ "includes": ["formatted.js"], "formatter": { "enabled": true } },
{
"include": ["dirty.js"],
"includes": ["dirty.js"],
"linter": {
"rules": {
"performance": {
Expand Down Expand Up @@ -278,9 +278,9 @@ fn does_include_file_with_different_languages() {
file_path.into(),
r#"{
"overrides": [
{ "include": ["test.js"], "formatter": { "lineWidth": 120 }, "javascript": { "formatter": { "quoteStyle": "single" } } },
{ "include": ["test2.js"], "formatter": { "lineWidth": 120, "indentStyle": "space" }, "javascript": { "formatter": { "semicolons": "asNeeded" } } },
{ "include": ["test.css"], "formatter": { "lineWidth": 120, "indentStyle": "space" }, "css": { "formatter": { "quoteStyle": "single" } } }
{ "includes": ["test.js"], "formatter": { "lineWidth": 120 }, "javascript": { "formatter": { "quoteStyle": "single" } } },
{ "includes": ["test2.js"], "formatter": { "lineWidth": 120, "indentStyle": "space" }, "javascript": { "formatter": { "semicolons": "asNeeded" } } },
{ "includes": ["test.css"], "formatter": { "lineWidth": 120, "indentStyle": "space" }, "css": { "formatter": { "quoteStyle": "single" } } }
]
}
"#
Expand Down Expand Up @@ -335,15 +335,15 @@ fn does_include_file_with_different_languages_and_files() {
file_path.into(),
r#"{
"overrides": [
{ "include": ["test.js"], "formatter": { "lineWidth": 120 }, "javascript": { "formatter": { "quoteStyle": "single" } } },
{ "includes": ["test.js"], "formatter": { "lineWidth": 120 }, "javascript": { "formatter": { "quoteStyle": "single" } } },
{
"include": ["test2.js"],
"includes": ["test2.js"],
"formatter": { "lineWidth": 120, "indentStyle": "space" },
"javascript": { "formatter": { "semicolons": "asNeeded" } },
"json": { "formatter": { "indentStyle": "space", "lineWidth": 20, "indentWidth": 4 } }
},
{
"include": ["test3.json"],
"includes": ["test3.json"],
"formatter": { "lineWidth": 120, "indentStyle": "space" },
"json": { "formatter": { "indentStyle": "space", "lineWidth": 20, "indentWidth": 4 } }
}
Expand Down Expand Up @@ -408,7 +408,7 @@ fn does_not_change_formatting_settings() {
r#"{
"formatter": { "lineWidth": 20, "indentStyle": "space" },
"overrides": [
{ "include": ["test.js"], "linter": { "enabled": false } }
{ "includes": ["test.js"], "linter": { "enabled": false } }
]
}

Expand Down Expand Up @@ -452,7 +452,7 @@ fn does_not_change_formatting_language_settings() {
r#"{
"javascript": { "formatter": { "quoteStyle": "single" } },
"overrides": [
{ "include": ["test.js"], "linter": { "enabled": false } }
{ "includes": ["test.js"], "linter": { "enabled": false } }
]
}

Expand Down Expand Up @@ -496,7 +496,7 @@ fn does_not_change_formatting_language_settings_2() {
r#"{
"javascript": { "formatter": { "lineWidth": 20 } },
"overrides": [
{ "include": ["test.js"], "linter": { "enabled": false } }
{ "includes": ["test.js"], "linter": { "enabled": false } }
]
}

Expand Down Expand Up @@ -540,8 +540,8 @@ fn does_not_conceal_previous_overrides() {
r#"{
"javascript": { "formatter": { "quoteStyle": "single" } },
"overrides": [
{ "include": ["*.js"], "javascript": { "formatter": { "quoteStyle": "double" } } },
{ "include": ["test.js"], "javascript": { "formatter": { "indentWidth": 4 } } }
{ "includes": ["*.js"], "javascript": { "formatter": { "quoteStyle": "double" } } },
{ "includes": ["test.js"], "javascript": { "formatter": { "indentWidth": 4 } } }
]
}"#
.as_bytes(),
Expand Down Expand Up @@ -578,10 +578,10 @@ fn takes_last_formatter_enabled_into_account() {
r#"{
"overrides": [
{
"include": ["*.js"],
"includes": ["*.js"],
"formatter": { "enabled": false }
}, {
"include": ["*.js"],
"includes": ["*.js"],
"formatter": { "enabled": true }
}
]
Expand Down Expand Up @@ -617,7 +617,7 @@ fn does_not_override_well_known_special_files_when_config_override_is_present()
r#"{
"overrides": [
{
"include": [
"includes": [
"**/*.json"
],
"formatter": { "enabled": false }
Expand Down Expand Up @@ -673,7 +673,7 @@ fn allow_trailing_commas_on_well_known_files() {
},
"overrides": [
{
"include": [
"includes": [
"**/*.json"
],
"json": { "parser": { "allowTrailingCommas": true } }
Expand Down Expand Up @@ -741,7 +741,7 @@ fn disallow_comments_on_well_known_files() {
},
"overrides": [
{
"include": [
"includes": [
"**/*.json"
],
"json": { "parser": { "allowComments": false } }
Expand Down Expand Up @@ -785,7 +785,7 @@ fn overrides_default_formatter_for_package_json() {
r#"{
"overrides": [
{
"include": ["package.json"],
"includes": ["package.json"],
"json": { "formatter": { "expand": "followSource" } }
}
]
Expand Down Expand Up @@ -825,7 +825,7 @@ fn overrides_grit_formatting_options() {
},
"overrides": [
{
"include": [
"includes": [
"file.grit"
],
"grit": { "formatter": { "indentStyle": "space", "indentWidth": 8 } }
Expand Down
Loading
Loading