remove-unused-vars
v0.0.11
Published
Remove more unused variables
Downloads
34,548
Readme
remove-unused-vars
Remove more unused variables. Highly experimental.
[!WARNING]
There's a reason linters don't fix the unused variables, even with a flag like
--unsafeor--fix-dangerously.
Modern linters can fix a lot of issues automatically, but don't always remove all unused variables and types. Even when
using --unsafe or --fix-dangerously.
Use remove-unused-vars to remove everything the linter finds. Then run QA and review if there's anything that might
need reverting. Needless to say, Git's your friend here!
Don't use e.g. eslint --fix or biome lint --write when piping to remove-unused-vars, otherwise the positions to
remove things might not match up. Use the linter first to have it remove whatever it can, then proceed with the
command(s) below.
[!TIP]
Use this with Knip for a cruel code crusher experience.
Install
npm install -D remove-unused-varsPipe JSON
Pipe the JSON-formatted output of the linter to remove-unused-vars
Add to package.json#scripts, modify the commands below and make sure to use local linter configuration.
ESLint
eslint --rule 'no-unused-vars: error' --quiet -f json | remove-unused-varstypescript-eslint
eslint --rule 'no-unused-vars: off' --rule '@typescript-eslint/no-unused-vars: error' --quiet -f json | remove-unused-varsBiome
biome lint \
--only correctness/noUnusedVariables \
--only correctness/noUnusedImports \
--only correctness/noUnusedFunctionParameters \
--reporter json | remove-unused-varsoxlint
oxlint -A all -D 'no-unused-vars' -D '@typescript-eslint/no-unused-vars' -f json | remove-unused-varsFrom JSON file
Alternatively, provide a JSON file as the first argument to remove-unused-vars, for example:
oxlint -A all -D '@typescript-eslint/no-unused-vars' -f json > unused-vars.json
remove-unused-vars unused-vars.jsonWithout installation
Use something like this without installing remove-unused-vars:
eslint -- --quiet --format json | npx -y remove-unused-vars