I'd like to run ts-prune in order to detect dead code on the files staged for commit using lint-staged.
I've tried the following:
"find-deadcode": "ts-prune -e",
...
"lint-staged": {
"*.{js,ts,tsx}": [
"npm run find-deadcode",
"eslint --fix"
]
}
However it lists all files with dead code instead of only the ones that are going to be commmited.
Is there a way to achieve this?
lint-stagedworks by passing the list of staged files to the specified commands. Sincets-prunedoesn't take a list of files as an argument it doesn't work out-of-the-box withlint-staged.An alternative to @James's answer if you want to use
lint-stagedis to wrapts-prunein a script that takes the file list supplied bylint-stagedand filters the output using it.tools/ts-prune-included.shAnd you'd use it in the
lint-stagedconfig like so: