Skip to content

Commit

Permalink
feat: move useWhile to complexity
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed Dec 22, 2024
1 parent 1907096 commit dff56ee
Show file tree
Hide file tree
Showing 27 changed files with 213 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .changeset/remove_support_for_legacy_suppressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ cli: major
Biome used to support "legacy suppressions" that looked like this:

```js
// biome-ignore lint(style/useWhile): reason
// biome-ignore lint(complexity/useWhile): reason
```

This format is no longer supported.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
cli: major
---

# The rule `useWhile` now belongs to the `complexity` group
10 changes: 5 additions & 5 deletions crates/biome_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -590,10 +590,10 @@ fn range_match(filter: Option<TextRange>, range: TextRange) -> bool {
///
/// - `// biome-ignore format` -> `vec![]`
/// - `// biome-ignore lint` -> `vec![Everything]`
/// - `// biome-ignore lint/style/useWhile` -> `vec![Rule("style/useWhile")]`
/// - `// biome-ignore lint/style/useWhile(foo)` -> `vec![RuleWithValue("style/useWhile", "foo")]`
/// - `// biome-ignore lint/style/useWhile lint/nursery/noUnreachable` -> `vec![Rule("style/useWhile"), Rule("nursery/noUnreachable")]`
/// - `/** biome-ignore lint/style/useWhile */` if the comment is top-level -> `vec![TopLevel("style/useWhile")]`
/// - `// biome-ignore lint/complexity/useWhile` -> `vec![Rule("complexity/useWhile")]`
/// - `// biome-ignore lint/complexity/useWhile(foo)` -> `vec![RuleWithValue("complexity/useWhile", "foo")]`
/// - `// biome-ignore lint/complexity/useWhile lint/nursery/noUnreachable` -> `vec![Rule("complexity/useWhile"), Rule("nursery/noUnreachable")]`
/// - `/** biome-ignore lint/complexity/useWhile */` if the comment is top-level -> `vec![TopLevel("complexity/useWhile")]`
type SuppressionParser<D> =
for<'a> fn(&'a str, TextRange) -> Vec<Result<AnalyzerSuppression<'a>, D>>;

