Specifically, -local flag:
-local string
put imports beginning with this string after 3rd-party packages
That is very useful for projects that follow this grouping style:
import (
// stdlib
// third-party
// other packages of that project
)
goimports shouldn't complain if the file is already formatted with -local - it's still correctly imported as goimports won't merge/sort newline-separated blocks of imports.
Yes, but I want it to complain if imports are not formatted with -local flag, but local setting is present in the configuration.
Hi!
Thank you for the idea,
I supported it in the master branch. I will include it into a next release
@jirfag I don't think this is working as intended yet.
We're setting https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/gofmt.go#L115 , which resolves to golang.org/x/tools/imports.LocalPrefix ( https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/gofmt.go#L9 )
Then we invoke https://github.com/golangci/golangci-lint/blob/master/vendor/github.com/golangci/gofmt/goimports/golangci.go#L11 , which in turn uses https://github.com/golangci/golangci-lint/blob/master/vendor/github.com/golangci/gofmt/goimports/golangci.go#L8 - golang.org/golangci/tools/imports.LocalPrefix
So when GoImports is invoked, it doesn't have the LocalPrefix that we attempted to set - we set another LocalPrefix that isn't used.
I won't PR this as it's pretty deep into dep hell - swapping https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/gofmt.go#L9 to github.com/golangci/tools/imports works for me - but there may be a better solution (or more cleanup: like picking one of the vendored goimports and using it).
thank you
@thepwagner you are right, the bug was introduced in commit c02a6daa5c6d2b0faf5b4be37b65ef15a52a1f35.
I need to make a test for it, the fix will be to use golang.org/x/tools (I've switched to the fork because of the bug in x/tools, now it should be fixed)
Most helpful comment
@thepwagner you are right, the bug was introduced in commit c02a6daa5c6d2b0faf5b4be37b65ef15a52a1f35.
I need to make a test for it, the fix will be to use golang.org/x/tools (I've switched to the fork because of the bug in x/tools, now it should be fixed)