knip icon indicating copy to clipboard operation
knip copied to clipboard

Respect up-the-tree `.gitignore` files

Open alecmev opened this issue 5 months ago • 6 comments

I have a .gitignore in my ~ with the following contents:

.scratch/

This allows me to plop .scratch directories all over the place and put not-for-remote stuff there like personal notes, half-baked code snippets, etc. Knip, unfortunately, doesn't look at ~/.gitignore and reports code files in .scratch directories as unused.

I don't want to add .scratch to the repo .gitignore because it has nothing to do with the project. I don't want to store these files outside of the repo because I want to keep them close to the packages they're related to.

alecmev avatar Feb 29 '24 15:02 alecmev

Does something like npm do the same eg when publishing?

webpro avatar Feb 29 '24 15:02 webpro

Doesn't look like it, unfortunately:

https://stackoverflow.com/q/12534699/242684 https://github.com/semantic-release-action/typescript/issues/10#issuecomment-1536964025

Though I wouldn't treat npm's choices as gospel :sweat_smile:

alecmev avatar Feb 29 '24 15:02 alecmev

To frame this a little bit differently, how else could I tell Knip to ignore **/.scratch/** without polluting the configuration?

alecmev avatar Feb 29 '24 15:02 alecmev

I'm not against the feature per se, but I also don't want unexpected results. What might be a feature to you, could be a hard-to-track and tricky-to-overcome issue to someone else.

So if other tools use it as well it's common/expected behavior.

To frame this a little bit differently, how else could I tell Knip to ignore **/.scratch/** without polluting the configuration?

You can use ignore at the root config with this pattern. If you don't fancy that you could perhaps use a knip.ts and make it more DRY.

webpro avatar Feb 29 '24 16:02 webpro

I'm struggling to find examples. Prettier doesn't respect .gitignore, nor does ESLint. Biome, however, does (at least intends to). Outside of JavaScript, RipGrep does too, and fd. Can you maybe suggest some more projects to take a look at?

I'm not against the feature per se, but I also don't want unexpected results. What might be a feature to you, could be a hard-to-track and tricky-to-overcome issue to someone else.

On the one hand, I agree, changes like this require justification. On the other hand, Git is the common denominator here. If a file ultimately isn't committed, does it make sense to ever take it into consideration?

alecmev avatar Mar 01 '24 22:03 alecmev

It should probably just follow whatever git check-ignore does?

TheKnarf avatar Mar 11 '24 09:03 TheKnarf