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(biome_cli): add schema version check to check,lint,format commands #4796

Merged
merged 9 commits into from
Feb 28, 2025
5 changes: 5 additions & 0 deletions .changeset/great-planes-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": minor
---

Biome now emits a warning diagnostic if the configuration contains an out-of-sync schema URL.
1 change: 1 addition & 0 deletions Cargo.lock

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

25 changes: 25 additions & 0 deletions crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3903,3 +3903,28 @@ fn linter_doesnt_crash_on_malformed_code_from_issue_4723() {
result,
));
}

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

let biome_json = Utf8Path::new("biome.json");
fs.insert(
biome_json.into(),
r#"{
"$schema": "https://biomejs.dev/schemas/0.0.1/schema.json"
}
"#,
);
let (fs, result) = run_cli(fs, &mut console, Args::from([("check")].as_slice()));

assert!(result.is_err(), "run_cli returned {result:?}");
assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_report_when_schema_version_mismatch",
fs,
console,
result,
));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
snapshot_kind: text
---
## `biome.json`

```json
{
"$schema": "https://biomejs.dev/schemas/0.0.1/schema.json"
}
```

# Termination Message

```block
internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× No files were processed in the specified paths.



```

# Emitted Messages

```block
The configuration schema version does not match the CLI version.
Expect: 0.0.0
Found: 0.0.1

If you wish to update the configuration schema, setting the `$schema` option to the expected version.
```

```block
Checked 0 files in <TIME>. No fixes applied.
```
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━

# Emitted Messages

```block
biome.json:2:24 deserialize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! The configuration schema version does not match the CLI version 0.0.0

1 │ {
> 2 │ "$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │ "assist": {
4 │ "enabled": true

i Expected: 0.0.0
Found: 1.6.1


i Run the command biome migrate to migrate the configuration file.


```

```block
build/file.js format ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ value["optimizelyService"] = optimizelyService;

# Emitted Messages

```block
biome.json:2:24 deserialize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! The configuration schema version does not match the CLI version 0.0.0

1 │ {
> 2 │ "$schema": "https://biomejs.dev/schemas/1.6.1/schema.json",
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │ "assist": {
4 │ "enabled": true

i Expected: 0.0.0
Found: 1.6.1


i Run the command biome migrate to migrate the configuration file.


```

```block
Formatted 1 file in <TIME>. Fixed 1 file.
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
snapshot_kind: text
---
## `biome.json`

```json
{
"$schema": "https://biomejs.dev/schemas/0.0.1/schema.json"
}
```

# Termination Message

```block
internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× No files were processed in the specified paths.



```

# Emitted Messages

```block
The configuration schema version does not match the CLI version.
Expect: 0.0.0
Found: 0.0.1

If you wish to update the configuration schema, setting the `$schema` option to the expected version.
```

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

```json
{
"$schema": "https://biomejs.dev/schemas/0.0.1/schema.json"
}
```

# Termination Message

```block
internalError/io ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× No files were processed in the specified paths.



```

# Emitted Messages

```block
biome.json:2:16 deserialize ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

! The configuration schema version does not match the CLI version 0.0.0

1 │ {
> 2 │ "$schema": "https://biomejs.dev/schemas/0.0.1/schema.json"
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3 │ }
4 │

i Expected: 0.0.0
Found: 0.0.1


i Run the command biome migrate to migrate the configuration file.


```

```block
Checked 0 files in <TIME>. No fixes applied.
```
1 change: 1 addition & 0 deletions crates/biome_configuration/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ biome_rowan = { workspace = true, features = ["serde"] }
bpaf = { workspace = true }
camino = { workspace = true }
oxc_resolver = { workspace = true }
regex = { workspace = true }
rustc-hash = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
Expand Down
Loading
Loading