numtide / treefmt

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

gofmt should not format vendor directories #306

Closed tom-wegener closed 1 month ago

tom-wegener commented 1 month ago

Is your feature request related to a problem? Please describe.

When using gofmt it always also formats my vendor directory which is not necessary since this is code I won't touch.

It also completely ignores any exclude settings but I guess that this is a gofmt problem since it does not support excludes.

Describe the solution you'd like

The trick most people use is something like gofmt -w go list ./... | grep -v /vendor/ which is not perfect but a solid start. Similar behaviour could be switched on via the config.

Additional context

gofumpt also does not work.

zimbatm commented 1 month ago

Did you try using the excludes functionality? Something like this should fix your issue:

[global]
excludes = [
  "vendor/*"
]
tom-wegener commented 1 month ago

I'm using treefmt-nix (which uses treefmt, I think) and my config was slightly off but didn't report an error so I thought I was wrong but after looking a bit harder at the docs and you saying that it should work I found my error.

I had settings.excludes = ["**/vendor/*"] in my config but settings.global.excludes = ["**/vendor/*"] was necessary (the global was missing).

Thank you for your fast reply!