-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
x/tools/cmd/goimports: Allow "-local" imports to be sorted in between standard library and third party imports #27673
Comments
I think it's highly beneficial to avoid adding flags if possible.
A better way to resolve this would be to change those packages to be consistent with what goimports does (easy), or perhaps change goimports if everyone seems to be doing something else (hard; how to confirm this?). /cc @bradfitz @josharian per owners. |
Yeah, I don't really like the idea of a separate flag, but the (a) 2 groups: "standard" and "everything else" |
Related issue is #20818. |
Worth noting here that the example in the CodeReviewComments section on imports seems to suggest a three-group pattern: standard library, local imports, then third-party imports. It'd be nice to align that wiki page with the default |
golang/tools@12a7c31 changed goimports such that groups are combined. e.g. import (
"os"
"github.com/aws/aws-lambda-go/lambdacontext"
"github.com/elastic/apm-agent-go"
) becomes import (
"os"
"github.com/aws/aws-lambda-go/lambdacontext"
"github.com/elastic/apm-agent-go"
) When using
I'm in favour of one canonical grouping scheme, and my preference is (b). In order for (b) to work, I think we need a way of identifying the local imports without |
I don't like the idea to have a canonical grouping scheme. Because there is no canonical way to name packages and importpaths, there is no way for goimports to be smart enough to do the grouping in a sensible way. However, a config file might work -- put packages matching certain rules in a certain group -- but such config sounds troublesome and I'd prefer to avoid. |
With go modules (go 1.11) One could defer the |
Is there something specific to be done here? I think we're pretty clear that we don't want any more configuration for |
Why not make goimports part of gofmt, removing all configuration? Just sort the imports (and maybe group stdlib and "everything else" separately) and that's it. Why not? |
The full functionality of goimports is way too complicated, subtle, and slow to be integrated into gofmt. Sorting and grouping imports I suppose you could make a case for but that doesn't even work right in goimports today, see #20818. |
Makes sense to me to avoid any more flags. I think that means the recommendation is to sort local packages in the 3rd group? It would be nice if this was called out and examples (e.g., style guide) reflected that. A separate unrelated issue, it may be more reasonable to auto-detect |
That's https://golang.org/issue/32049, basically. |
goimports supports a
-local
flag to identify local imports, which are currently sorted after 3rd party import groups. However, this doesn't match the import ordering of some projects which sort local imports last. E.g.,Should goimports have flags to control the import group ordering, or should local packages always be imported last?
The text was updated successfully, but these errors were encountered: