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
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@khos2ow
Copy link

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 This label describes issues relating to any tools in the x/tools repository. 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
@heschi
Copy link
Contributor

heschi commented May 13, 2020

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

@khos2ow
Copy link
Author

khos2ow commented May 13, 2020

Yes definitely.

@cagedmantis cagedmantis added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. NeedsFix The path to resolution is known, but the work has not been done. labels May 18, 2020
@gopherbot gopherbot removed the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label May 18, 2020
@gopherbot
Copy link

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

@heschi
Copy link
Contributor

heschi commented Jun 10, 2020

Rolling this back per #39316 (comment).

@golang golang locked and limited conversation to collaborators Jun 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

4 participants