mvdan / gofumpt

A stricter gofmt
https://pkg.go.dev/mvdan.cc/gofumpt
BSD 3-Clause "New" or "Revised" License
3.27k stars 112 forks source link

Option to disable imports processing #308

Open scop opened 2 months ago

scop commented 2 months ago

Could an option to disable gofumpt's processing of imports be added?

An option to disable gofumpt's import processing would help with both of the above.

mvdan commented 2 months ago

gci and gofumpt overlap quite a lot in terms of wanting to be in control of how imports are grouped. They seem to have different goals as well. Why would you use both at the same time?

I don't plan on adding options to disable some of gofumpt's features. Just like gofmt, the tool becomes less useful the more options it gains, as it loses consistency.

If there is something in particular about import grouping that you think gci does better than gofumpt, I'm happy to consider it as a feature request. Or if gci makes any reasonable change that gofumpt later undoes, I'm also open to looking into that as a potential bug. Aside from those two options, I don't see the point in ensuring that gofumpt can be used together with gci.

scop commented 2 months ago

gci formats only imports, and is great at that. gofumpt does a lot of other things gci doesn't and is great at them, but its import formatting is much more limited than gci's. Therefore as it stands, it makes perfect sense to me to want to use both of the tools.

Now, if gofumpt would grow some more abilities in the import sorting/grouping area, I certainly wouldn't mind. gofumpt might do a lot of the following already, but for my taste, the ability to do three groups with one empty line between each, and each group sorted internally alphabetically, would be fine: 1) stdlib, 2) 3rd party (everything that's not stdlib or "local", 3) "local". Alias, dot, and default imports I don't have a particular opinion about as long as they're sorted consistently within their respective group. Maybe all at the beginning or at the end of the group, also sorted by the module path. For the definition of "local", see https://github.com/daixiang0/gci#gci and https://github.com/daixiang0/gci#localmodule

The above is just my preference though (even if I believe it is a fairly common one).