Skip to content
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

📎 noUnusedImports should remove empty imports #3574

Closed
1 task done
KurtGokhan opened this issue Aug 2, 2024 · 7 comments · Fixed by #4478
Closed
1 task done

📎 noUnusedImports should remove empty imports #3574

KurtGokhan opened this issue Aug 2, 2024 · 7 comments · Fixed by #4478
Assignees
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Enhancement Status: Improve an existing feature

Comments

@KurtGokhan
Copy link

KurtGokhan commented Aug 2, 2024

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

  • I agree to follow Biome's Code of Conduct
@Conaclos Conaclos added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Enhancement Status: Improve an existing feature labels Aug 2, 2024
@Conaclos Conaclos changed the title 💅 noUnusedImports should remove empty imports 📎 noUnusedImports should remove empty imports Aug 3, 2024
@danielsht86
Copy link

Is there a workaround for this? Perhaps another rule that would remove the empty imports?

@Conaclos
Copy link
Member

Conaclos commented Sep 4, 2024

Is there a workaround for this? Perhaps another rule that would remove the empty imports?

I think we can extend the behavior of this rule to remove such imports. What do you think?

@danielsht86
Copy link

Is there a workaround for this? Perhaps another rule that would remove the empty imports?

I think we can extend the behavior of this rule to remove such imports. What do you think?

That sounds great to me! That would be amazing

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Sep 6, 2024

I think we can extend the behavior of this rule to remove such imports. What do you think?

I would love to help ;-)

@Conaclos
Copy link
Member

Conaclos commented Sep 6, 2024

Hi @h-a-n-a I already started a wider fix for several issues related to noUnusedImports.

@h-a-n-a
Copy link
Contributor

h-a-n-a commented Sep 6, 2024

Hi @h-a-n-a I already started a wider fix for several issues related to noUnusedImports.

@Conaclos I see! Just out of curious if #3761 is conflicting to your fix?

@Conaclos
Copy link
Member

Conaclos commented Sep 6, 2024

I see! Just out of curious if #3761 is conflicting to your fix?

I don't think so because I only modified the rule implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Enhancement Status: Improve an existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants