Navigation Menu

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

go.tools/cmd/goimports: order of dot imports differs from gofmt #7866

Closed
kisielk opened this issue Apr 25, 2014 · 11 comments
Closed

go.tools/cmd/goimports: order of dot imports differs from gofmt #7866

kisielk opened this issue Apr 25, 2014 · 11 comments

Comments

@kisielk
Copy link
Contributor

kisielk commented Apr 25, 2014

goimports places dot imports at the end of the imports block, gofmt places them in
alphabetical order. The tools keep undoing each others' changes.

This is annoying some team members use gofmt and other use goimports, the import lines
keep jumping around.
@kisielk
Copy link
Contributor Author

kisielk commented Apr 25, 2014

Comment 1:

Sorry, didn't change full/import/path before clicking submit. Of course it should be
code.google.com/p/go.tools/cmd/goimports

@ianlancetaylor
Copy link
Contributor

Comment 2:

Labels changed: added repo-tools, release-go1.3maybe.

@bradfitz
Copy link
Contributor

Comment 3:

Can you provide an example minimal play.golang.org program that shows differing results?
I failed to make a repro quickly.

@kisielk
Copy link
Contributor Author

kisielk commented Apr 25, 2014

Comment 4:

http://play.golang.org/p/cvG0QUhg0H
Check Imports then click Format. Now uncheck it and click Format again.

@bradfitz
Copy link
Contributor

Comment 5:

Oh, goimports is forgetting to put a blank line in between the standard library and the
3rd-party imports in this case.

@rsc
Copy link
Contributor

rsc commented May 9, 2014

Comment 6:

We're not shipping goimports in the binary release so not tied to a specific release.

Labels changed: added release-none, removed release-go1.3maybe.

Status changed to Accepted.

@dmitshur
Copy link
Contributor

Comment 7:

The problem is in imports.go:
https://code.google.com/p/go/source/browse/imports/imports.go?repo=tools&r=1911e4f0ca34#241
  var impLine = regexp.MustCompile(`^\s+(?:\w+\s+)?"(.+)"`)
That regex fails to match dot imports (it works fine for _ and renamed imports, since \w
captures that, but not dot).
It can be fixed by changing the regex to:
  var impLine = regexp.MustCompile(`^\s+(?:[\w\.]+\s+)?"(.+)"`)
In my testing, that fixes this issue. Being regex, it may introduce other issues (and
it's unfortunate to need to resort to regex to make Go source modifications), so I'll
let someone else figure out if this is acceptable.
I could make a CL for it, but I already have one in flight, so I'll wait until that
moves forward, or after 1.3 is out.

@bradfitz
Copy link
Contributor

Comment 8:

Sorry, your other CL is now submitted. Could you send a CL & test for this one as well?

@dmitshur
Copy link
Contributor

Comment 9:

Thanks a lot; will do later today!

@dmitshur
Copy link
Contributor

Comment 10:

This issue was fixed by https://golang.org/cl/99400043. Can someone close it
please?

@minux
Copy link
Member

minux commented Aug 10, 2014

Comment 11:

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 25, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants