xojs / xo

❤️ JavaScript/TypeScript linter (ESLint wrapper) with great defaults
MIT License
7.65k stars 291 forks source link

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

Open nahtnam opened 4 weeks ago

nahtnam commented 4 weeks ago

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 commented 4 weeks ago

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

fregante commented 3 weeks ago

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 commented 3 weeks ago

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: https://github.com/typescript-eslint/typescript-eslint/issues/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)