Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable imports processing #308

Open
scop opened this issue Jul 24, 2024 · 2 comments
Open

Option to disable imports processing #308

scop opened this issue Jul 24, 2024 · 2 comments

Comments

@scop
Copy link
Contributor

scop commented Jul 24, 2024

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

  • There seem to be a few long standing issues related to them, so it could be useful for direct gofumpt users.
  • Also, when using golangci-lint and gofumpt together with gci or goimports, the formatters can stomp on each other in some cases and result in e.g. duplicate imports: gci+goimports = duplicated imports golangci/golangci-lint#1490
    This one (given compatible formatter configs) is quite likely a golangci-lint bug that should be fixed there. But it can be that a user wants to use let's say a gci config that differs from gofumpt's opinion on imports, but wants to use both it and gofumpt because both are great at what they do, and there's nothing golangci-lint could do about that. Even if there would be no formatting conflicts, the formatting done by gofumpt would be redundant for cases where another import formatter is in use.

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

@mvdan
Copy link
Owner

mvdan commented Jul 24, 2024

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
Copy link
Contributor Author

scop commented Jul 25, 2024

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants