Skip to content

Commit

Permalink
feat: change to lint/plugin for consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
wanghaoPolar committed Feb 24, 2025
1 parent ba70dee commit 24992b3
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 44 deletions.
2 changes: 1 addition & 1 deletion crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ pub fn to_analyzer_suppressions(
for (key, subcategory, value) in suppression.categories {
if key == category!("lint") {
result.push(AnalyzerSuppression::everything().with_variant(&suppression.kind));
} else if key == category!("plugin") {
} else if key == category!("lint/plugin") {
let suppression = AnalyzerSuppression::plugin(subcategory)
.with_ignore_range(ignore_range)
.with_variant(&suppression.kind);
Expand Down
12 changes: 6 additions & 6 deletions crates/biome_analyze/src/suppressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use biome_diagnostics::category;
use biome_rowan::{TextRange, TextSize};
use rustc_hash::{FxHashMap, FxHashSet};

const PLUGIN_RULE_FILTER: RuleFilter<'static> = RuleFilter::Group("plugin");
const PLUGIN_LINT_RULE_FILTER: RuleFilter<'static> = RuleFilter::Group("lint/plugin");

#[derive(Debug, Default)]
pub struct TopLevelSuppression {
Expand Down Expand Up @@ -54,7 +54,7 @@ impl TopLevelSuppression {
// The absence of a filter means that it's a suppression all
match filter {
None => self.suppress_all = true,
Some(PLUGIN_RULE_FILTER) => self.insert_plugin(&suppression.kind),
Some(PLUGIN_LINT_RULE_FILTER) => self.insert_plugin(&suppression.kind),
Some(filter) => self.insert(filter),
}
self.comment_range = comment_range;
Expand Down Expand Up @@ -166,7 +166,7 @@ impl RangeSuppressions {
text_range: TextRange,
already_suppressed: Option<TextRange>,
) -> Result<(), AnalyzerSuppressionDiagnostic> {
if let Some(PLUGIN_RULE_FILTER) = filter {
if let Some(PLUGIN_LINT_RULE_FILTER) = filter {
return Err(AnalyzerSuppressionDiagnostic::new(
category!("suppressions/incorrect"),
text_range,
Expand Down Expand Up @@ -322,7 +322,7 @@ impl<'analyzer> Suppressions<'analyzer> {
suppression.suppressed_instances.clear();
suppression.suppressed_plugins.clear();
}
Some(PLUGIN_RULE_FILTER) => {
Some(PLUGIN_LINT_RULE_FILTER) => {
if let Some(plugin_name) = plugin_name {
suppression.suppressed_plugins.insert(plugin_name);
suppression.suppress_all_plugins = false;
Expand Down Expand Up @@ -354,7 +354,7 @@ impl<'analyzer> Suppressions<'analyzer> {
None => {
suppression.suppress_all = true;
}
Some(PLUGIN_RULE_FILTER) => {
Some(PLUGIN_LINT_RULE_FILTER) => {
if let Some(plugin_name) = plugin_name {
suppression.suppressed_plugins.insert(plugin_name);
} else {
Expand Down Expand Up @@ -383,7 +383,7 @@ impl<'analyzer> Suppressions<'analyzer> {
AnalyzerSuppressionKind::Everything => return Ok(None),
AnalyzerSuppressionKind::Rule(rule) => rule,
AnalyzerSuppressionKind::RuleInstance(rule, _) => rule,
AnalyzerSuppressionKind::Plugin(_) => return Ok(Some(PLUGIN_RULE_FILTER)),
AnalyzerSuppressionKind::Plugin(_) => return Ok(Some(PLUGIN_LINT_RULE_FILTER)),
};

let group_rule = rule.split_once('/');
Expand Down
1 change: 1 addition & 0 deletions crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ define_categories! {
"lint/security",
"lint/style",
"lint/suspicious",
"lint/plugin",

// Suppression comments
"suppressions/parse",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ expression: preferObjectSpreadSuppression.grit
---
# Input
```js
// biome-ignore plugin/preferObjectSpreadSuppression: reason
// biome-ignore lint/plugin/preferObjectSpreadSuppression: reason
Object.assign({ foo: 'bar'}, baz);
// biome-ignore-start plugin/preferObjectSpreadSuppression: reason
// biome-ignore-start lint/plugin/preferObjectSpreadSuppression: reason
Object.assign({}, {foo: 'bar'});
// biome-ignore-end plugin/preferObjectSpreadSuppression: reason
// biome-ignore-end lint/plugin/preferObjectSpreadSuppression: reason
// if no name is specified, should suppress all plugins
// biome-ignore plugin: reason
// biome-ignore lint/plugin: reason
Object.assign({}, foo);
// only suppress specified plugin
// biome-ignore plugin/anotherPlugin: reason
// biome-ignore lint/plugin/anotherPlugin: reason
Object.assign({ foo: 'bar'}, baz);
```
Expand All @@ -30,10 +30,10 @@ preferObjectSpreadSuppression.grit:4:1 suppressions/incorrect ━━━━━━
2 │ Object.assign({ foo: 'bar'}, baz);
3 │
> 4 │ // biome-ignore-start plugin/preferObjectSpreadSuppression: reason
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 4 │ // biome-ignore-start lint/plugin/preferObjectSpreadSuppression: reason
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5 │ Object.assign({}, {foo: 'bar'});
6 │ // biome-ignore-end plugin/preferObjectSpreadSuppression: reason
6 │ // biome-ignore-end lint/plugin/preferObjectSpreadSuppression: reason
i Remove this suppression.
Expand All @@ -45,10 +45,10 @@ preferObjectSpreadSuppression.grit:6:1 suppressions/incorrect ━━━━━━
! Found a biome-ignore-<range> suppression on plugin. This is not supported. See https://github.com/biomejs/biome/issues/5175
4 │ // biome-ignore-start plugin/preferObjectSpreadSuppression: reason
4 │ // biome-ignore-start lint/plugin/preferObjectSpreadSuppression: reason
5 │ Object.assign({}, {foo: 'bar'});
> 6 │ // biome-ignore-end plugin/preferObjectSpreadSuppression: reason
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 6 │ // biome-ignore-end lint/plugin/preferObjectSpreadSuppression: reason
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7 │
8 │ // if no name is specified, should suppress all plugins
Expand All @@ -62,10 +62,10 @@ preferObjectSpreadSuppression.grit:5:15 plugin ━━━━━━━━━━━
! Prefer object spread instead of `Object.assign()`
4 │ // biome-ignore-start plugin/preferObjectSpreadSuppression: reason
4 │ // biome-ignore-start lint/plugin/preferObjectSpreadSuppression: reason
> 5 │ Object.assign({}, {foo: 'bar'});
│ ^^^^^^^^^^^^^^^^
6 │ // biome-ignore-end plugin/preferObjectSpreadSuppression: reason
6 │ // biome-ignore-end lint/plugin/preferObjectSpreadSuppression: reason
7 │
Expand All @@ -77,7 +77,7 @@ preferObjectSpreadSuppression.grit:14:15 plugin ━━━━━━━━━━
! Prefer object spread instead of `Object.assign()`
12 │ // only suppress specified plugin
13 │ // biome-ignore plugin/anotherPlugin: reason
13 │ // biome-ignore lint/plugin/anotherPlugin: reason
> 14 │ Object.assign({ foo: 'bar'}, baz);
│ ^^^^^^^^^^^^^^^^^^
15 │
Expand All @@ -91,8 +91,8 @@ preferObjectSpreadSuppression.grit:13:1 suppressions/unused ━━━━━━
! Suppression comment has no effect. Remove the suppression or make sure you are suppressing the correct rule.
12 │ // only suppress specified plugin
> 13 │ // biome-ignore plugin/anotherPlugin: reason
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 13 │ // biome-ignore lint/plugin/anotherPlugin: reason
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14 │ Object.assign({ foo: 'bar'}, baz);
15 │
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// biome-ignore plugin/preferObjectSpreadSuppression: reason
// biome-ignore lint/plugin/preferObjectSpreadSuppression: reason
Object.assign({ foo: 'bar'}, baz);

// biome-ignore-start plugin/preferObjectSpreadSuppression: reason
// biome-ignore-start lint/plugin/preferObjectSpreadSuppression: reason
Object.assign({}, {foo: 'bar'});
// biome-ignore-end plugin/preferObjectSpreadSuppression: reason
// biome-ignore-end lint/plugin/preferObjectSpreadSuppression: reason

// if no name is specified, should suppress all plugins
// biome-ignore plugin: reason
// biome-ignore lint/plugin: reason
Object.assign({}, foo);

// only suppress specified plugin
// biome-ignore plugin/anotherPlugin: reason
// biome-ignore lint/plugin/anotherPlugin: reason
Object.assign({ foo: 'bar'}, baz);
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: preferObjectSpreadSuppressionAll.grit
---
# Input
```js
// biome-ignore-all plugin/preferObjectSpreadSuppressionAll: reason
// biome-ignore-all lint/plugin/preferObjectSpreadSuppressionAll: reason
console.log("foo");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// biome-ignore-all plugin/preferObjectSpreadSuppressionAll: reason
// biome-ignore-all lint/plugin/preferObjectSpreadSuppressionAll: reason

console.log("foo");

Expand Down
30 changes: 16 additions & 14 deletions crates/biome_suppression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ fn parse_suppression_line(
///
/// # Example
/// - No category: `// biome-ignore` -> `(None, None)`
/// - Custom Plugin: `// biome-ignore plugin/my-plugin` -> `("plugin", "my-plugin")`
/// - Custom Plugin: `// biome-ignore lint/plugin/myPlugin` -> `("lint/plugin", "myPlugin")`
/// - Valid category: `// biome-ignore lint/complexity` -> `("lint/complexity", None)`
/// - Invalid category: `// biome-ignore linx` -> `Err(SuppressionDiagnostic)`
fn parse_category<'a>(
Expand All @@ -326,11 +326,10 @@ fn parse_category<'a>(
if category.is_empty() {
return Ok((None, None));
}
if let Some(rest) = category.strip_prefix("plugin/") {
// only handle specified plugin here: e.g. `// biome-ignore plugin/myPlugin: reason`
return Ok(("plugin".parse().ok(), Some(rest)));
// if user doesn't specify plugin name: e.g. `// biome-ignore plugin: reason`
// will return ("plugin", None) and treat as `suppress all plugins`
if let Some(rest) = category.strip_prefix("lint/plugin/") {
return Ok(("lint/plugin".parse().ok(), Some(rest)));
// if user doesn't specify plugin name: e.g. `// biome-ignore lint/plugin: reason`
// will return ("lint/plugin", None) and treat as `suppress all plugins linting`
}
let category: &'static Category = category.parse().map_err(|()| SuppressionDiagnostic {
message: SuppressionDiagnosticKind::ParseCategory(category.into()),
Expand Down Expand Up @@ -506,20 +505,21 @@ mod tests_biome_ignore_inline {
);

assert_eq!(
parse_suppression_comment("// biome-ignore plugin: explanation5").collect::<Vec<_>>(),
parse_suppression_comment("// biome-ignore lint/plugin: explanation5")
.collect::<Vec<_>>(),
vec![Ok(Suppression {
categories: vec![(category!("plugin"), None, None)],
categories: vec![(category!("lint/plugin"), None, None)],
reason: "explanation5",
kind: SuppressionKind::Classic,
range: TextRange::new(TextSize::from(3), TextSize::from(15))
})],
);

assert_eq!(
parse_suppression_comment("// biome-ignore plugin/myPlugin: explanation6")
parse_suppression_comment("// biome-ignore lint/plugin/myPlugin: explanation6")
.collect::<Vec<_>>(),
vec![Ok(Suppression {
categories: vec![(category!("plugin"), Some("myPlugin"), None)],
categories: vec![(category!("lint/plugin"), Some("myPlugin"), None)],
reason: "explanation6",
kind: SuppressionKind::Classic,
range: TextRange::new(TextSize::from(3), TextSize::from(15))
Expand Down Expand Up @@ -630,13 +630,12 @@ mod tests_biome_ignore_inline {
#[test]
fn parse_multiple_suppression_categories() {
assert_eq!(
parse_suppression_comment("// biome-ignore format lint plugin: explanation")
parse_suppression_comment("// biome-ignore format lint: explanation")
.collect::<Vec<_>>(),
vec![Ok(Suppression {
categories: vec![
(category!("format"), None, None),
(category!("lint"), None, None),
(category!("plugin"), None, None),
],
reason: "explanation",
kind: SuppressionKind::Classic,
Expand All @@ -653,8 +652,11 @@ mod tests_biome_ignore_inline {
);

assert_eq!(
parse_category("// biome-ignore plugin/myPlugin: reason", "plugin/myPlugin"),
Ok((Some(category!("plugin")), Some("myPlugin")))
parse_category(
"// biome-ignore lint/plugin/myPlugin: reason",
"lint/plugin/myPlugin"
),
Ok((Some(category!("lint/plugin")), Some("myPlugin")))
);

assert_eq!(
Expand Down
1 change: 1 addition & 0 deletions packages/@biomejs/backend-jsonrpc/src/workspace.ts

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

0 comments on commit 24992b3

Please sign in to comment.