Skip to content
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

refactor(analyzer): severity in metadata #4634

Open
wants to merge 1 commit into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ use biome_console::fmt::Display;
use biome_console::{markup, MarkupBuf};
use biome_diagnostics::advice::CodeSuggestionAdvice;
use biome_diagnostics::location::AsSpan;
use biome_diagnostics::Applicability;
use biome_diagnostics::{
Advices, Category, Diagnostic, DiagnosticTags, Location, LogCategory, MessageAndDescription,
Visit,
};
use biome_diagnostics::{Applicability, Severity};
use biome_rowan::{AstNode, BatchMutation, BatchMutationExt, Language, TextRange};
use std::borrow::Cow;
use std::cmp::Ordering;
Expand Down Expand Up @@ -41,6 +41,8 @@ pub struct RuleMetadata {
pub sources: &'static [RuleSource],
/// The source kind of the rule
pub source_kind: Option<RuleSourceKind>,
/// The default severity of the rule
pub severity: Severity,
}

#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
Expand Down Expand Up @@ -328,6 +330,7 @@ impl RuleMetadata {
fix_kind: FixKind::None,
sources: &[],
source_kind: None,
severity: Severity::Information,
}
}

Expand Down Expand Up @@ -364,6 +367,11 @@ impl RuleMetadata {
self
}

pub const fn severity(mut self, severity: Severity) -> Self {
self.severity = severity;
self
}

pub fn applicability(&self) -> Applicability {
self.fix_kind
.try_into()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use biome_css_syntax::{
AnyCssAtRule, AnyCssGenericComponentValue, AnyCssValue, CssAtRule,
CssGenericComponentValueList, CssGenericProperty, CssSyntaxKind,
};
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, SyntaxNodeCast, TextRange};
use biome_string_case::StrLikeExtension;

