Skip to content

Commit dcb695d

Browse files
authored
fix(configuration): .jsonc config deserialization in extends (biomejs#2393)
1 parent 62e5aab commit dcb695d

7 files changed

Lines changed: 26 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
142142

143143
- Now setting group level `all` to `false` can disable recommended rules from that group when top level `recommended` is `true` or unset. Contributed by @Sec-ant
144144

145+
- Biome configuration files can correctly extends `.jsonc` configuration files now ([#2279](https://github.com/biomejs/biome/issues/2279)). Contributed by @Sec-ant
146+
145147
#### Enhancements
146148

147149
- Biome now displays the location of a parsing error for its configuration file ([#1627](https://github.com/biomejs/biome/issues/1627)).

crates/biome_fs/src/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub trait FileSystem: Send + Sync + RefUnwindSafe {
113113
Err(err) => {
114114
if !is_searching_in_parent_dir && should_error_if_file_not_found {
115115
let error_message = format!(
116-
"Biome couldn't read the config file {:?}, reason:\n {}",
116+
"Biome couldn't read the file {:?}, reason:\n {}",
117117
file_path, err
118118
);
119119
errors.push((
@@ -134,7 +134,7 @@ pub trait FileSystem: Send + Sync + RefUnwindSafe {
134134
Err(err) => {
135135
if !is_searching_in_parent_dir && should_error_if_file_not_found {
136136
let error_message = format!(
137-
"Biome couldn't find the config file {:?}, reason:\n {}",
137+
"Biome couldn't find the file {:?}, reason:\n {}",
138138
file_path, err
139139
);
140140
errors.push((

crates/biome_service/src/configuration.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use biome_fs::{AutoSearchResult, ConfigName, FileSystem, OpenOptions};
1414
use biome_js_analyze::metadata;
1515
use biome_json_formatter::context::JsonFormatOptions;
1616
use biome_json_parser::{parse_json, JsonParserOptions};
17+
use std::ffi::OsStr;
1718
use std::fmt::Debug;
1819
use std::io::ErrorKind;
1920
use std::iter::FusedIterator;
@@ -413,7 +414,12 @@ impl PartialConfigurationExt for PartialConfiguration {
413414
})?;
414415
let deserialized = deserialize_from_json_str::<PartialConfiguration>(
415416
content.as_str(),
416-
JsonParserOptions::default(),
417+
match config_path.extension().and_then(OsStr::to_str) {
418+
Some("json") => JsonParserOptions::default(),
419+
_ => JsonParserOptions::default()
420+
.with_allow_comments()
421+
.with_allow_trailing_commas(),
422+
},
417423
"",
418424
);
419425
deserialized_configurations.push(deserialized)

crates/biome_service/tests/spec_tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::ffi::OsStr;
66
use std::fs::read_to_string;
77
use std::path::Path;
88

9-
tests_macros::gen_tests! {"tests/invalid/**/*.{json}", crate::run_invalid_configurations, "module"}
10-
tests_macros::gen_tests! {"tests/valid/**/*.{json}", crate::run_valid_configurations, "module"}
9+
tests_macros::gen_tests! {"tests/invalid/**/*.{json,jsonc}", crate::run_invalid_configurations, "module"}
10+
tests_macros::gen_tests! {"tests/valid/**/*.{json,jsonc}", crate::run_valid_configurations, "module"}
1111

1212
fn run_invalid_configurations(input: &'static str, _: &str, _: &str, _: &str) {
1313
let input_file = Path::new(input);
@@ -75,7 +75,9 @@ fn run_valid_configurations(input: &'static str, _: &str, _: &str, _: &str) {
7575
),
7676
"jsonc" => deserialize_from_json_str::<PartialConfiguration>(
7777
input_code.as_str(),
78-
JsonParserOptions::default().with_allow_comments(),
78+
JsonParserOptions::default()
79+
.with_allow_comments()
80+
.with_allow_trailing_commas(),
7981
"",
8082
),
8183
_ => {
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": ["./extends_jsonc_s.jsonc"]
3+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"linter": {
3+
"enabled": false, // linter is disabled
4+
}
5+
}

website/src/content/docs/internals/changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,8 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
148148

149149
- Now setting group level `all` to `false` can disable recommended rules from that group when top level `recommended` is `true` or unset. Contributed by @Sec-ant
150150

151+
- Biome configuration files can correctly extends `.jsonc` configuration files now ([#2279](https://github.com/biomejs/biome/issues/2279)). Contributed by @Sec-ant
152+
151153
#### Enhancements
152154

153155
- Biome now displays the location of a parsing error for its configuration file ([#1627](https://github.com/biomejs/biome/issues/1627)).

0 commit comments

Comments
 (0)