Expand Down Expand Up @@ -673,7 +673,7 @@ impl<'a> AnalyzerSuppression<'a> {
pub enum AnalyzerSuppressionKind<'a> {
/// A suppression disabling all lints eg. `// biome-ignore lint`
Everything,
/// A suppression disabling a specific rule eg. `// biome-ignore lint/style/useWhile`
/// A suppression disabling a specific rule eg. `// biome-ignore lint/complexity/useWhile`
Rule(&'a str),
/// A suppression to be evaluated by a specific rule eg. `// biome-ignore lint/correctness/useExhaustiveDependencies(foo)`
RuleInstance(&'a str, &'a str),
Expand Down

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

Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ biome.json:5:17 deserialize ━━━━━━━━━━━━━━━━━
- useTemplate
- useThrowNewError
- useThrowOnlyError
- useWhile
```
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ biome.json:9:13 deserialize ━━━━━━━━━━━━━━━━━
- useTemplate
- useThrowNewError
- useThrowOnlyError
- useWhile
```
36 changes: 18 additions & 18 deletions crates/biome_configuration/src/analyzer/linter/rules.rs

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

2 changes: 1 addition & 1 deletion crates/biome_diagnostics_categories/src/categories.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ define_categories! {
"lint/complexity/useRegexLiterals": "https://biomejs.dev/linter/rules/use-regex-literals",
"lint/complexity/useSimpleNumberKeys": "https://biomejs.dev/linter/rules/use-simple-number-keys",
"lint/complexity/useSimplifiedLogicExpression": "https://biomejs.dev/linter/rules/use-simplified-logic-expression",
"lint/complexity/useWhile": "https://biomejs.dev/linter/rules/use-while",
"lint/correctness/noChildrenProp": "https://biomejs.dev/linter/rules/no-children-prop",
"lint/correctness/noConstAssign": "https://biomejs.dev/linter/rules/no-const-assign",
"lint/correctness/noConstantCondition": "https://biomejs.dev/linter/rules/no-constant-condition",
Expand Down Expand Up @@ -271,7 +272,6 @@ define_categories! {
"lint/style/useTemplate": "https://biomejs.dev/linter/rules/use-template",
"lint/style/useThrowNewError": "https://biomejs.dev/linter/rules/use-throw-new-error",
"lint/style/useThrowOnlyError": "https://biomejs.dev/linter/rules/use-throw-only-error",
"lint/style/useWhile": "https://biomejs.dev/linter/rules/use-while",
"lint/suspicious/noApproximativeNumericConstant": "https://biomejs.dev/linter/rules/no-approximative-numeric-constant",
"lint/suspicious/noArrayIndexKey": "https://biomejs.dev/linter/rules/no-array-index-key",
"lint/suspicious/noAssignInExpressions": "https://biomejs.dev/linter/rules/no-assign-in-expressions",
Expand Down
26 changes: 13 additions & 13 deletions crates/biome_js_analyze/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,9 @@ let bar = 33;
p == f;
// biome-ignore lint/suspicious/noDoubleEquals: single rule
j == k;
/* biome-ignore lint/style/useWhile: multiple block comments */ /* biome-ignore lint/suspicious/noDoubleEquals: multiple block comments */
/* biome-ignore lint/complexity/useWhile: multiple block comments */ /* biome-ignore lint/suspicious/noDoubleEquals: multiple block comments */
o == m;
// biome-ignore lint/style/useWhile: multiple line comments
// biome-ignore lint/complexity/useWhile: multiple line comments
// biome-ignore lint/suspicious/noDoubleEquals: multiple line comments
d == x;
z == v;
Expand All @@ -301,9 +301,9 @@ let bar = 33;
a == b;
// biome-ignore lint/suspicious/noDoubleEquals: single rule
a == b;
/* biome-ignore lint/style/useWhile: multiple block comments */ /* biome-ignore lint(suspicious/noDoubleEquals): multiple block comments */
/* biome-ignore lint/complexity/useWhile: multiple block comments */ /* biome-ignore lint(suspicious/noDoubleEquals): multiple block comments */
a == b;
// biome-ignore lint/style/useWhile: multiple line comments
// biome-ignore lint/complexity/useWhile: multiple line comments
// biome-ignore lint/suspicious/noDoubleEquals: multiple line comments
a == b;
a == b;
Expand Down Expand Up @@ -366,21 +366,21 @@ let bar = 33;
lint_ranges.as_slice(),
&[
TextRange::new(TextSize::from(67), TextSize::from(69)),
TextRange::new(TextSize::from(641), TextSize::from(643)),
TextRange::new(TextSize::from(835), TextSize::from(837)),
TextRange::new(TextSize::from(922), TextSize::from(924)),
TextRange::new(TextSize::from(1498), TextSize::from(1500)),
TextRange::new(TextSize::from(1693), TextSize::from(1695)),
TextRange::new(TextSize::from(651), TextSize::from(653)),
TextRange::new(TextSize::from(845), TextSize::from(847)),
TextRange::new(TextSize::from(932), TextSize::from(934)),
TextRange::new(TextSize::from(1518), TextSize::from(1520)),
TextRange::new(TextSize::from(1713), TextSize::from(1715)),
]
);

assert_eq!(
parse_ranges.as_slice(),
&[
TextRange::new(TextSize::from(1797), TextSize::from(1808)),
TextRange::new(TextSize::from(1848), TextSize::from(1849)),
TextRange::new(TextSize::from(1882), TextSize::from(1883)),
TextRange::new(TextSize::from(1935), TextSize::from(1942)),
TextRange::new(TextSize::from(1817), TextSize::from(1828)),
TextRange::new(TextSize::from(1868), TextSize::from(1869)),
TextRange::new(TextSize::from(1902), TextSize::from(1903)),
TextRange::new(TextSize::from(1955), TextSize::from(1962)),
]
);
}
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_js_analyze/src/lint/complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub mod use_optional_chain;
pub mod use_regex_literals;
pub mod use_simple_number_keys;
pub mod use_simplified_logic_expression;
pub mod use_while;

declare_lint_group! {
pub Complexity {
Expand Down Expand Up @@ -71,6 +72,7 @@ declare_lint_group! {
self :: use_regex_literals :: UseRegexLiterals ,
self :: use_simple_number_keys :: UseSimpleNumberKeys ,
self :: use_simplified_logic_expression :: UseSimplifiedLogicExpression ,
self :: use_while :: UseWhile ,
]
}
}
2 changes: 0 additions & 2 deletions crates/biome_js_analyze/src/lint/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ pub mod use_single_var_declarator;
pub mod use_template;
pub mod use_throw_new_error;
pub mod use_throw_only_error;
pub mod use_while;

declare_lint_group! {
pub Style {
Expand Down Expand Up @@ -104,7 +103,6 @@ declare_lint_group! {
self :: use_template :: UseTemplate ,
self :: use_throw_new_error :: UseThrowNewError ,
self :: use_throw_only_error :: UseThrowOnlyError ,
self :: use_while :: UseWhile ,
]
}
}
2 changes: 1 addition & 1 deletion crates/biome_js_analyze/src/options.rs

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

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ for /*a*/ ( /*init*/; /*test before*/ true /*test after*/; /*update*/ ) /*b*/ {

# Diagnostics
```
invalid.js:1:1 lint/style/useWhile FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.js:1:1 lint/complexity/useWhile FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Use a while loop instead of a for loop.
Expand All @@ -43,7 +43,7 @@ invalid.js:1:1 lint/style/useWhile FIXABLE ━━━━━━━━━━━
```

```
invalid.js:4:1 lint/style/useWhile FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.js:4:1 lint/complexity/useWhile FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Use a while loop instead of a for loop.
Expand All @@ -68,7 +68,7 @@ invalid.js:4:1 lint/style/useWhile FIXABLE ━━━━━━━━━━━
```

```
invalid.js:9:1 lint/style/useWhile FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
invalid.js:9:1 lint/complexity/useWhile FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Use a while loop instead of a for loop.
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_migrate/src/analyzers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::analyzers::no_var::NoVar;
use crate::analyzers::nursery_rules::NurseryRules;
use crate::analyzers::schema::Schema;
use crate::analyzers::style_rules::StyleRules;
use crate::analyzers::use_while::UseWhile;
use biome_analyze::{GroupCategory, RegistryVisitor, RuleCategory, RuleGroup};
use biome_json_syntax::JsonLanguage;

Expand All @@ -13,6 +14,7 @@ mod no_var;
mod nursery_rules;
mod schema;
mod style_rules;
mod use_while;

pub(crate) struct MigrationGroup;
pub(crate) struct MigrationCategory;
Expand All @@ -33,6 +35,7 @@ impl RuleGroup for MigrationGroup {
registry.record_rule::<StyleRules>();
registry.record_rule::<NoVar>();
registry.record_rule::<DeletedRules>();
registry.record_rule::<UseWhile>();
}
}

Expand Down
20 changes: 14 additions & 6 deletions crates/biome_migrate/src/analyzers/no_var.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use biome_analyze::{Rule, RuleAction, RuleDiagnostic};
use biome_console::markup;
use biome_diagnostics::{category, Applicability};
use biome_json_syntax::JsonMember;
use biome_rowan::AstNode;
use biome_rowan::{AstNode, TextRange};

declare_migration! {
pub(crate) NoVar {
Expand All @@ -17,7 +17,7 @@ declare_migration! {

impl Rule for NoVar {
type Query = Version<JsonMember>;
type State = ();
type State = TextRange;
type Signals = Option<Self::State>;
type Options = ();

Expand All @@ -32,17 +32,25 @@ impl Rule for NoVar {
let name = node.name().ok()?;
let text = name.inner_string_text().ok()?;

if text.text() == "noVar" {
return Some(());
if text.text() == "style" {
if let Some(object) = node.value().ok()?.as_json_object_value() {
for item in object.json_member_list().into_iter().flatten() {
let name = item.name().ok()?;
let text = name.inner_string_text().ok()?;
if text.text() == "noVar" {
return Some(name.range());
}
}
}
}

None
}

fn diagnostic(ctx: &RuleContext<Self>, _state: &Self::State) -> Option<RuleDiagnostic> {
fn diagnostic(_ctx: &RuleContext<Self>, state: &Self::State) -> Option<RuleDiagnostic> {
Some(RuleDiagnostic::new(
category!("migrate"),
ctx.query().range(),
state,
markup! {
"The rule "<Emphasis>"style/noVar"</Emphasis>" has ben moved to the "<Emphasis>"suspicious"</Emphasis>" group."
}
Expand Down
Loading

0 comments on commit dff56ee

Please sign in to comment.