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

x/tools/cmd/goimports: provide a flag for the local import path prefix #12420

Closed
kr opened this issue Aug 31, 2015 · 4 comments
Closed

x/tools/cmd/goimports: provide a flag for the local import path prefix #12420

kr opened this issue Aug 31, 2015 · 4 comments
Milestone

Comments

@kr
Copy link
Contributor

@kr kr commented Aug 31, 2015

My company has tried to adopt a convention placing import paths into three groups: standard library followed by third-party packages followed by local packages. For example

import (
    "database/sql"
    "io"
    "strconv"

    "github.com/lib/pq"

    "mycompany.com/foo/bar"
    "mycompany.com/foo/baz"
)

We'd like to be able to add a flag to our goimports-on-save hook, like

goimports -local mycompany.com/

to tell goimports to put any paths beginning with "mycompany.com/" into our third group. I think that would end up as group value 3 in the goimports source: stdlib=0, 3rd party=1, appengine=2, then local=3.

If this sounds reasonable, I can write a patch.

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Aug 31, 2015
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Aug 31, 2015

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jul 21, 2016

Seems fine I guess. I suppose to tell your editor to pass the argument you might need to make a wrapper program which added the arg, depending on your editor.

@kr
Copy link
Contributor Author

@kr kr commented Jul 22, 2016

I just sent https://golang.org/cl/25145.

If matchPattern were handy, I would have made this a pattern like 'example.com/...'. But a simple prefix gets the job done (for me anyway).

The plumbing was a little gross. I'm all ears for a cleaner approach.

kr added a commit to kr/tools that referenced this issue Jul 22, 2016
This allows the caller to indicate they want certain
import paths to sort into another group after 3rd-party
imports when added by goimports. For example, running
'goimports -local example.com/' might produce

    import (
        "database/sql"
        "io"
        "strconv"

        "golang.org/x/net/context"

        "example.com/foo/bar"
        "example.com/foo/baz"
    )

Updates golang/go#12420

Change-Id: If6d88599f6cca2f102313bce95ba6ac46ffec1fe
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 22, 2016

CL https://golang.org/cl/25145 mentions this issue.

kr added a commit to kr/tools that referenced this issue Jul 22, 2016
This allows the caller to indicate they want certain
import paths to sort into another group after 3rd-party
imports when added by goimports. For example, running
'goimports -local example.com/' might produce

    import (
        "database/sql"
        "io"
        "strconv"

        "golang.org/x/net/context"

        "example.com/foo/bar"
        "example.com/foo/baz"
    )

Updates golang/go#12420

Change-Id: If6d88599f6cca2f102313bce95ba6ac46ffec1fe
@golang golang locked and limited conversation to collaborators Jul 23, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.