Skip to content

Commit

Permalink
refactor(linter): severity and recommendation of lint rules (#5133)
Browse files Browse the repository at this point in the history
Co-authored-by: arendjr <[email protected]>
Co-authored-by: Conaclos <[email protected]>
  • Loading branch information
3 people authored Feb 19, 2025
1 parent c237df0 commit 84e0407
Show file tree
Hide file tree
Showing 589 changed files with 6,115 additions and 6,008 deletions.
33 changes: 33 additions & 0 deletions .changeset/spotty-buckets-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
"@biomejs/biome": major
---

Reworked some recommended rules recommended to be less pedantic and blocking. This is a **breaking change** if your project relied on those rules to block the CI in case of violations; if that's the case, you should raise their severity level to **error**.

Some rules aren't recommended anymore, and some others return a different severity.

The following rules return a **warning** diagnostic:
- `noDelete`
- `noForEach`
- `noSuspiciousSemicolonInJsx`
- `noThisInStatic`
- `noUnusedLabels`

The following rules return an **information** diagnostic:
- `noUselessCatch`
- `noUselessConstructor`
- `noUselessEmptyExport`
- `noUselessFragments`
- `noUselessLabel`
- `noUselessLoneBlockStatements`
- `noUselessSwitchCase`
- `noUselessTernary`
- `noUselessThisAlias`
- `noUselessTypeConstraint`
- `noFlatMapIdentity`

The following rules aren't recommended anymore:
- `noDelete`
- `noForEach`

The rule `noRenderReturnValue` is only recommended when the `react` domain is enabled.
2 changes: 1 addition & 1 deletion crates/biome_analyze/src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ impl RuleSource {

pub fn to_rule_url(&self) -> String {
match self {
Self::Clippy(rule_name) => format!("https://rust-lang.github.io/rust-clippy/master/#/{rule_name}"),
Self::Clippy(rule_name) => format!("https://rust-lang.github.io/rust-clippy/master/#{rule_name}"),
Self::Eslint(rule_name) => format!("https://eslint.org/docs/latest/rules/{rule_name}"),
Self::EslintGraphql(rule_name) => format!("https://the-guild.dev/graphql/eslint/rules/{rule_name}"),
Self::EslintGraphqlSchemaLinter(rule_name) => format!("https://github.com/cjoudrey/graphql-schema-linter?tab=readme-ov-file#{rule_name}"),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
# Input messages

Expand All @@ -21,7 +22,7 @@ delete a.c;
import * as vueUse from "vue-use";
import { Button } from "./components/Button.vue";
a.c = undefined;
delete a.c;
</script>
<template></template>
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
# Input messages
Expand All @@ -20,7 +20,7 @@ var foo: string = "";
```block
<script setup lang="ts">
a === b;
a.c = undefined;
delete a.c;
var foo: string = "";
</script>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `file.vue`
Expand Down Expand Up @@ -55,30 +55,7 @@ file.vue:2:3 lint/suspicious/noDoubleEquals FIXABLE ━━━━━━━━
```

```block
file.vue:3:1 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Avoid the delete operator which can impact performance.
1 │ <script setup lang="js">
2 │ a == b;
> 3 │ delete a.c;
│ ^^^^^^^^^^
4 │
5 │ var foo = "";
i Unsafe fix: Use an undefined assignment instead.
1 1 │ a == b;
2 │ - delete·a.c;
2 │ + a.c·=·undefined;
3 3 │
4 4 │ var foo = "";
```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 2 errors.
Found 1 error.
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `file.vue`
Expand Down Expand Up @@ -55,30 +55,7 @@ file.vue:2:3 lint/suspicious/noDoubleEquals FIXABLE ━━━━━━━━
```

```block
file.vue:3:1 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Avoid the delete operator which can impact performance.
1 │ <script setup lang="ts">
2 │ a == b;
> 3 │ delete a.c;
│ ^^^^^^^^^^
4 │
5 │ var foo: string = "";
i Unsafe fix: Use an undefined assignment instead.
1 1 │ a == b;
2 │ - delete·a.c;
2 │ + a.c·=·undefined;
3 3 │
4 4 │ var foo: string = "";
```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 2 errors.
Found 1 error.
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `check.js`

Expand Down Expand Up @@ -39,7 +40,7 @@ check.js:1:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━
```block
check.js:1:11 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Avoid the delete operator which can impact performance.
! Avoid the delete operator which can impact performance.
> 1 │ debugger; delete obj.prop; a === -0;
│ ^^^^^^^^^^^^^^^
Expand All @@ -54,5 +55,6 @@ check.js:1:11 lint/performance/noDelete FIXABLE ━━━━━━━━━━

```block
Checked 1 file in <TIME>. No fixes applied.
Found 2 errors.
Found 1 error.
Found 1 warning.
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `check.js`

Expand Down Expand Up @@ -39,7 +40,7 @@ check.js:1:1 lint/suspicious/noDebugger FIXABLE ━━━━━━━━━━
```block
check.js:1:11 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Avoid the delete operator which can impact performance.
! Avoid the delete operator which can impact performance.
> 1 │ debugger; delete obj.prop; a === -0;
│ ^^^^^^^^^^^^^^^
Expand All @@ -54,5 +55,6 @@ check.js:1:11 lint/performance/noDelete FIXABLE ━━━━━━━━━━

```block
Checked 1 file in <TIME>. No fixes applied.
Found 2 errors.
Found 1 error.
Found 1 warning.
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `biome.json`

Expand All @@ -20,38 +21,10 @@ expression: content

```js
debugger; delete obj.prop;
```

# Termination Message

```block
lint ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Some errors were emitted while running checks.
```

# Emitted Messages

```block
check.js:1:11 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Avoid the delete operator which can impact performance.
> 1 │ debugger; delete obj.prop;
│ ^^^^^^^^^^^^^^^
i Unsafe fix: Use an undefined assignment instead.
- debugger;·delete·obj.prop;
+ debugger;·obj.prop·=·undefined;
```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 1 error.
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
snapshot_kind: text
---
## `check.js`

Expand All @@ -21,22 +22,6 @@ lint ━━━━━━━━━━━━━━━━━━━━━━━━━

# Emitted Messages

```block
check.js:1:11 lint/performance/noDelete FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
× Avoid the delete operator which can impact performance.
> 1 │ debugger; delete obj.prop; a === -0;
│ ^^^^^^^^^^^^^^^
i Unsafe fix: Use an undefined assignment instead.
- debugger;·delete·obj.prop;·a·===·-0;
+ debugger;·obj.prop·=·undefined;·a·===·-0;
```

```block
check.js:1:28 lint/suspicious/noCompareNegZero FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Expand All @@ -54,5 +39,5 @@ check.js:1:28 lint/suspicious/noCompareNegZero FIXABLE ━━━━━━━

```block
Checked 1 file in <TIME>. No fixes applied.
Found 2 errors.
Found 1 error.
```
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ Linter:
complexity/noBannedTypes
complexity/noEmptyTypeParameters
complexity/noExtraBooleanCast
complexity/noForEach
complexity/noMultipleSpacesInRegularExpressionLiterals
complexity/noStaticOnlyClass
complexity/noThisInStatic
Expand Down
12 changes: 4 additions & 8 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.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
---
source: crates/biome_css_analyze/tests/spec_tests.rs
expression: useLowercaseColors.grit
snapshot_kind: text
---
# Input
```css
Expand All @@ -16,7 +17,7 @@ div {
```
useLowercaseColors.grit:3:12 plugin ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
! Prefer lowercase colors
i Prefer lowercase colors
1 │ div {
2color: red;
Expand Down
4 changes: 1 addition & 3 deletions crates/biome_css_analyze/tests/spec_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use biome_analyze::{
use biome_css_parser::{parse_css, CssParserOptions};
use biome_css_syntax::{CssFileSource, CssLanguage};
use biome_diagnostics::advice::CodeSuggestionAdvice;
use biome_diagnostics::{DiagnosticExt, Severity};
use biome_fs::OsFileSystem;
use biome_plugin_loader::AnalyzerGritPlugin;
use biome_rowan::AstNode;
Expand Down Expand Up @@ -146,8 +145,7 @@ pub(crate) fn analyze_and_snap(
}
}

let error = diag.with_severity(Severity::Warning);
diagnostics.push(diagnostic_to_string(file_name, input_code, error));
diagnostics.push(diagnostic_to_string(file_name, input_code, diag.into()));
return ControlFlow::Continue(());
}

Expand Down
Loading

0 comments on commit 84e0407

Please sign in to comment.