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

Add eslint-plugin-unused-imports to disallow unused imports #766

Open
nahtnam opened this issue Aug 14, 2024 · 3 comments
Open

Add eslint-plugin-unused-imports to disallow unused imports #766

nahtnam opened this issue Aug 14, 2024 · 3 comments

Comments

@nahtnam
Copy link

nahtnam commented Aug 14, 2024

I noticed that my imports are not being trimmed once I stop using a certain function. Any particular reason?

https://www.npmjs.com/package/eslint-plugin-unused-imports

@voxpelli
Copy link
Contributor

An alternative solution is to use knip for that: https://knip.dev/

@fregante
Copy link
Member

fregante commented Aug 17, 2024

I like knip but it's heavy handed for small projects (it also attempts to delete files you're not using right now, but don't hurt keeping them around)

This could easily be part of eslint and I don't know why it isn't. It seems that it should be part of no-unused-vars

They did reject removing the whole import line, but I can't find any reference about removing specific imports:

- import {log, unused} from 'x'
+ import {log} from 'x'
log(123)

@voxpelli
Copy link
Contributor

I misread the original issue, I thought it was about removing them from package.json.

ESLint itself seems to generally dislike autofixing of this rule: typescript-eslint/typescript-eslint#7877 Because they think it's poor DX when a user has format on save on (I didn't realize that the two things the mentioned plugin in does is to split rule for imports from other undefined vars and enabling auto fix for it)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants