numtide / treefmt

one CLI to format your repo
https://treefmt.com
MIT License
551 stars 33 forks source link

Add support to follow `.gitignore` (or custom `.treefmtignore`) file for ignoring files or directories? #198

Open aldoborrero opened 1 year ago

aldoborrero commented 1 year ago

Rationale

Sometimes, you want to exclude directories that don't belong to any specific language but rather because you don't want treefmt to traverse those. As far as I'm aware, you need to exclude those from one specific formatter.

Note: There's global support for ignoring directories.

We can add support to follow the .gitignore options or if .treefmtignore is present, add those directories to the global config.

We can achieve a similar behaviour by leveraging something like gitignore crate.

zimbatm commented 1 year ago

At the moment it looks for .ignore files during the tree traversal if I'm not mistaken, per the ignore crate. I think it can be extended to also load .gitignore files?

I think the big question is: are there cases where you want to treefmt a file that is not in git? If yes, then it would be circumventing that use case.

zimbatm commented 1 year ago

Related to https://github.com/numtide/treefmt/issues/154 and https://github.com/numtide/treefmt/issues/182