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: missing import alias #30035

Closed
vearutop opened this issue Jan 31, 2019 · 4 comments
Closed

x/tools/cmd/goimports: missing import alias #30035

vearutop opened this issue Jan 31, 2019 · 4 comments
Assignees
Milestone

Comments

@vearutop
Copy link
Contributor

@vearutop vearutop commented Jan 31, 2019

What version of Go are you using (go version)?

$ go version
go version go1.11.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/viacheslav.poturaev/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/viacheslav.poturaev/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/lb/j0gz8jln36z4frqkrzmkdb0c0000gp/T/go-build387979460=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

After go get -u golang.org/x/tools/cmd/goimports.
Having a file.go with

import "github.com/bla/updater-go"

I'm running goimports -w file.go.

What did you expect to see?

import updater "github.com/bla/updater-go"

What did you see instead?

import "github.com/bla/updater-go"

Not long ago goimports started adding aliases in case package name differs from import path, with recent update that seem to be reverted.

@gopherbot gopherbot added this to the Unreleased milestone Jan 31, 2019
@puellanivis
Copy link

@puellanivis puellanivis commented Jan 31, 2019

This was an intentional reversion to prior behavior: #29556

@vearutop
Copy link
Contributor Author

@vearutop vearutop commented Jan 31, 2019

#29556 is likely to be relevant, I tried with different imports:

	“github.com/acme/stats-go”
	uuid “github.com/acme/go.uuid”

and got uuid added because go does not match package name uuid, while stats-go does match stats package name after non-identifier rune cut off.

@ianthehat
Copy link

@ianthehat ianthehat commented Jan 31, 2019

This was an intentional change.
We decided that goimports was adding a local alias in cases where the name was easy to determine from a simple rule, in cases where the base name is not valid as a package name.
RIght now the rules are, any trailing path fragments that look like versions are dropped.
The last remaining fragment is examined, if it starts with go- then that bit is dropped.
If the remains contains a character that would not be valid in an identifier, then only the part before that character is considered.
If what we have left matches the internal name, then no local alias is added, otherwise one is.

@ianthehat ianthehat closed this Jan 31, 2019
@hiromaily
Copy link

@hiromaily hiromaily commented Apr 3, 2019

@ianthehat
As you mentioned, goimports added many aliases but it affects many our source code and it's not readable for us because we are used to previous code without alias.
Is there any way to prevent alias addition functionality??

@golang golang locked and limited conversation to collaborators Apr 2, 2020
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
5 participants
You can’t perform that action at this time.