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

fix(configuration): merge inherited overrides #3671

Merged
merged 1 commit into from
Aug 18, 2024
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
60 changes: 59 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
#### Bug fixes

- `biome lint --write` now takes `--only` and `--skip` into account ([#3470](https://github.com/biomejs/biome/issues/3470)). Contributed by @Conaclos

- Fix [#3368](https://github.com/biomejs/biome/issues/3368), now the reporter `github` tracks the diagnostics that belong to formatting and organize imports. Contributed by @ematipico

- Fix [#3545](https://github.com/biomejs/biome/issues/3545), display a warning, 'Avoid using unnecessary Fragment,' when a Fragment contains only one child element that is placed on a new line. Contributed by @satojin219

- Migrating from Prettier or ESLint no longer overwrite the `overrides` field from the configuration ([#3544](https://github.com/biomejs/biome/issues/3544)). Contributed by @Conaclos

### Configuration

- Add support for loading configuration from `.editorconfig` files ([#1724](https://github.com/biomejs/biome/issues/1724)). Contributed by @dyc3
- Add support for loading configuration from `.editorconfig` files ([#1724](https://github.com/biomejs/biome/issues/1724)).

Configuration supplied in `.editorconfig` will be overridden by the configuration in `biome.json`. Support is disabled by default and can be enabled by adding the following to your formatter configuration in `biome.json`:

```json
{
"formatter": {
Expand All @@ -101,6 +107,58 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
}
```

Contributed by @dyc3

- `overrides` from an extended configuration is now merged with the `overrides` of the extension.

Given the following shared configuration `biome.shared.json`:

```json5
{
"overrides": [
{
"include": ["**/*.json"],
// ...
}
]
}
```

and the following configuration:

```json5
{
"extends": ["./biome.shared.json"],
"overrides": [
{
"include": ["**/*.ts"],
// ...
}
]
}
```

Previously, the `overrides` from `biome.shared.json` was overwritten.
It is now merged and results in the following configuration:

```json5
{
"extends": ["./biome.shared.json"],
"overrides": [
{
"include": ["**/*.json"],
// ...
},
{
"include": ["**/*.ts"],
// ...
}
]
}
```

Contributed by @Conaclos

### Editors

#### Bug fixes
Expand Down
46 changes: 46 additions & 0 deletions crates/biome_cli/tests/cases/config_extends.rs
Original file line number Diff line number Diff line change
Expand Up @@ -358,3 +358,49 @@ fn allows_reverting_fields_in_extended_config_to_default() {
result,
));
}

#[test]
fn extends_config_merge_overrides() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let shared = Path::new("shared.json");
fs.insert(
shared.into(),
r#"{
"overrides": [{
"include": ["**/*.js"],
"linter": { "rules": { "suspicious": { "noDebugger": "off" } } }
}]
}"#,
);

let biome_json = Path::new("biome.json");
fs.insert(
biome_json.into(),
r#"{
"extends": ["shared.json"],
"overrides": [{
"include": ["**/*.js"],
"linter": { "rules": { "correctness": { "noUnusedVariables": "error" } } }
}]
}"#,
);

let test_file = Path::new("test.js");
fs.insert(test_file.into(), "debugger; const a = 0;");

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["lint", test_file.as_os_str().to_str().unwrap()].as_slice()),
);

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"extends_config_merge_overrides",
fs,
console,
result,
));
}
38 changes: 38 additions & 0 deletions crates/biome_cli/tests/commands/migrate_eslint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,3 +665,41 @@ fn migrate_eslintrcjson_extended_rules() {
result,
));
}

#[test]
fn migrate_merge_with_overrides() {
let biomejson = r#"{
"overrides": [{
"include": ["*.js"],
"linter": { "enabled": false }
}]
}"#;
let eslintrc = r#"{
"overrides": [{
"files": ["bin/*.js", "lib/*.js"],
"excludedFiles": "*.test.js",
"rules": {
"eqeqeq": ["off"]
}
}]
}"#;

let mut fs = MemoryFileSystem::default();
fs.insert(Path::new("biome.json").into(), biomejson.as_bytes());
fs.insert(Path::new(".eslintrc.json").into(), eslintrc.as_bytes());

let mut console = BufferConsole::default();
let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(["migrate", "eslint"].as_slice()),
);

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"migrate_merge_with_overrides",
fs,
console,
result,
));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `biome.json`

```json
{
"extends": ["shared.json"],
"overrides": [
{
"include": ["**/*.js"],
"linter": { "rules": { "correctness": { "noUnusedVariables": "error" } } }
}
]
}
```

## `shared.json`

```json
{
"overrides": [{
"include": ["**/*.js"],
"linter": { "rules": { "suspicious": { "noDebugger": "off" } } }
}]
}
```

## `test.js`

```js
debugger; const a = 0;
```

# Termination Message

```block
lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Some errors were emitted while running checks.



```

# Emitted Messages

```block
test.js:1:17 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× This variable is unused.

> 1 │ debugger; const a = 0;
│ ^

i Unused variables usually are result of incomplete refactoring, typos and other source of bugs.

i Unsafe fix: If this is intentional, prepend a with an underscore.

- debugger;·const·a·=·0;
+ debugger;·const·_a·=·0;


```

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

```json
{
"overrides": [
{
"include": ["*.js"],
"linter": { "enabled": false }
}
]
}
```

## `.eslintrc.json`

```json
{
"overrides": [{
"files": ["bin/*.js", "lib/*.js"],
"excludedFiles": "*.test.js",
"rules": {
"eqeqeq": ["off"]
}
}]
}
```

# Emitted Messages

```block
biome.json migrate ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

i Configuration file can be updated.

1 1 │ {
2 │ - ········"overrides":·[{
3 │ - ············"include":·["*.js"],
4 │ - ············"linter":·{·"enabled":·false·}
5 │ - ········}]
6 │ - ····}
2 │ + → "linter":·{·"rules":·{·"recommended":·false·}·},
3 │ + → "overrides":·[
4 │ + → → {·"include":·["*.js"],·"linter":·{·"enabled":·false·}·},
5 │ + → → {
6 │ + → → → "ignore":·["*.test.js"],
7 │ + → → → "include":·["bin/*.js",·"lib/*.js"],
8 │ + → → → "linter":·{·"rules":·{·"suspicious":·{·"noDoubleEquals":·"off"·}·}·}
9 │ + → → }
10 │ + → ]
11 │ + }
12 │ +


```

```block
Run the command with the option --write to apply the changes.
```
Loading