Skip to content

Commit

Permalink
fix(core): enforce parsing options for biome.jsonc (#3729)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Aug 28, 2024
1 parent 3483800 commit f186ee2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
#### Bug fixes

- Fix [#3577](https://github.com/biomejs/biome/issues/3577), where the update of the configuration file was resulting in the creation of a new internal project. Contributed by @ematipico
- Fix [#3696](https://github.com/biomejs/biome/issues/3696), where `biome.jsonc` was incorrectly parsed with incorrect options. Contributed by @ematipico

### Formatter

Expand Down
39 changes: 23 additions & 16 deletions crates/biome_service/src/file_handlers/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,31 @@ fn parse(
settings: Option<&Settings>,
cache: &mut NodeCache,
) -> ParseResult {
let parser = settings.map(|s| &s.languages.json.parser);
let overrides = settings.map(|s| &s.override_settings);
let optional_json_file_source = file_source.to_json_file_source();
let options = JsonParserOptions {
allow_comments: parser.and_then(|p| p.allow_comments).map_or_else(
|| optional_json_file_source.map_or(false, |x| x.allow_comments()),
|value| value,
),
allow_trailing_commas: parser.and_then(|p| p.allow_trailing_commas).map_or_else(
|| optional_json_file_source.map_or(false, |x| x.allow_trailing_commas()),
|value| value,
),
};
let options = if let Some(overrides) = overrides {
overrides.to_override_json_parser_options(biome_path, options)
let options = if biome_path.ends_with(ConfigName::biome_jsonc()) {
JsonParserOptions::default()
.with_allow_comments()
.with_allow_trailing_commas()
} else {
options
let parser = settings.map(|s| &s.languages.json.parser);
let overrides = settings.map(|s| &s.override_settings);
let optional_json_file_source = file_source.to_json_file_source();
let options = JsonParserOptions {
allow_comments: parser.and_then(|p| p.allow_comments).map_or_else(
|| optional_json_file_source.map_or(false, |x| x.allow_comments()),
|value| value,
),
allow_trailing_commas: parser.and_then(|p| p.allow_trailing_commas).map_or_else(
|| optional_json_file_source.map_or(false, |x| x.allow_trailing_commas()),
|value| value,
),
};
if let Some(overrides) = overrides {
overrides.to_override_json_parser_options(biome_path, options)
} else {
options
}
};

let parse = biome_json_parser::parse_json_with_cache(text, cache, options);

ParseResult {
Expand Down

0 comments on commit f186ee2

Please sign in to comment.