Static Newsabout
kazushisan | 14 comments

joseferben|next|

really nice that you're tool focuses on removing. i've been using https://knip.dev/ for detection in monorepos, but it's cumbersome to remove manually.

Cannabat|parent|next|

Knip does have some auto fix capabilities but it’s not perfect yet. The detection is great, though. I use it with `dpdm` to keep things tidy. With these (plus eslint, prettier and typescript) in CI, I feel all warm and fuzzy.

OP, can you describe differences from knip?


zlies|prev|next|

You should switch the default to not delete any files and modify/remove the files only with some flag (--dry-run=false, --rm, --delete, etc). I just deleted all files accidentally in a monorepo :D Luckily I didn't had any uncommitted changes and could recover using git

jamil7|parent|next|

It's maybe reasonable to change the defaults, but I think you should also be mindful of running any random cli program in your codebase, the top of the Github readme does indicate that the --check mode runs it without deleting files.

zlies|root|parent|next|

You're totally right. I just quickly scanned the readme and had expected a tool that only check the files. But yes, it's a bad idea in general to run random cli programs without checking them in detail

kazushisan|root|parent|next|

I’m sorry that it may have been unclear that the tool will make modifications without the check flag. I’m glad you didn’t loose any unstated changes :)

I will add a cautionary note to README to make it clear!


devjab|prev|next|

This is cool, as a place which uses Typescript for a lot of things, including back-end services we handle it differently. Basically we have a rather strict linting process setup which will warn developers of unused code in development environments and outright refuse it for staging deployment and forward. I’m not sure we would “dare” to automatically remove it, because for the most part there is a reason it is there. Maybe it’s something that needs to be deleted, but it’s almost always something which needs to be handled in some way.

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.


kazushisan|parent|next|

Thanks for the input! I think there may be a misunderstanding about what this does. Existing linters work great for detecting unused code within a file but once you add `export` to it, you can’t detect unused code with linters even if it’s not referenced from any file.

You’re right that this tool may not be useful for some codebases. If your modules are more like “scripts” that include side effects, deleting modules just because it’s not referenced may break things. That should not be the case for react projects that are based on components.

In our development process, we don’t allow the changes made by this tool to be deployed automatically. Instead we make sure the changes are okay by creating a pull request and reviewing. We treat it more like an assistant that does all the cumbersome clean up work in no time.


cdaringe|prev|next|

Cool. A prettier plugin does this too. Cant remember which, but maybe https://www.npmjs.com/package/prettier-plugin-organize-impor...?

aiibe|prev|next|

Another good alternative. Archived but still in used at work. https://github.com/nadeesha/ts-prune

kazushisan|parent|next|

I was initially using it but decided to write my own tool because I was too lazy to go through the result of ts-prune and delete the code myself :P

_aqua|prev|

Does not work quite well with monorepos, just tried but overall a good idea

kazushisan|parent|

Perhaps you need to specify skip option for the entry point file?