-
-
Notifications
You must be signed in to change notification settings - Fork 475
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
test(parse/json): add test for bug where overrides erroneously override special parsing options #3260
Conversation
ed73e95
to
8ebe45f
Compare
// HACK: prevent overrides from affecting how special json files are parsed | ||
if options_file_source.allow_comments { | ||
options.allow_comments = true; | ||
} | ||
if options_file_source.allow_trailing_commas { | ||
options.allow_trailing_commas = true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should prioritize "file source" (well-known files) specific options over "overrides" options. For example, if a user wants to forbid comments or trailing commas in tsconfig.json
, they should be able to achieve that.
File source specific options should be the default fallback < then normal options < then overrides options
I think we need to fix this problem in .to_override_json_parser_options
.
I also think it's acceptable to temporarily disable the cache if it can give us the correct behavior, if maintaining them is error prone.
The following isn't necessarily related to the issue, but can be a good refactoring that makes the code easier to read and maintain. I think we should add a biome/crates/biome_service/src/settings.rs Lines 666 to 708 in fc9b1eb
And add a new method biome/crates/biome_service/src/settings.rs Lines 510 to 551 in fc9b1eb
So we can abstract this part of the logic: biome/crates/biome_service/src/file_handlers/json.rs Lines 178 to 191 in fc9b1eb
into this struct (in the
|
I introduced the caching mainly because computing overrides can be very expensive and slow down the CLI, especially if there's an override that changes lint rules. This was done months ago after Yagiz noticed a degradation in performance for each override added to the configuration. Unfortunately we don't have benchmarks for our CLI - and we really should - but we could evaluate how the caching is done, still, since it's a hot path, we should add more care to it. |
There're two factors that caused this erroneous behavior:
biome/crates/biome_service/src/file_handlers/json.rs Lines 187 to 191 in fc9b1eb
biome/crates/biome_service/src/settings.rs Lines 852 to 854 in fc9b1eb
biome/crates/biome_service/src/settings.rs Lines 1104 to 1105 in fc9b1eb
biome/crates/biome_configuration/src/json.rs Lines 33 to 39 in fc9b1eb
biome/crates/biome_service/src/settings.rs Lines 478 to 479 in fc9b1eb
I think we should keep consistent about using biome/crates/biome_service/src/settings.rs Lines 942 to 946 in fc9b1eb
Edit:
Actually, this is not reliable, file source cannot reliably distinguish different format options specified in overrides. So when different options are specified in different override entries for files with the same file source type, only one of them will win. We should use the matched patterns as the cache key. If two files match the same set of overrides patterns, and they have the same file source type, they should share the settings. |
This appears to be a much larger issue than I originally thought. It's clear that the current caching approach is not semantically correct. Would it be acceptable to disable caching parser options for json files to unblock #3246, and open an issue to continue discussion? |
My 2 cents are holding that PR for a bit before we really understand how this bug is triggered. For example, I seem to not understand why biome/crates/biome_service/src/settings.rs Lines 1104 to 1105 in fc9b1eb
|
I must have made a mistake in my previous testing. |
In that case, only disabling caching will not solve the problem. So I guess we should address this first:
I'll need some confirmation and thoughts from @ematipico before heading towards this direction. But I also would like to know if you want to take up this refactoring task if that's the decision? :) @dyc3 |
Yeah, I can take a shot at it. I can change this PR to just have the test (disabled) since it's already here. |
…de special parsing options
8ebe45f
to
37db33d
Compare
Yes, I think we made a small mistake when implementing some options, some of which are And also, yes, I think it's time to have a method called Sorry @dyc3 for this mess, I know you had great intentions for the |
I've posted the |
Summary
This one is kinda weird, and this doesn't really feel like the correct fix. I'm unfamiliar with this area of the codebase.
If an override is applied to a json file that is considered "well known" to be parsed with trailing commas and/or comments, then those settings will not be applied because the override is present (not necessarily using the override's value, if the settings are cached).
For example, if we add the following override to this repo's
biome.json
, runningbiome check
will fail, even though it should be effectively a no-op.Note that json files that have different default parsing settings, that also match the override must be checked. The following command does not reproduce the issue:
This PR aims to fix this behavior, allowing the settings fromThis PR now just adds a disabled unit test for the correct behavior.JsonFileSource
take more precedence if the settings aretrue
.I'd like to know more about the purpose of caching the settings.
Removing this cache read branch from the following code also fixes the issue:(After testing it again, this change actually doesn't fix it)biome/crates/biome_service/src/settings.rs
Lines 1095 to 1100 in cc65fe8
blocks: #3246
tangentally related to: #1724
additional context: #3246 (comment)
Test Plan
The following command now runs without emitting diagnostics, with the override applied to
biome.json
.Planning to add a specific unit test.