But other than that it's pretty nice, I might look into the code to see if I can help with that small bug.
I’ve tried tools like this in the past within projects that have high test coverage but I have never had any luck because of this edge case.
Unused imports is perhaps the one area where I would be comfortable removing unused imports. I would never personally allow a third party package into our environment for something like this. I really don’t want to be rude about it, but it’s too “trivial” to rely on an external import for. Not because your code couldn’t be better than ours, it probably will be, but because it’s an unnecessary risk.
For smaller or personal projects I think many people will rely on something like prettier to do the same.
One interesting observation: when using it with our Next.js project, it flags all page TypeScript files as unused. This inadvertently highlights a potential drawback of file-system based routing - it can lead to less explicit code relationships.
I've added a more detailed explanation to README so I hope it will change your mind if you've previously had a negative impression :)
BTW a complimentary tool I've used in the past is depcheck, it is an npm package that removes unused dependencies from your npm package.json file. Smaller package.json files means faster "npm install" and also smaller docker files.
https://marketplace.visualstudio.com/items?itemName=iulian-r...
Has more features (like excluding enums) and works very well in large code bases.
For python there is a lib for this, but it is a bit crappy.
That’s a genuine question — I’m only passingly familiar with tree-shaking so I may have a misunderstanding of what it does.
Could this also work with .svelte files, which are essentially html-like files with <script lang="ts">?
This looks great, particularly the `skip` and `mode` options (which I'm guessing several commenters here missed).
I suppose it should work just as well with monorepos or any other directory hierarchy right? It only "knows" files are unused because they're never referenced in any code within the defined `projectRoot, and it only knows exports are unused whenever they're never imported?
Cool project, will definitely try it soon.
It deleted 100s of files, most of which were Jest test files, and potentially all of which were a mistake. I restored them all with `git restore $(git ls-files -d)`.
I then ran `tsc` on the remaining _modified_ files and `Found 3920 errors in 511 files.`
Obviously at that point I had no choice but to discard all changes and unfortunately I would not recommend this for others to even try.