Skip to content

Commit

Permalink
docs: improve list of rules, add data to rules metadata (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico authored Sep 27, 2023
1 parent ef7ef50 commit ae1021c
Show file tree
Hide file tree
Showing 256 changed files with 1,828 additions and 1,713 deletions.
7 changes: 7 additions & 0 deletions crates/biome_analyze/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ Let's say we want to create a new rule called `myRuleName`, which uses the seman

This function is called for every signal emitted by the `run` function.
It may return zero or one code action.
Rules can return a code action that can be **safe** or **unsafe**. If a rule returns a code action, you must add `fix_kind` to the macro `declare_rule`.
```rust,ignore
use biome_analyze::FixKind;
declare_rule!{
fix_kind: FixKind::Safe,
}
```
When returning a code action, you must pass the `category` and the `applicability` fields.
`category` must be `ActionCategory::QuickFix`.
`applicability` is either `Applicability:MaybeIncorrect` or `Applicability:Always`.
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub use crate::registry::{
RuleRegistry, RuleRegistryBuilder, RuleSuppressions,
};
pub use crate::rule::{
CategoryLanguage, GroupCategory, GroupLanguage, Rule, RuleAction, RuleDiagnostic, RuleGroup,
RuleMeta, RuleMetadata, SuppressAction,
CategoryLanguage, FixKind, GroupCategory, GroupLanguage, Rule, RuleAction, RuleDiagnostic,
RuleGroup, RuleMeta, RuleMetadata, SuppressAction,
};
pub use crate::services::{FromServices, MissingServicesDiagnostic, ServiceBag};
pub use crate::signals::{
Expand Down
18 changes: 18 additions & 0 deletions crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ pub struct RuleMetadata {
pub docs: &'static str,
/// Whether a rule is recommended or not
pub recommended: bool,
/// The kind of fix
pub fix_kind: Option<FixKind>,
}

#[derive(Debug, Eq, PartialEq)]
/// Used to identify the kind of code action emitted by a rule
pub enum FixKind {
/// The rule emits a code action that is safe to apply. Usually these fixes don't change the semantic of the program.
Safe,
/// The rule emits a code action that is _unsafe_ to apply. Usually these fixes remove comments, or change
/// the semantic of the program.
Unsafe,
}

impl RuleMetadata {
Expand All @@ -38,6 +50,7 @@ impl RuleMetadata {
name,
docs,
recommended: false,
fix_kind: None,
}
}

Expand All @@ -50,6 +63,11 @@ impl RuleMetadata {
self.deprecated = Some(deprecated);
self
}

pub const fn fix_kind(mut self, kind: FixKind) -> Self {
self.fix_kind = Some(kind);
self
}
}

pub trait RuleMeta {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test.js:1:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━
> 1 │ debugger; console.log("string");·
│ ^^^^^^^^^
i Suggested fix: Remove debugger statement
i Unsafe fix: Remove debugger statement
1 │ debugger;·console.log("string");·
│ ----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test.js:1:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━
> 1 │ debugger; console.log("string");·
│ ^^^^^^^^^
i Suggested fix: Remove debugger statement
i Unsafe fix: Remove debugger statement
1 │ debugger;·console.log("string");·
│ ----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ check.js:1:1 lint/correctness/noNewSymbol FIXABLE ━━━━━━━━━
> 1 │ new Symbol("");
│ ^^^^^^^^^^^^^^
i Suggested fix: Remove new.
i Unsafe fix: Remove new.
1 │ new·Symbol("");
│ ----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ file.js:1:1 suppressions/deprecatedSuppressionComment FIXABLE DEPRECATED ━
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ a == b;
i Suggested fix: Use // biome-ignore instead
i Unsafe fix: Use // biome-ignore instead
1 │ - //·rome-ignore·lint(suspicious/noDoubleEquals):·test
2 │ - a·
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ file.js:1:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━
> 1 │ debugger;
│ ^^^^^^^^^
i Suggested fix: Remove debugger statement
i Unsafe fix: Remove debugger statement
1 │ debugger;
│ ---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fix.js:3:11 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━
i Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
i Suggested fix: If this is intentional, prepend FOO with an underscore.
i Unsafe fix: If this is intentional, prepend FOO with an underscore.
1 1 │
2 2 │ function f() {arguments;}
Expand All @@ -106,7 +106,7 @@ fix.js:4:9 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━
i Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
i Suggested fix: If this is intentional, prepend x with an underscore.
i Unsafe fix: If this is intentional, prepend x with an underscore.
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand All @@ -130,7 +130,7 @@ fix.js:4:12 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━
i Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
i Suggested fix: If this is intentional, prepend y with an underscore.
i Unsafe fix: If this is intentional, prepend y with an underscore.
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fix.js:4:5 lint/style/useSingleVarDeclarator FIXABLE ━━━━━━━━
│ ^^^^^^^^^
5 │
i Suggested fix: Break out into multiple declarations
i Unsafe fix: Break out into multiple declarations
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand Down Expand Up @@ -93,7 +93,7 @@ fix.js:4:5 lint/style/noVar FIXABLE ━━━━━━━━━━━━━━
i See MDN web docs for more details.
i Suggested fix: Use 'let' instead.
i Unsafe fix: Use 'let' instead.
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ check.js:1:1 lint/correctness/noNewSymbol FIXABLE ━━━━━━━━━
> 1 │ new Symbol("");
│ ^^^^^^^^^^^^^^
i Suggested fix: Remove new.
i Unsafe fix: Remove new.
1 │ new·Symbol("");
│ ----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ file.js:1:1 suppressions/deprecatedSuppressionComment FIXABLE DEPRECATED ━
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │ a == b;
i Suggested fix: Use // biome-ignore instead
i Unsafe fix: Use // biome-ignore instead
1 │ - //·rome-ignore·lint(suspicious/noDoubleEquals):·test
2 │ - a·
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ file.js:1:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━
> 1 │ debugger;
│ ^^^^^^^^^
i Suggested fix: Remove debugger statement
i Unsafe fix: Remove debugger statement
1 │ debugger;
│ ---------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fix.js:3:11 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━
i Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
i Suggested fix: If this is intentional, prepend FOO with an underscore.
i Unsafe fix: If this is intentional, prepend FOO with an underscore.
1 1 │
2 2 │ function f() {arguments;}
Expand All @@ -95,7 +95,7 @@ fix.js:4:9 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━━
i Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
i Suggested fix: If this is intentional, prepend x with an underscore.
i Unsafe fix: If this is intentional, prepend x with an underscore.
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand All @@ -119,7 +119,7 @@ fix.js:4:12 lint/correctness/noUnusedVariables FIXABLE ━━━━━━━
i Unused variables usually are result of incomplete refactoring, typos and other source of bugs.
i Suggested fix: If this is intentional, prepend y with an underscore.
i Unsafe fix: If this is intentional, prepend y with an underscore.
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fix.js:4:5 lint/style/useSingleVarDeclarator FIXABLE ━━━━━━━━
│ ^^^^^^^^^
5 │
i Suggested fix: Break out into multiple declarations
i Unsafe fix: Break out into multiple declarations
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand Down Expand Up @@ -93,7 +93,7 @@ fix.js:4:5 lint/style/noVar FIXABLE ━━━━━━━━━━━━━━
i See MDN web docs for more details.
i Suggested fix: Use 'let' instead.
i Unsafe fix: Use 'let' instead.
2 2 │ function f() {arguments;}
3 3 │ const FOO = "FOO";
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_diagnostics/src/advice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ where
fn record(&self, visitor: &mut dyn Visit) -> io::Result<()> {
let applicability = match self.applicability {
Applicability::Always => "Safe fix",
Applicability::MaybeIncorrect => "Suggested fix",
Applicability::MaybeIncorrect => "Unsafe fix",
};

visitor.record_log(
Expand Down
3 changes: 2 additions & 1 deletion crates/biome_js_analyze/src/analyzers/a11y/no_access_key.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::JsRuleAction;
use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic,
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand Down Expand Up @@ -40,6 +40,7 @@ declare_rule! {
version: "1.0.0",
name: "noAccessKey",
recommended: false,
fix_kind: FixKind::Unsafe,
}
}

Expand Down
3 changes: 2 additions & 1 deletion crates/biome_js_analyze/src/analyzers/a11y/no_auto_focus.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::JsRuleAction;
use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic,
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand Down Expand Up @@ -60,6 +60,7 @@ declare_rule! {
version: "1.0.0",
name: "noAutofocus",
recommended: true,
fix_kind: FixKind::Unsafe,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::JsRuleAction;
use biome_analyze::context::RuleContext;
use biome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_factory::make::{
Expand Down Expand Up @@ -52,6 +52,7 @@ declare_rule! {
version: "1.0.0",
name: "noBlankTarget",
recommended: true,
fix_kind: FixKind::Safe,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use biome_analyze::context::RuleContext;
use biome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_syntax::jsx_ext::AnyJsxElement;
Expand Down Expand Up @@ -41,6 +41,7 @@ declare_rule! {
version: "1.0.0",
name: "noDistractingElements",
recommended: true,
fix_kind: FixKind::Unsafe,
}
}

Expand Down
5 changes: 3 additions & 2 deletions crates/biome_js_analyze/src/analyzers/a11y/no_header_scope.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use biome_analyze::context::RuleContext;
use biome_analyze::{declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_syntax::jsx_ext::AnyJsxElement;
Expand Down Expand Up @@ -41,6 +41,7 @@ declare_rule! {
version: "1.0.0",
name: "noHeaderScope",
recommended: true,
fix_kind: FixKind::Unsafe,
}
}

Expand Down Expand Up @@ -73,7 +74,7 @@ impl Rule for NoHeaderScope {
markup! {"Avoid using the "<Emphasis>"scope"</Emphasis>" attribute on elements other than "<Emphasis>"th"</Emphasis>" elements."}
.to_owned(),
).note(markup!{
"The "<Emphasis>"scope"</Emphasis>" attribute is used to associate a data cell with its corresponding header cell in a data table,
"The "<Emphasis>"scope"</Emphasis>" attribute is used to associate a data cell with its corresponding header cell in a data table,
so it should be placed on "<Emphasis>"th"</Emphasis>" elements to provide accessibility to screen readers."
}).note(markup!{
"Follow the links for more information,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ use biome_js_syntax::{jsx_ext::AnyJsxElement, JsxElement};
use biome_rowan::AstNode;

declare_rule! {
/// Enforce that heading elements (h1, h2, etc.) have content and that the content is accessible to screen readers.
/// Accessible means that it is not hidden using the aria-hidden prop.
/// Enforce that heading elements (h1, h2, etc.) have content and that the content is accessible to screen readers. Accessible means that it is not hidden using the aria-hidden prop.
///
/// ## Examples
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic,
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand Down Expand Up @@ -60,6 +60,7 @@ declare_rule! {
version: "1.0.0",
name: "noExtraBooleanCast",
recommended: true,
fix_kind: FixKind::Unsafe,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic,
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand Down Expand Up @@ -51,6 +51,7 @@ declare_rule! {
version: "1.0.0",
name: "noMultipleSpacesInRegularExpressionLiterals",
recommended: true,
fix_kind: FixKind::Unsafe,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic,
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand Down Expand Up @@ -81,6 +81,7 @@ declare_rule! {
version: "1.0.0",
name: "noUselessConstructor",
recommended: true,
fix_kind: FixKind::Unsafe,
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, Ast, Rule, RuleDiagnostic,
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand Down Expand Up @@ -47,6 +47,7 @@ declare_rule! {
version: "1.0.0",
name: "noUselessEmptyExport",
recommended: true,
fix_kind: FixKind::Safe,
}
}

Expand Down
Loading

0 comments on commit ae1021c

Please sign in to comment.