Skip to content

Commit

Permalink
refactor(analyze): add language field to rule metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
dyc3 committed May 11, 2024
1 parent 50c270e commit ff18ad5
Show file tree
Hide file tree
Showing 247 changed files with 264 additions and 4 deletions.
18 changes: 16 additions & 2 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ pub struct RuleMetadata {
pub name: &'static str,
/// The content of the documentation comments for this rule
pub docs: &'static str,
/// The language that the rule applies to.
pub language: &'static str,
/// Whether a rule is recommended or not
pub recommended: bool,
/// The kind of fix
Expand Down Expand Up @@ -242,12 +244,18 @@ impl RuleSourceKind {
}

impl RuleMetadata {
pub const fn new(version: &'static str, name: &'static str, docs: &'static str) -> Self {
pub const fn new(
version: &'static str,
name: &'static str,
docs: &'static str,
language: &'static str,
) -> Self {
Self {
deprecated: None,
version,
name,
docs,
language,
recommended: false,
fix_kind: None,
sources: &[],
Expand Down Expand Up @@ -282,6 +290,11 @@ impl RuleMetadata {
self.source_kind = Some(source_kind);
self
}

pub const fn language(mut self, language: &'static str) -> Self {
self.language = language;
self
}
}

pub trait RuleMeta {
Expand Down Expand Up @@ -315,6 +328,7 @@ macro_rules! declare_rule {
( $( #[doc = $doc:literal] )+ $vis:vis $id:ident {
version: $version:literal,
name: $name:tt,
language: $language:literal,
$( $key:ident: $value:expr, )*
} ) => {
$( #[doc = $doc] )*
Expand All @@ -323,7 +337,7 @@ macro_rules! declare_rule {
impl $crate::RuleMeta for $id {
type Group = super::Group;
const METADATA: $crate::RuleMetadata =
$crate::RuleMetadata::new($version, $name, concat!( $( $doc, "\n", )* )) $( .$key($value) )*;
$crate::RuleMetadata::new($version, $name, concat!( $( $doc, "\n", )* ), $language) $( .$key($value) )*;
}

// Declare a new `rule_category!` macro in the module context that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare_rule! {
pub NoColorInvalidHex {
version: "next",
name: "noColorInvalidHex",
language: "css",
recommended: false,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ declare_rule! {
pub NoCssEmptyBlock {
version: "next",
name: "noCssEmptyBlock",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("no-empty-block")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare_rule! {
pub NoDuplicateAtImportRules {
version: "next",
name: "noDuplicateAtImportRules",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("no-duplicate-at-import-rules")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ declare_rule! {
pub NoDuplicateFontNames {
version: "next",
name: "noDuplicateFontNames",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("font-family-no-duplicate-names")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ declare_rule! {
pub NoDuplicateSelectorsKeyframeBlock {
version: "next",
name: "noDuplicateSelectorsKeyframeBlock",
language: "css",
recommended: true,
sources:&[RuleSource::Stylelint("keyframe-block-no-duplicate-selectors")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare_rule! {
pub NoImportantInKeyframe {
version: "next",
name: "noImportantInKeyframe",
language: "css",
recommended: true,
sources:&[RuleSource::Stylelint("keyframe-declaration-no-important")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ declare_rule! {
pub NoInvalidPositionAtImportRule {
version: "next",
name: "noInvalidPositionAtImportRule",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("no-invalid-position-at-import-rule")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ declare_rule! {
pub NoUnknownFunction {
version: "next",
name: "noUnknownFunction",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("function-no-unknown")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ declare_rule! {
pub NoUnknownMediaFeatureName {
version: "next",
name: "noUnknownMediaFeatureName",
language: "css",
recommended: false,
sources: &[RuleSource::Stylelint("media-feature-name-no-unknown")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ declare_rule! {
pub NoUnknownProperty {
version: "next",
name: "noUnknownProperty",
language: "css",
recommended: false,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ declare_rule! {
pub NoUnknownSelectorPseudoElement {
version: "next",
name: "noUnknownSelectorPseudoElement",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("selector-pseudo-element-no-unknown")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ declare_rule! {
pub NoUnknownUnit {
version: "next",
name: "noUnknownUnit",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("unit-no-unknown")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ declare_rule! {
pub NoUnmatchableAnbSelector {
version: "next",
name: "noUnmatchableAnbSelector",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("selector-anb-no-unmatchable")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare_rule! {
pub UseGenericFontNames {
version: "next",
name: "useGenericFontNames",
language: "css",
recommended: true,
sources: &[RuleSource::Stylelint("font-family-no-missing-generic-family-keyword")],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ declare_rule! {
pub OrganizeImports {
version: "1.0.0",
name: "organizeImports",
language: "js",
recommended: false,
fix_kind: FixKind::Unsafe,
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/no_access_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ declare_rule! {
pub NoAccessKey {
version: "1.0.0",
name: "noAccessKey",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-access-key")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ declare_rule! {
pub NoAriaHiddenOnFocusable {
version: "1.4.0",
name: "noAriaHiddenOnFocusable",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-aria-hidden-on-focusable")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ declare_rule! {
pub NoAriaUnsupportedElements {
version: "1.0.0",
name: "noAriaUnsupportedElements",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("aria-unsupported-elements")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/no_autofocus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ declare_rule! {
pub NoAutofocus {
version: "1.0.0",
name: "noAutofocus",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-autofocus")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/no_blank_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare_rule! {
pub NoBlankTarget {
version: "1.0.0",
name: "noBlankTarget",
language: "jsx",
sources: &[RuleSource::EslintReact("jsx-no-target-blank")],
recommended: true,
fix_kind: FixKind::Safe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ declare_rule! {
pub NoDistractingElements {
version: "1.0.0",
name: "noDistractingElements",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-distracting-elements")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/no_header_scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ declare_rule! {
pub NoHeaderScope {
version: "1.0.0",
name: "noHeaderScope",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("scope")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ declare_rule! {
pub NoInteractiveElementToNoninteractiveRole {
version: "1.3.0",
name: "noInteractiveElementToNoninteractiveRole",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-interactive-element-to-noninteractive-role")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ declare_rule! {
pub NoNoninteractiveElementToInteractiveRole {
version: "1.0.0",
name: "noNoninteractiveElementToInteractiveRole",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-noninteractive-element-to-interactive-role")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare_rule! {
pub NoNoninteractiveTabindex {
version: "1.0.0",
name: "noNoninteractiveTabindex",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-noninteractive-tabindex")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare_rule! {
pub NoPositiveTabindex {
version: "1.0.0",
name: "noPositiveTabindex",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("tabindex-no-positive")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/no_redundant_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare_rule! {
pub NoRedundantAlt {
version: "1.0.0",
name: "noRedundantAlt",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("img-redundant-alt")],
recommended: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare_rule! {
pub NoRedundantRoles {
version: "1.0.0",
name: "noRedundantRoles",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("no-redundant-roles")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ declare_rule! {
pub NoSvgWithoutTitle {
version: "1.0.0",
name: "noSvgWithoutTitle",
language: "jsx",
recommended: true,
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/use_alt_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ declare_rule! {
pub UseAltText {
version: "1.0.0",
name: "useAltText",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("alt-text")],
recommended: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ declare_rule! {
pub UseAnchorContent {
version: "1.0.0",
name: "useAnchorContent",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("anchor-has-content")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ declare_rule! {
pub UseAriaActivedescendantWithTabindex {
version: "1.3.0",
name: "useAriaActivedescendantWithTabindex",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("aria-activedescendant-has-tabindex")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ declare_rule! {
pub UseAriaPropsForRole {
version: "1.0.0",
name: "useAriaPropsForRole",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("role-has-required-aria-props")],
recommended: true,
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/use_button_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ declare_rule! {
pub UseButtonType {
version: "1.0.0",
name: "useButtonType",
language: "jsx",
sources: &[RuleSource::EslintReact("button-has-type")],
recommended: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ declare_rule! {
pub UseHeadingContent {
version: "1.0.0",
name: "useHeadingContent",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("heading-has-content")],
recommended: true,
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/use_html_lang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ declare_rule! {
pub UseHtmlLang {
version: "1.0.0",
name: "useHtmlLang",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("html-has-lang")],
recommended: true,
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/use_iframe_title.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ declare_rule! {
pub UseIframeTitle {
version: "1.0.0",
name: "useIframeTitle",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("iframe-has-title")],
recommended: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ declare_rule! {
pub UseKeyWithClickEvents {
version: "1.0.0",
name: "useKeyWithClickEvents",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("click-events-have-key-events")],
recommended: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare_rule! {
pub UseKeyWithMouseEvents {
version: "1.0.0",
name: "useKeyWithMouseEvents",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("mouse-events-have-key-events")],
recommended: true,
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/use_media_caption.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ declare_rule! {
pub UseMediaCaption {
version: "1.0.0",
name: "useMediaCaption",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("media-has-caption")],
recommended: true,
}
Expand Down
1 change: 1 addition & 0 deletions crates/biome_js_analyze/src/lint/a11y/use_valid_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ declare_rule! {
pub UseValidAnchor {
version: "1.0.0",
name: "useValidAnchor",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("anchor-is-valid")],
recommended: true,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ declare_rule! {
pub UseValidAriaProps {
version: "1.0.0",
name: "useValidAriaProps",
language: "jsx",
sources: &[RuleSource::EslintJsxA11y("aria-props")],
recommended: true,
fix_kind: FixKind::Unsafe,
Expand Down
Loading

0 comments on commit ff18ad5

Please sign in to comment.