-
-
Notifications
You must be signed in to change notification settings - Fork 534
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: add plugin suppression #5139
feat: add plugin suppression #5139
Conversation
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.
Great work! Just left a few comments.
Hi @arendjr , thanks for help reviewing! I pushed 2 new commit: In a7e06b6 I fixed the above issues you raised:
In ba70dee I handled the case of |
CodSpeed Performance ReportMerging #5139 will not alter performanceComparing Summary
|
24992b3 : change syntax to |
589d85b
to
24992b3
Compare
Perhaps I should disallow the usage of |
Our linter allows suppressing all rules that belong to a group e.g. Plus, with the arrival of new suppressions like the top-level suppression, it's something that users might need |
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.
Thanks so much!
@arendjr any chance to address my comment? #5139 (comment) |
Of course!
The way I understood it, the PR allows this in its current form, and @wanghaoPolar was contemplating whether to disallow it because they saw no use case for it. Based on your comment I also thought we might want to keep it as is, so I merged as is. Let me know if I misunderstood! |
Yes, in current implementation using 'lint/plugin' disables diagnosis raised by all plugins. In my previous comment I was asking if I should disallow it instead. |
task: #4667
Plugin Suppression
changes are split into 2 parts:
Part 1: Changes to data structs in each step of existing lint suppression workflow
plugin suppression reuse most of the existing lint suppression workflow, but new fields are added to handle dynamic plugin names that users input.
Step 1: parse comment string to Suppression<'a>
file: crates/biome_suppression/src/lib.rs
each suppression comment is parse a single Suppression<'a>
here, a new 'subcategory' is added to the parse result
In the case for plugin, category will be 'plugin', and subcategory will be the custom plugin name that users input
Step 2: Suppression<'a> processed into AnalyzerSuppression
file: crates/biome_analyze/src/lib.rs
Suppression<'a> is then processed into AnalyzerSuppression
previously AnalyzerSuppression.kind has 3 variants:
Everything, Rule(&'a str), RuleInstance(&'a str, &'a str)
a new variant
Plugin(&'a str)
is added for pluginStep 3: AnalyzerSuppression pushed to PhaseRunner.suppression
see crates/biome_analyze/src/suppressions.rs
top level suppression, new field
plugins
is addedfor line suppression, new field
suppressed_plugins
is addedfor range suppression
range suppression for plugin is not supported, and an error is reported if there is a range suppression for plugin
the reason it's not supported is because plugin is run after lint phases.
During lint phase, range suppressions are dynamiclly updated while parsing
// biome-range-start
and// biome-range-end
.after lint phases are finished, all range suppressions have empty filters.
Why not reuse current Category/RuleFilter to avoid adding new fileds
in optimal cases, we can treat
plugin/xxx
same aslint/xxx
to avoid adding new fields and making changes to exising workflow.however, currently it's not implemented as such because step 1 and 3 of above section both require pre-register static string and codegen, thus doesn't allow for dynamic values.
but for plugin, it must allow user to use dynamic plugin names.
step 1:
Suppression<'a> stores &'a Category instead of arbitrary string
but we cannot init a new
Category
outside of thebiome_diagnostics_categories
crate, which serves as a registry for all known diagnostic categories (currently this registry is fully static and generated at compile time).step 3:
filter is required to be a RuleFilter<'static>
see
map_to_rule_filter
incrates/biome_analyze/src/suppressions.rs
, this requires the group/rule to be registered in MetadataRegistry, which is currently done during codegen usingdeclare_lint_group!
due to these 2 reasons, it will be troublesome to fit in the new plugin suppression into existing flow without adding new fields.
Part 2: Handle plugin diagnosis
Plugins are run after exiting lint runners are finished.
During plugin evaluation, everytime there is a diagnosis, we will check to see if it is suppressed
see crates/biome_analyze/src/lib.rs, most logic is copied from
flush_matches
, except for:plugins
suppressed_plugins