xojs/xo

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

Opened this issue · 4 comments

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

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

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)

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)

I've been using this plugin and I agree that its autofix is useful.