Expand Down Expand Up @@ -65,6 +66,7 @@ declare_lint_rule! {
name: "useGenericFontNames",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("font-family-no-missing-generic-family-keyword")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::{CssFunction, CssParameter};
use biome_diagnostics::Severity;
use biome_rowan::AstNode;
use biome_rowan::AstSeparatedList;
use biome_string_case::StrLikeExtension;
Expand Down Expand Up @@ -47,6 +48,7 @@ declare_lint_rule! {
name: "noInvalidDirectionInLinearGradient",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("function-linear-gradient-no-nonstandard-direction")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::CssDeclarationOrRuleList;
use biome_diagnostics::Severity;
use biome_rowan::{TextRange, TokenText};

use rustc_hash::FxHashSet;
Expand Down Expand Up @@ -53,6 +54,7 @@ declare_lint_rule! {
name: "noInvalidGridAreas",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("named-grid-areas-no-invalid")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::{AnyCssRule, CssRuleList};
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, TextRange};

declare_lint_rule! {
Expand Down Expand Up @@ -31,6 +32,7 @@ declare_lint_rule! {
name: "noInvalidPositionAtImportRule",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("no-invalid-position-at-import-rule")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::CssFunction;
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, TextRange};

use crate::utils::{is_custom_function, is_function_keyword};
Expand Down Expand Up @@ -36,6 +37,7 @@ declare_lint_rule! {
name: "noUnknownFunction",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("function-no-unknown")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use biome_css_syntax::{
AnyCssMediaTypeQuery, AnyCssQueryFeature, CssMediaAndCondition, CssMediaConditionQuery,
CssMediaOrCondition, CssMediaQueryList,
};
use biome_diagnostics::Severity;
use biome_rowan::AstNode;

use crate::utils::is_media_feature_name;
Expand Down Expand Up @@ -71,6 +72,7 @@ declare_lint_rule! {
name: "noUnknownMediaFeatureName",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("media-feature-name-no-unknown")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::CssGenericProperty;
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, TextRange};
use biome_string_case::StrLikeExtension;

Expand Down Expand Up @@ -61,6 +62,7 @@ declare_lint_rule! {
name: "noUnknownProperty",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("property-no-unknown")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use biome_console::markup;
use biome_css_syntax::{
AnyCssDimension, CssFunction, CssGenericProperty, CssQueryFeaturePlain, CssSyntaxKind,
};
use biome_diagnostics::Severity;
use biome_rowan::{SyntaxNodeCast, TextRange};
use biome_string_case::StrLikeExtension;

Expand Down Expand Up @@ -64,6 +65,7 @@ declare_lint_rule! {
name: "noUnknownUnit",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("unit-no-unknown")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use biome_console::markup;
use biome_css_syntax::{
AnyCssPseudoClassNth, CssPseudoClassFunctionSelectorList, CssPseudoClassNthSelector,
};
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, SyntaxNodeCast};

declare_lint_rule! {
Expand Down Expand Up @@ -57,6 +58,7 @@ declare_lint_rule! {
name: "noUnmatchableAnbSelector",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("selector-anb-no-unmatchable")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use biome_analyze::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnosti
use biome_console::markup;
use biome_css_semantic::model::{Rule as CssSemanticRule, RuleId, SemanticModel, Specificity};
use biome_css_syntax::{AnyCssSelector, CssRoot};
use biome_diagnostics::Severity;
use biome_rowan::TextRange;

use biome_rowan::AstNode;
Expand Down Expand Up @@ -76,6 +77,7 @@ declare_lint_rule! {
name: "noDescendingSpecificity",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("no-descending-specificity")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::hash_map::Entry;
use biome_analyze::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_css_syntax::CssDeclarationOrRuleList;
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, TextRange};
use rustc_hash::FxHashMap;

Expand Down Expand Up @@ -40,6 +41,7 @@ declare_lint_rule! {
name: "noDuplicateCustomProperties",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("declaration-block-no-duplicate-custom-properties")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::{borrow::Cow, collections::hash_map::Entry};
use biome_analyze::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_css_syntax::CssDeclarationOrRuleList;
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, TextRange};
use biome_string_case::StrOnlyExtension;
use rustc_hash::FxHashMap;
Expand Down Expand Up @@ -39,6 +40,7 @@ declare_lint_rule! {
name: "noDuplicateProperties",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("declaration-block-no-duplicate-properties")],
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use biome_analyze::{context::RuleContext, declare_lint_rule, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_css_syntax::{AnyCssProperty, CssDashedIdentifier, CssDeclaration, CssSyntaxKind};
use biome_diagnostics::Severity;
use biome_rowan::AstNode;

use crate::services::semantic::Semantic;
Expand Down Expand Up @@ -117,6 +118,7 @@ declare_lint_rule! {
name: "noMissingVarFunction",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("custom-property-no-missing-var-function")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use biome_css_syntax::{
CssPseudoClassFunctionSelector, CssPseudoClassFunctionSelectorList,
CssPseudoClassFunctionValueList, CssPseudoClassIdentifier, CssPseudoElementSelector,
};
use biome_diagnostics::Severity;
use biome_rowan::{declare_node_union, AstNode, TextRange};
use biome_string_case::StrLikeExtension;

Expand Down Expand Up @@ -62,6 +63,7 @@ declare_lint_rule! {
name: "noUnknownPseudoClass",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("selector-pseudo-class-no-unknown")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::{AnyCssPseudoElement, CssPseudoElementSelector};
use biome_diagnostics::Severity;
use biome_rowan::AstNode;
use biome_string_case::StrLikeExtension;

Expand Down Expand Up @@ -54,6 +55,7 @@ declare_lint_rule! {
name: "noUnknownPseudoElement",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("selector-pseudo-element-no-unknown")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::CssTypeSelector;
use biome_diagnostics::Severity;
use biome_rowan::AstNode;

use crate::utils::is_known_type_selector;
Expand Down Expand Up @@ -54,6 +55,7 @@ declare_lint_rule! {
name: "noUnknownTypeSelector",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("selector-type-no-unknown")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::{AnyCssAtRule, AnyCssRule, CssImportAtRule, CssRuleList};
use biome_diagnostics::Severity;
use biome_rowan::AstNode;
use biome_string_case::StrOnlyExtension;

Expand Down Expand Up @@ -51,6 +52,7 @@ declare_lint_rule! {
name: "noDuplicateAtImportRules",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("no-duplicate-at-import-rules")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::{AnyCssGenericComponentValue, AnyCssValue, CssGenericProperty};
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, TextRange};
use biome_string_case::StrLikeExtension;

Expand Down Expand Up @@ -48,6 +49,7 @@ declare_lint_rule! {
name: "noDuplicateFontNames",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("font-family-no-duplicate-names")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::{AnyCssKeyframesItem, AnyCssKeyframesSelector, CssKeyframesBlock};
use biome_diagnostics::Severity;
use biome_rowan::AstNode;
use biome_string_case::StrLikeExtension;

Expand Down Expand Up @@ -42,6 +43,7 @@ declare_lint_rule! {
name: "noDuplicateSelectorsKeyframeBlock",
language: "css",
recommended: true,
severity: Severity::Error,
sources:&[RuleSource::Stylelint("keyframe-block-no-duplicate-selectors")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::stmt_ext::CssBlockLike;
use biome_diagnostics::Severity;
use biome_rowan::AstNode;

declare_lint_rule! {
Expand Down Expand Up @@ -47,6 +48,7 @@ declare_lint_rule! {
name: "noEmptyBlock",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("block-no-empty")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use biome_console::markup;
use biome_css_syntax::{
AnyCssDeclarationBlock, AnyCssKeyframesItem, CssDeclarationImportant, CssKeyframesBlock,
};
use biome_diagnostics::Severity;
use biome_rowan::AstNode;

declare_lint_rule! {
Expand Down Expand Up @@ -45,6 +46,7 @@ declare_lint_rule! {
name: "noImportantInKeyframe",
language: "css",
recommended: true,
severity: Severity::Error,
sources:&[RuleSource::Stylelint("keyframe-declaration-no-important")],
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use biome_analyze::{
};
use biome_console::markup;
use biome_css_syntax::{AnyCssDeclarationName, CssGenericProperty, CssLanguage, CssSyntaxKind};
use biome_diagnostics::Severity;
use biome_rowan::{AstNode, Language, SyntaxNode, TextRange, WalkEvent};

fn remove_vendor_prefix<'a>(prop: &'a str, prefix: &'a str) -> &'a str {
Expand Down Expand Up @@ -72,6 +73,7 @@ declare_lint_rule! {
name: "noShorthandPropertyOverrides",
language: "css",
recommended: true,
severity: Severity::Error,
sources: &[RuleSource::Stylelint("declaration-block-no-shorthand-property-overrides")],
}
}
Expand Down
Loading