Skip to content

Commit

Permalink
refactor: add source to analyze::correctness rules
Browse files Browse the repository at this point in the history
  • Loading branch information
Conaclos committed Jan 10, 2024
1 parent b20a8f7 commit 21c7273
Show file tree
Hide file tree
Showing 36 changed files with 73 additions and 48 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use biome_analyze::context::RuleContext;
use biome_analyze::RuleSource;
use biome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_js_syntax::{JsConstructorClassMember, JsReturnStatement};
Expand All @@ -14,8 +15,6 @@ declare_rule! {
///
/// Only returning without a value is allowed, as it’s a control flow statement.
///
/// Source: https://eslint.org/docs/latest/rules/no-constructor-return
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -47,6 +46,7 @@ declare_rule! {
pub(crate) NoConstructorReturn {
version: "1.0.0",
name: "noConstructorReturn",
source: RuleSource::Eslint("no-constructor-return"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::ops::Range;

use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::JsRegexLiteralExpression;
use biome_rowan::{TextRange, TextSize};
Expand All @@ -12,8 +12,6 @@ declare_rule! {
/// In contrast, negated empty classes match any character.
/// They are often the result of a typing mistake.
///
/// Source: https://eslint.org/docs/latest/rules/no-empty-character-class/
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -43,6 +41,7 @@ declare_rule! {
pub(crate) NoEmptyCharacterClassInRegex {
version: "1.3.0",
name: "noEmptyCharacterClassInRegex",
source: RuleSource::Eslint("no-empty-character-class"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::{JsArrayBindingPattern, JsObjectBindingPattern};
use biome_rowan::{declare_node_union, AstNode, AstSeparatedList};
Expand Down Expand Up @@ -35,6 +35,7 @@ declare_rule! {
pub(crate) NoEmptyPattern {
version: "1.0.0",
name: "noEmptyPattern",
source: RuleSource::Eslint("no-empty-pattern"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::{AnyJsDeclaration, JsFileSource, JsStatementList, JsSyntaxKind};
use biome_rowan::AstNode;
Expand All @@ -19,8 +19,6 @@ declare_rule! {
/// and therefore they are not affected by this rule.
/// Moreover, `function` declarations in nested blocks are allowed inside _ES modules_.
///
/// Source: https://eslint.org/docs/rules/no-inner-declarations
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -90,6 +88,7 @@ declare_rule! {
pub(crate) NoInnerDeclarations {
version: "1.0.0",
name: "noInnerDeclarations",
source: RuleSource::Eslint("no-inner-declarations"),
recommended: true,
}
}
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, Ast, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::{markup, MarkupBuf};
use biome_js_syntax::{
AnyJsClass, AnyJsExpression, JsAssignmentOperator, JsConstructorClassMember, JsLogicalOperator,
Expand Down Expand Up @@ -48,6 +48,7 @@ declare_rule! {
pub(crate) NoInvalidConstructorSuper {
version: "1.0.0",
name: "noInvalidConstructorSuper",
source: RuleSource::Eslint("constructor-super"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::JsRuleAction;
use biome_analyze::{
context::RuleContext, declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic,
RuleSource,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand All @@ -26,8 +27,6 @@ declare_rule! {
/// However, web browsers are still required to support it, but only in non-strict mode.
/// Regardless of your targeted environment, it is recommended to avoid using these escape sequences in new code.
///
/// Source: https://eslint.org/docs/latest/rules/no-nonoctal-decimal-escape
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -57,6 +56,7 @@ declare_rule! {
pub(crate) NoNonoctalDecimalEscape {
version: "1.0.0",
name: "noNonoctalDecimalEscape",
source: RuleSource::Eslint("no-nonoctal-decimal-escape"),
recommended: true,
fix_kind: FixKind::Unsafe,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::num::IntErrorKind;
use std::ops::RangeInclusive;

use biome_analyze::context::RuleContext;
use biome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;

use biome_js_syntax::numbers::split_into_radix_and_number;
Expand Down Expand Up @@ -56,6 +56,7 @@ declare_rule! {
pub(crate) NoPrecisionLoss {
version: "1.0.0",
name: "noPrecisionLoss",
source: RuleSource::Eslint("no-loss-of-precision"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use biome_analyze::RuleSource;
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
use biome_console::markup;
use biome_js_syntax::{
Expand All @@ -20,8 +21,6 @@ declare_rule! {
///
/// Self assignments have no effect, so probably those are an error due to incomplete refactoring.
///
/// Source: https://eslint.org/docs/latest/rules/no-self-assign
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -67,6 +66,7 @@ declare_rule! {
pub(crate) NoSelfAssign {
version: "1.0.0",
name: "noSelfAssign",
source: RuleSource::Eslint("no-self-assign"),
recommended: true,
}
}
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, Ast, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::{JsReturnStatement, JsSetterClassMember, JsSetterObjectMember};
use biome_rowan::{declare_node_union, AstNode};
Expand Down Expand Up @@ -67,6 +67,7 @@ declare_rule! {
pub(crate) NoSetterReturn {
version: "1.0.0",
name: "noSetterReturn",
source: RuleSource::Eslint("no-setter-return"),
recommended: true,
}
}
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, FixKind, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_factory::make;
Expand Down Expand Up @@ -34,6 +34,7 @@ declare_rule! {
pub(crate) NoStringCaseMismatch {
version: "1.0.0",
name: "noStringCaseMismatch",
source: RuleSource::Clippy("match_str_case_mismatch"),
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;
use biome_analyze::{declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, ActionCategory, Ast, FixKind, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_diagnostics::Applicability;
use biome_js_factory::make;
Expand All @@ -18,8 +18,6 @@ declare_rule! {
///
/// To ensure that the lexical declarations only apply to the current `switch` clause wrap your declarations in a block.
///
/// Source: https://eslint.org/docs/latest/rules/no-case-declarations
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -74,6 +72,7 @@ declare_rule! {
pub(crate) NoSwitchDeclarations {
version: "1.0.0",
name: "noSwitchDeclarations",
source: RuleSource::Eslint("no-case-declarations"),
recommended: true,
fix_kind: FixKind::Unsafe,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{cmp::Ordering, collections::VecDeque, num::NonZeroU32, vec::IntoIter};

use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic};
use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic, RuleSource};
use biome_control_flow::{
builder::{BlockId, ROOT_BLOCK_ID},
ExceptionHandler, ExceptionHandlerKind, Instruction, InstructionKind,
Expand Down Expand Up @@ -50,6 +50,7 @@ declare_rule! {
pub(crate) NoUnreachable {
version: "1.0.0",
name: "noUnreachable",
source: RuleSource::Eslint("no-unreachable"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic};
use biome_analyze::{context::RuleContext, declare_rule, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_control_flow::{
builder::{BlockId, ROOT_BLOCK_ID},
Expand Down Expand Up @@ -64,6 +64,7 @@ declare_rule! {
pub(crate) NoUnreachableSuper {
version: "1.0.0",
name: "noUnreachableSuper",
source: RuleSource::Eslint("no-this-before-super"),
recommended: true,
}
}
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, Ast, Rule, RuleDiagnostic};
use biome_analyze::{declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::*;
use biome_rowan::{declare_node_union, AstNode};
Expand Down Expand Up @@ -127,6 +127,7 @@ declare_rule! {
pub(crate) NoUnsafeFinally {
version: "1.0.0",
name: "noUnsafeFinally",
source: RuleSource::Eslint("no-unsafe-finally"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::{
AnyJsAssignmentPattern, AnyJsBindingPattern, AnyJsOptionalChainExpression,
Expand Down Expand Up @@ -64,6 +64,7 @@ declare_rule! {
pub(crate) NoUnsafeOptionalChaining {
version: "1.0.0",
name: "noUnsafeOptionalChaining",
source: RuleSource::Eslint("no-unsafe-optional-chaining"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use biome_analyze::context::RuleContext;
use biome_analyze::{
declare_rule, ActionCategory, AddVisitor, FixKind, Phases, QueryMatch, Queryable, Rule,
RuleDiagnostic, ServiceBag, Visitor, VisitorContext,
RuleDiagnostic, RuleSource, ServiceBag, Visitor, VisitorContext,
};
use biome_console::markup;
use biome_diagnostics::Applicability;
Expand All @@ -21,8 +21,6 @@ declare_rule! {
///
/// Labels that are declared and never used are most likely an error due to incomplete refactoring.
///
/// Source: https://eslint.org/docs/latest/rules/no-unused-labels
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -56,6 +54,7 @@ declare_rule! {
pub(crate) NoUnusedLabels {
version: "1.0.0",
name: "noUnusedLabels",
source: RuleSource::Eslint("no-unused-labels"),
recommended: true,
fix_kind: FixKind::Unsafe,
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic};
use biome_analyze::{context::RuleContext, declare_rule, Ast, Rule, RuleDiagnostic, RuleSource};
use biome_console::markup;
use biome_js_syntax::{
AnyJsExpression, JsAssignmentOperator, JsBinaryOperator, JsForStatement,
Expand Down Expand Up @@ -41,6 +41,7 @@ declare_rule! {
pub(crate) UseValidForDirection {
version: "1.0.0",
name: "useValidForDirection",
source: RuleSource::Eslint("for-direction"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use biome_analyze::context::RuleContext;
use biome_analyze::{
declare_rule, AddVisitor, Phases, QueryMatch, Queryable, Rule, RuleDiagnostic, ServiceBag,
Visitor, VisitorContext,
declare_rule, AddVisitor, Phases, QueryMatch, Queryable, Rule, RuleDiagnostic, RuleSource,
ServiceBag, Visitor, VisitorContext,
};
use biome_console::markup;
use biome_js_syntax::{AnyFunctionLike, JsLanguage, JsYieldExpression, TextRange, WalkEvent};
Expand All @@ -12,8 +12,6 @@ declare_rule! {
///
/// This rule generates warnings for generator functions that do not have the `yield` keyword.
///
/// Source: [require-yield](https://eslint.org/docs/latest/rules/require-yield).
///
/// ## Examples
///
/// ### Invalid
Expand Down Expand Up @@ -41,6 +39,7 @@ declare_rule! {
pub(crate) UseYield {
version: "1.0.0",
name: "useYield",
source: RuleSource::Eslint("require-yield"),
recommended: true,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ title: noConstructorReturn (since v1.0.0)
This rule is recommended by Biome. A diagnostic error will appear when linting your code.
:::

Source: <a href="https://eslint.org/docs/latest/rules/no-constructor-return" target="_blank"><code>no-constructor-return</code></a>

Disallow returning a value from a `constructor`.

Returning a value from a `constructor` of a class is a possible error.
Forbidding this pattern prevents errors resulting from unfamiliarity with JavaScript or a copy-paste error.

Only returning without a value is allowed, as it’s a control flow statement.

Source: https://eslint.org/docs/latest/rules/no-constructor-return

## Examples

### Invalid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ title: noEmptyCharacterClassInRegex (since v1.3.0)
This rule is recommended by Biome. A diagnostic error will appear when linting your code.
:::

Source: <a href="https://eslint.org/docs/latest/rules/no-empty-character-class" target="_blank"><code>no-empty-character-class</code></a>

Disallow empty character classes in regular expression literals.

Empty character classes don't match anything.
In contrast, negated empty classes match any character.
They are often the result of a typing mistake.

Source: https://eslint.org/docs/latest/rules/no-empty-character-class/

## Examples

### Invalid
Expand Down
2 changes: 2 additions & 0 deletions website/src/content/docs/linter/rules/no-empty-pattern.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ title: noEmptyPattern (since v1.0.0)
This rule is recommended by Biome. A diagnostic error will appear when linting your code.
:::

Source: <a href="https://eslint.org/docs/latest/rules/no-empty-pattern" target="_blank"><code>no-empty-pattern</code></a>

Disallows empty destructuring patterns.

## Examples
Expand Down
Loading

0 comments on commit 21c7273

Please sign in to comment.