Skip to content

Commit 7ae83f2

Browse files
authored
fix(lint/js): improve diagnostics for noConstantCondition, useForOf, noRedeclare (#9889)
1 parent 5b05c9f commit 7ae83f2

File tree

52 files changed

+1458
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1458
-421
lines changed

.changeset/clear-bananas-lie.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Improved the diagnostics for [`useForOf`](https://biomejs.dev/linter/rules/use-for-of/) to better explain the problem, why it matters, and how to fix it.

.changeset/plain-keys-arrive.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Improved the diagnostics for [`noConstantCondition`](https://biomejs.dev/linter/rules/no-constant-condition/) to better explain the problem, why it matters, and how to fix it.

.changeset/yellow-fans-glow.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@biomejs/biome": patch
3+
---
4+
5+
Improved the diagnostics for [`noRedeclare`](https://biomejs.dev/linter/rules/no-redeclare/) to better explain the problem, why it matters, and how to fix it.

crates/biome_cli/tests/snapshots/main_cases_handle_astro_files/full_support.snap

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ file.astro:41:1 lint/a11y/useHtmlLang ━━━━━━━━━━━━━━
184184
```block
185185
file.astro:11:6 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
186186
187-
× Shouldn't redeclare 'Props'. Consider to delete it or rename it.
187+
× 'Props' is redeclared in the same scope.
188188
189189
9 │ }
190190
10 │
@@ -201,13 +201,17 @@ file.astro:11:6 lint/suspicious/noRedeclare ━━━━━━━━━━━━
201201
8name: string;
202202
9}
203203
204+
i Redeclarations make it unclear which variable a reference points to and can hide earlier declarations.
205+
206+
i Remove the duplicate declaration or rename one of the variables.
207+
204208
205209
```
206210
207211
```block
208212
file.astro:30:7 lint/suspicious/noRedeclare ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
209213
210-
× Shouldn't redeclare 'Props'. Consider to delete it or rename it.
214+
× 'Props' is redeclared in the same scope.
211215
212216
28 │ }
213217
29 │
@@ -225,6 +229,10 @@ file.astro:30:7 lint/suspicious/noRedeclare ━━━━━━━━━━━━
225229
27 │ name: string;
226230
28 │ }
227231
232+
i Redeclarations make it unclear which variable a reference points to and can hide earlier declarations.
233+
234+
i Remove the duplicate declaration or rename one of the variables.
235+
228236
229237
```
230238

crates/biome_cli/tests/snapshots/main_cases_reporter_checkstyle/reports_diagnostics_checkstyle_check_command.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
5656
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
5757
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
5858
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
59-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
60-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
59+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
60+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
6161
<error line="0" column="0" severity="error" message="Formatter would have printed the following content:" source="format" />
6262
</file>
6363
<file name="main.ts">
@@ -70,8 +70,8 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
7070
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
7171
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
7272
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
73-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
74-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
73+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
74+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
7575
<error line="0" column="0" severity="error" message="Formatter would have printed the following content:" source="format" />
7676
</file>
7777
</checkstyle>

crates/biome_cli/tests/snapshots/main_cases_reporter_checkstyle/reports_diagnostics_checkstyle_check_command_file.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ expression: redactor(content)
1717
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
1818
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
1919
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
20-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
21-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
20+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
21+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
2222
<error line="0" column="0" severity="error" message="Formatter would have printed the following content:" source="format" />
2323
</file>
2424
<file name="main.ts">
@@ -31,8 +31,8 @@ expression: redactor(content)
3131
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
3232
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
3333
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
34-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
35-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
34+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
35+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
3636
<error line="0" column="0" severity="error" message="Formatter would have printed the following content:" source="format" />
3737
</file>
3838
</checkstyle>

crates/biome_cli/tests/snapshots/main_cases_reporter_checkstyle/reports_diagnostics_checkstyle_ci_command.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ ci ━━━━━━━━━━━━━━━━━━━━━━━━━
5656
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
5757
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
5858
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
59-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
60-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
59+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
60+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
6161
<error line="0" column="0" severity="error" message="File content differs from formatting output" source="format" />
6262
</file>
6363
<file name="main.ts">
@@ -70,8 +70,8 @@ ci ━━━━━━━━━━━━━━━━━━━━━━━━━
7070
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
7171
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
7272
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
73-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
74-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
73+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
74+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
7575
<error line="0" column="0" severity="error" message="File content differs from formatting output" source="format" />
7676
</file>
7777
</checkstyle>

crates/biome_cli/tests/snapshots/main_cases_reporter_checkstyle/reports_diagnostics_checkstyle_lint_command.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ lint ━━━━━━━━━━━━━━━━━━━━━━━━━
5555
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
5656
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
5757
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
58-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
59-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
58+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
59+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
6060
</file>
6161
<file name="main.ts">
6262
<error line="1" column="8" severity="warning" message="This import is unused." source="lint/correctness/noUnusedImports" />
@@ -67,8 +67,8 @@ lint ━━━━━━━━━━━━━━━━━━━━━━━━━
6767
<error line="6" column="1" severity="error" message="This is an unexpected use of the debugger statement." source="lint/suspicious/noDebugger" />
6868
<error line="8" column="5" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
6969
<error line="9" column="7" severity="error" message="This variable implicitly has the any type." source="lint/suspicious/noImplicitAnyLet" />
70-
<error line="2" column="10" severity="error" message="Shouldn&apos;t redeclare &apos;z&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
71-
<error line="9" column="7" severity="error" message="Shouldn&apos;t redeclare &apos;f&apos;. Consider to delete it or rename it." source="lint/suspicious/noRedeclare" />
70+
<error line="2" column="10" severity="error" message="&apos;z&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
71+
<error line="9" column="7" severity="error" message="&apos;f&apos; is redeclared in the same scope." source="lint/suspicious/noRedeclare" />
7272
</file>
7373
</checkstyle>
7474

crates/biome_cli/tests/snapshots/main_cases_reporter_github/reports_diagnostics_github_check_command.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
9696
```
9797

9898
```block
99-
::error title=lint/suspicious/noRedeclare,file=index.ts,line=2,endLine=2,col=10,endColumn=11::Shouldn't redeclare 'z'. Consider to delete it or rename it.
99+
::error title=lint/suspicious/noRedeclare,file=index.ts,line=2,endLine=2,col=10,endColumn=11::'z' is redeclared in the same scope.
100100
```
101101

102102
```block
103-
::error title=lint/suspicious/noRedeclare,file=index.ts,line=9,endLine=9,col=7,endColumn=8::Shouldn't redeclare 'f'. Consider to delete it or rename it.
103+
::error title=lint/suspicious/noRedeclare,file=index.ts,line=9,endLine=9,col=7,endColumn=8::'f' is redeclared in the same scope.
104104
```
105105

106106
```block
@@ -128,11 +128,11 @@ check ━━━━━━━━━━━━━━━━━━━━━━━━
128128
```
129129

130130
```block
131-
::error title=lint/suspicious/noRedeclare,file=main.ts,line=2,endLine=2,col=10,endColumn=11::Shouldn't redeclare 'z'. Consider to delete it or rename it.
131+
::error title=lint/suspicious/noRedeclare,file=main.ts,line=2,endLine=2,col=10,endColumn=11::'z' is redeclared in the same scope.
132132
```
133133

134134
```block
135-
::error title=lint/suspicious/noRedeclare,file=main.ts,line=9,endLine=9,col=7,endColumn=8::Shouldn't redeclare 'f'. Consider to delete it or rename it.
135+
::error title=lint/suspicious/noRedeclare,file=main.ts,line=9,endLine=9,col=7,endColumn=8::'f' is redeclared in the same scope.
136136
```
137137

138138
```block

crates/biome_cli/tests/snapshots/main_cases_reporter_github/reports_diagnostics_github_ci_command.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ ci ━━━━━━━━━━━━━━━━━━━━━━━━━
9696
```
9797

9898
```block
99-
::error title=lint/suspicious/noRedeclare,file=index.ts,line=2,endLine=2,col=10,endColumn=11::Shouldn't redeclare 'z'. Consider to delete it or rename it.
99+
::error title=lint/suspicious/noRedeclare,file=index.ts,line=2,endLine=2,col=10,endColumn=11::'z' is redeclared in the same scope.
100100
```
101101

102102
```block
103-
::error title=lint/suspicious/noRedeclare,file=index.ts,line=9,endLine=9,col=7,endColumn=8::Shouldn't redeclare 'f'. Consider to delete it or rename it.
103+
::error title=lint/suspicious/noRedeclare,file=index.ts,line=9,endLine=9,col=7,endColumn=8::'f' is redeclared in the same scope.
104104
```
105105

106106
```block
@@ -128,11 +128,11 @@ ci ━━━━━━━━━━━━━━━━━━━━━━━━━
128128
```
129129

130130
```block
131-
::error title=lint/suspicious/noRedeclare,file=main.ts,line=2,endLine=2,col=10,endColumn=11::Shouldn't redeclare 'z'. Consider to delete it or rename it.
131+
::error title=lint/suspicious/noRedeclare,file=main.ts,line=2,endLine=2,col=10,endColumn=11::'z' is redeclared in the same scope.
132132
```
133133

134134
```block
135-
::error title=lint/suspicious/noRedeclare,file=main.ts,line=9,endLine=9,col=7,endColumn=8::Shouldn't redeclare 'f'. Consider to delete it or rename it.
135+
::error title=lint/suspicious/noRedeclare,file=main.ts,line=9,endLine=9,col=7,endColumn=8::'f' is redeclared in the same scope.
136136
```
137137

138138
```block

0 commit comments

Comments
 (0)