-
-
Notifications
You must be signed in to change notification settings - Fork 477
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(linter/no-unused-vars): report own type references within class,…
… interface, and type alias declarations (#6557) ## What This PR Does **Tl;Dr**: Using a class/interface/type alias as a type within its own declaration is no longer considered a usage. ### Example ```ts // LinkedList is only ever referenced within its own definition. // It could be safely deleted and not affect other code. class LinkedList<T> { #value: T; #next: LinkedList<T> | null = null; constructor(value: T) { this.#value = value; } [Symbol.iterator]*() { let current: LinkedList<T> | null = this; while (current !== null) { yield current.#value; current = current.#next; } } } ```
- Loading branch information
Showing
5 changed files
with
257 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
37 changes: 37 additions & 0 deletions
37
crates/oxc_linter/src/snapshots/no_unused_vars@oxc-self-call.snap
This file contains 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,37 @@ | ||
--- | ||
source: crates/oxc_linter/src/tester.rs | ||
--- | ||
⚠ eslint(no-unused-vars): Function 'foo' is declared but never used. | ||
╭─[no_unused_vars.tsx:1:10] | ||
1 │ function foo() { return function bar() { return foo() } } | ||
· ─┬─ | ||
· ╰── 'foo' is declared here | ||
╰──── | ||
help: Consider removing this declaration. | ||
|
||
⚠ eslint(no-unused-vars): Class 'Foo' is declared but never used. | ||
╭─[no_unused_vars.tsx:1:7] | ||
1 │ class Foo { | ||
· ─┬─ | ||
· ╰── 'Foo' is declared here | ||
2 │ static createFoo() { | ||
╰──── | ||
help: Consider removing this declaration. | ||
|
||
⚠ eslint(no-unused-vars): Class 'Foo' is declared but never used. | ||
╭─[no_unused_vars.tsx:1:7] | ||
1 │ class Foo { | ||
· ─┬─ | ||
· ╰── 'Foo' is declared here | ||
2 │ static createFoo(): Foo { | ||
╰──── | ||
help: Consider removing this declaration. | ||
|
||
⚠ eslint(no-unused-vars): Class 'Point' is declared but never used. | ||
╭─[no_unused_vars.tsx:1:7] | ||
1 │ class Point { | ||
· ──┬── | ||
· ╰── 'Point' is declared here | ||
2 │ public x: number; | ||
╰──── | ||
help: Consider removing this declaration. |
This file contains 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
This file contains 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