Auto-fix
WARNING: This is an experimental feature. Make sure to run in a VCS/Git repository so you can review and undo changes if necessary.
Run Knip as you normally would, and then run it again with the --fix
flag to
let Knip automatically apply fixes. Currently includes:
- Remove
export
keyword for unused exports - Remove
export
keyword for unused types - Remove unused
dependencies
anddevDependencies
frompackage.json
- Works across workspaces in a monorepo
Use --fix-type
to fix only specific issue types (exports
, types
and/or
dependencies
). Example:
Example Result
The export
keyword for unused exports is removed:
Note that also the default
keyword was removed here.
Sometimes a line can be completely removed safely:
Unused dependencies are removed from package.json
:
Post-fix
- You may want to run tools like
eslint --fix
orprettier --write
to fix the remaining issues. - Verify changes in
package.json
and update dependencies using your package manager:
Notes
Nothing is set in stone, but some ideas include:
- Add unlisted (dev) dependencies to
package.json
- Remove unused files
- Remove unused class and enum members
- Remove empty export declarations after the fact, e.g.:
ISC License © 2024 Lars Kappert