biome
biome copied to clipboard
📎 noUnusedImports should remove empty imports
Rule name
noUnusedImports
Playground link
https://codesandbox.io/p/devbox/biome-starter-cbs-rky6zq
Expected result
The fix for noUnusedImports
should remove imports like:
import {} from 'module';
Context
A while ago, I noticed empty imports like above in in our codebase. I would expect Biome's noUnusedImports
to remove this kind of imports, as the import is unused, and clearly not intended to be written that way.
The interesting thing is, the empty imports are also caused by auto-fix of noUnusedImports
. An unused import like this is successfully removed:
import { A } from 'module';
But when there are one or more imports and all are unused, it generates an empty import.
import { A, B } from 'module';
// After fix it becomes
import {} from 'module';
This doesn't happen in CLI and only happens in IDE (VSCode). I noticed that when fixing this code, I can briefly see that code is converted to import { A, } from 'module';
first. I think this happens because the fixer applies the fixes step-by-step as @Conaclos noted here.
Note that noUnusedImports
is known to cause some other related issues (#3383).
Code of Conduct
- [X] I agree to follow Biome's Code of Conduct