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: return non-zero exit code if there's an offense #39032

Closed
khos2ow opened this issue May 12, 2020 · 4 comments
Closed

x/tools/cmd/goimports: return non-zero exit code if there's an offense #39032

khos2ow opened this issue May 12, 2020 · 4 comments
Labels
Milestone

Comments

@khos2ow
Copy link

@khos2ow khos2ow commented May 12, 2020

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

$ go version
go version go1.14.2 linux/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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="~/.cache/go-build"
GOENV="~/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="~/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/lib/go/go-latest"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/lib/go/go-latest/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="~/go/path/to/project/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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build335622656=/tmp/go-build -gno-record-gcc-switches"

What did you do?

This is more of a feature request (or question) rather than bug reporting. I'm trying to check formatting of go files with goimports which works as expected, but if there's any offensive file it always exit with code 0. As a result I need to hack around with tee and similar tools to manually fail my make checkfmt target on CI.

I was wondering if this was by design or any specific reasons not to return non-zero exit code on list (-l). I briefly looked around and it seems there might be a really easy way to add this, something like adding:

if *list {
	fmt.Fprintln(out, filename)
+	exitCode = 1 # or any other reasonable exit code
}

right after line 156, here:

https://github.com/golang/tools/blob/a4cde3673cf4d442ef00a2df0d7a6f707d9e726b/cmd/goimports/goimports.go#L155-L157

@gopherbot gopherbot added this to the Unreleased milestone May 12, 2020
@gopherbot gopherbot added the Tools label May 12, 2020
@khos2ow khos2ow changed the title x/tools/cmd/goimports: Return exit code greater than zero if there's an offense x/tools/cmd/goimports: return non-zero exit code if there's an offense May 12, 2020
@heschik
Copy link
Contributor

@heschik heschik commented May 13, 2020

Makes sense to me. Would you like to send a CL?

@khos2ow
Copy link
Author

@khos2ow khos2ow commented May 13, 2020

Yes definitely.

@gopherbot
Copy link

@gopherbot gopherbot commented May 18, 2020

Change https://golang.org/cl/234484 mentions this issue: cmd/goimports: retrun exit code 1 when offense found

@heschik
Copy link
Contributor

@heschik heschik commented Jun 10, 2020

Rolling this back per #39316 (comment).

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
4 participants
You can’t perform that action at this time.