-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix(noUnusedVariables): recognize merged interfaces #11600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| --- | ||
| "@biomejs/biome": patch | ||
| --- | ||
|
|
||
| Fixed [#6644](https://github.com/biomejs/biome/issues/6644): [`noUnusedVariables`](https://biomejs.dev/linter/rules/no-unused-variables/) now recognizes all interface declarations in a TypeScript declaration-merging group when the interface is referenced. | ||
|
|
||
| The following snippet no longer triggers the rule. | ||
|
|
||
| ```ts | ||
| interface Things { | ||
| foo: string; | ||
| } | ||
|
|
||
| interface Things { | ||
| bar: string; | ||
| } | ||
|
|
||
| export type Key = keyof Things; | ||
|
|
||
| interface Things { | ||
| baz: string; | ||
| } | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
...s_analyze/tests/specs/correctness/noUnusedVariables/invalidInterfaceDeclarationMerging.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| /* should generate diagnostics */ | ||
|
|
||
| interface Unused { | ||
| first: string; | ||
| } | ||
|
|
||
| interface Unused { | ||
| second: string; | ||
| } | ||
|
|
||
| const ValueOnly = 0; | ||
| interface ValueOnly { | ||
| prop: string; | ||
| } | ||
| console.log(ValueOnly); | ||
|
|
||
| interface Shadowed { | ||
| outer: string; | ||
| } | ||
| export function useShadowed() { | ||
| interface Shadowed { | ||
| inner: string; | ||
| } | ||
| type Key = keyof Shadowed; | ||
| return null as Key; | ||
| } |
102 changes: 102 additions & 0 deletions
102
...lyze/tests/specs/correctness/noUnusedVariables/invalidInterfaceDeclarationMerging.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| --- | ||
| source: crates/biome_js_analyze/tests/spec_tests.rs | ||
| expression: invalidInterfaceDeclarationMerging.ts | ||
| --- | ||
| # Input | ||
| ```ts | ||
| /* should generate diagnostics */ | ||
|
|
||
| interface Unused { | ||
| first: string; | ||
| } | ||
|
|
||
| interface Unused { | ||
| second: string; | ||
| } | ||
|
|
||
| const ValueOnly = 0; | ||
| interface ValueOnly { | ||
| prop: string; | ||
| } | ||
| console.log(ValueOnly); | ||
|
|
||
| interface Shadowed { | ||
| outer: string; | ||
| } | ||
| export function useShadowed() { | ||
| interface Shadowed { | ||
| inner: string; | ||
| } | ||
| type Key = keyof Shadowed; | ||
| return null as Key; | ||
| } | ||
|
|
||
| ``` | ||
|
|
||
| # Diagnostics | ||
| ``` | ||
| invalidInterfaceDeclarationMerging.ts:3:11 lint/correctness/noUnusedVariables ━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| ! This interface Unused is unused. | ||
|
|
||
| 1 │ /* should generate diagnostics */ | ||
| 2 │ | ||
| > 3 │ interface Unused { | ||
| │ ^^^^^^ | ||
| 4 │ first: string; | ||
| 5 │ } | ||
|
|
||
| i Unused variables are often the result of typos, incomplete refactors, or other sources of bugs. | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| ``` | ||
| invalidInterfaceDeclarationMerging.ts:7:11 lint/correctness/noUnusedVariables ━━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| ! This interface Unused is unused. | ||
|
|
||
| 5 │ } | ||
| 6 │ | ||
| > 7 │ interface Unused { | ||
| │ ^^^^^^ | ||
| 8 │ second: string; | ||
| 9 │ } | ||
|
|
||
| i Unused variables are often the result of typos, incomplete refactors, or other sources of bugs. | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| ``` | ||
| invalidInterfaceDeclarationMerging.ts:12:11 lint/correctness/noUnusedVariables ━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| ! This interface ValueOnly is unused. | ||
|
|
||
| 11 │ const ValueOnly = 0; | ||
| > 12 │ interface ValueOnly { | ||
| │ ^^^^^^^^^ | ||
| 13 │ prop: string; | ||
| 14 │ } | ||
|
|
||
| i Unused variables are often the result of typos, incomplete refactors, or other sources of bugs. | ||
|
|
||
|
|
||
| ``` | ||
|
|
||
| ``` | ||
| invalidInterfaceDeclarationMerging.ts:17:11 lint/correctness/noUnusedVariables ━━━━━━━━━━━━━━━━━━━━━ | ||
|
|
||
| ! This interface Shadowed is unused. | ||
|
|
||
| 15 │ console.log(ValueOnly); | ||
| 16 │ | ||
| > 17 │ interface Shadowed { | ||
| │ ^^^^^^^^ | ||
| 18 │ outer: string; | ||
| 19 │ } | ||
|
|
||
| i Unused variables are often the result of typos, incomplete refactors, or other sources of bugs. | ||
|
|
||
|
|
||
| ``` |
19 changes: 19 additions & 0 deletions
19
..._js_analyze/tests/specs/correctness/noUnusedVariables/validInterfaceDeclarationMerging.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* should not generate diagnostics */ | ||
|
|
||
| interface Things { | ||
| foo: string; | ||
| } | ||
|
|
||
| interface Things { | ||
| bar: string; | ||
| } | ||
|
|
||
| type Key = keyof Things; | ||
|
|
||
| interface Things { | ||
| baz: string; | ||
| } | ||
|
|
||
| export function doStuff(key: Key) { | ||
| return key; | ||
| } |
27 changes: 27 additions & 0 deletions
27
...nalyze/tests/specs/correctness/noUnusedVariables/validInterfaceDeclarationMerging.ts.snap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| --- | ||
| source: crates/biome_js_analyze/tests/spec_tests.rs | ||
| expression: validInterfaceDeclarationMerging.ts | ||
| --- | ||
| # Input | ||
| ```ts | ||
| /* should not generate diagnostics */ | ||
|
|
||
| interface Things { | ||
| foo: string; | ||
| } | ||
|
|
||
| interface Things { | ||
| bar: string; | ||
| } | ||
|
|
||
| type Key = keyof Things; | ||
|
|
||
| interface Things { | ||
| baz: string; | ||
| } | ||
|
|
||
| export function doStuff(key: Key) { | ||
| return key; | ||
| } | ||
|
|
||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Document merged-interface behaviour in rustdoc.
This match arm adds user-visible rule behaviour. Update the
NoUnusedVariablesrustdoc block to state that same-name TypeScript interfaces are treated as one merged group when any declaration is referenced or exported. The changeset does not replace the Rust documentation required by this repository.Suggested rustdoc addition
🤖 Prompt for AI Agents
Source: Coding guidelines