Find and remove unused es6 modules
If running typescript-eslint please use the -ts
extension on your rules to make this also leverage type information (otherwise the autofixer will remove
imports only used for type information). There is an example in the Usage section below.
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-unused-imports
:
$ npm install eslint-plugin-unused-imports --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-unused-imports
globally.
Add unused-imports
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": ["unused-imports"]
}
Then configure the rules you want to use under the rules section.
e.g.
{
"rules": {
"no-unused-vars": "off",
"unused-imports/no-unused-imports": 2,
"unused-imports/no-unused-vars": 1
}
}
Or, if using TypeScript:
{
"rules": {
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports-ts": 2,
"unused-imports/no-unused-vars-ts": 1
}
}
no-unused-imports
no-unused-vars
no-unused-imports-ts
no-unused-vars-ts