Skip to content

Commit 06f1717

Browse files
committed
fix(linter): false positive in no unused vars when importing value used as type (#10690)
I accidently copied a pass test case to the fail array. ``` import { foo } from ''; export type Foo = typeof foo; ``` is allowed
1 parent d882eaa commit 06f1717

File tree

4 files changed

+9
-18
lines changed

4 files changed

+9
-18
lines changed

crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/oxc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,7 @@ fn test_type_references() {
11481148
accessor y!: Foo
11491149
}
11501150
",
1151+
"import { foo } from 'bar'; export type K = typeof foo",
11511152
];
11521153

11531154
let fail = vec![

crates/oxc_linter/src/rules/eslint/no_unused_vars/tests/typescript_eslint.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,6 +1402,13 @@ fn test() {
14021402
",
14031403
None,
14041404
),
1405+
(
1406+
"
1407+
import { foo } from 'foo';
1408+
export type Bar = typeof foo;
1409+
",
1410+
None,
1411+
),
14051412
];
14061413

14071414
let fail = vec![
@@ -1769,13 +1776,6 @@ fn test() {
17691776
",
17701777
None,
17711778
),
1772-
(
1773-
"
1774-
import { foo } from 'foo';
1775-
export type Bar = typeof foo;
1776-
",
1777-
None,
1778-
),
17791779
];
17801780

17811781
Tester::new(NoUnusedVars::NAME, NoUnusedVars::PLUGIN, pass, fail)

crates/oxc_linter/src/rules/eslint/no_unused_vars/usage.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a> Symbol<'_, 'a> {
137137
continue;
138138
}
139139

140-
if !self.flags().intersects(SymbolFlags::TypeImport)
140+
if !self.flags().intersects(SymbolFlags::TypeImport.union(SymbolFlags::Import))
141141
&& self.reference_contains_type_query(reference)
142142
{
143143
continue;

crates/oxc_linter/src/snapshots/[email protected]

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -400,13 +400,3 @@ source: crates/oxc_linter/src/tester.rs
400400
3 │ bar: {
401401
╰────
402402
help: Consider removing this declaration.
403-
404-
eslint(no-unused-vars): Identifier 'foo' is imported but never used.
405-
╭─[no_unused_vars.ts:2:18]
406-
1
407-
2import { foo } from 'foo';
408-
· ─┬─
409-
· ╰── 'foo' is imported here
410-
3export type Bar = typeof foo;
411-
╰────
412-
help: Consider removing this import.

0 commit comments

Comments
 (0)