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: why goimports rename variables #38637

Closed
ericxsun opened this issue Apr 24, 2020 · 0 comments
Closed

x/tools/cmd/goimports: why goimports rename variables #38637

ericxsun opened this issue Apr 24, 2020 · 0 comments
Labels
Milestone

Comments

@ericxsun
Copy link

@ericxsun ericxsun commented Apr 24, 2020

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

$ go version

go version go1.13.9 darwin/amd64

Does this issue reproduce with the latest release?

not tested

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/username/Library/Caches/go-build"
GOENV="/Users/username/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY="git.in.xxx.com"
GONOSUMDB="git.in.xxx.com"
GOOS="darwin"
GOPATH="/Users/username/go"
GOPRIVATE="git.in.xxx.com"
GOPROXY="https://goproxy.in.xxx.com,direct"
GOROOT="/usr/local/Cellar/go@1.13/1.13.9/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go@1.13/1.13.9/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/username/go/src/git.in.xxx.com/data/projectname/go.mod"
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/j0/j6p5rq894ysfxdscvqm4qfzh0000gn/T/go-build516394362=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

format generated thrift file

before format Output
  switch cmd {
	case "batch_get":
		if flag.NArg()-1 != 1 {
			fmt.Fprintln(os.Stderr, "BatchGet requires 1 args")
			flag.Usage()
		}
		arg8 := flag.Arg(1)
		mbTrans9 := thrift.NewTMemoryBufferLen(len(arg8))
		defer mbTrans9.Close()
		_, err10 := mbTrans9.WriteString(arg8)
		if err10 != nil {
			Usage()
			return
		}
		factory11 := thrift.NewTSimpleJSONProtocolFactory()
		jsProt12 := factory11.GetProtocol(mbTrans9)
		argvalue0 := media_profile_2_thrift.NewBatchGetParam()
		err13 := argvalue0.Read(jsProt12)
		if err13 != nil {
			Usage()
			return
		}
		value0 := argvalue0
		fmt.Print(client.BatchGet(context.Background(), value0))
		fmt.Print("\n")
		break
	case "":
		Usage()
		break
	default:
		fmt.Fprintln(os.Stderr, "Invalid function ", cmd)
	}

format with cmd

$ goimports -w -local -v -l filename

after format

after format Output
	switch cmd {
	case "batch_get":
		if flag.NArg()-1 != 1 {
			fmt.Fprintln(os.Stderr, "BatchGet requires 1 args")
			flag.Usage()
		}
		arg9 := flag.Arg(1)
		mbTrans10 := thrift.NewTMemoryBufferLen(len(arg9))
		defer mbTrans10.Close()
		_, err11 := mbTrans10.WriteString(arg9)
		if err11 != nil {
			Usage()
			return
		}
		factory12 := thrift.NewTSimpleJSONProtocolFactory()
		jsProt13 := factory12.GetProtocol(mbTrans10)
		argvalue0 := media_profile_2_thrift.NewBatchGetParam()
		err14 := argvalue0.Read(jsProt13)
		if err14 != nil {
			Usage()
			return
		}
		value0 := argvalue0
		fmt.Print(client.BatchGet(context.Background(), value0))
		fmt.Print("\n")
		break
	case "":
		Usage()
		break
	default:
		fmt.Fprintln(os.Stderr, "Invalid function ", cmd)
	}

What did you expect to see?

do not rename, just leave the variable name along

What did you see instead?

see, arg8, mbTrans9, err10, factory11, jsProt12, err13 was renamed to arg9, mbTrans10, err11, factory12, jsProt13, err14 respectively

@ericxsun ericxsun changed the title why goimports rename variables x/tools/cmd/goimports: why goimports rename variables Apr 24, 2020
@gopherbot gopherbot added this to the Unreleased milestone Apr 24, 2020
@gopherbot gopherbot added the Tools label Apr 24, 2020
@ericxsun ericxsun closed this Apr 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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