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

version: prints to Stderr instead of StdOut #1868

Closed
4 tasks done
clebs opened this issue Mar 24, 2021 · 2 comments · Fixed by #1869
Closed
4 tasks done

version: prints to Stderr instead of StdOut #1868

clebs opened this issue Mar 24, 2021 · 2 comments · Fixed by #1869
Labels
bug Something isn't working

Comments

@clebs
Copy link
Contributor

clebs commented Mar 24, 2021

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc).
  • Yes, I've tried with the standalone linter if available. (https://golangci-lint.run/usage/linters/)
Commands print to Stderr instead of StdOut

Trying to fetch the version in a shell script: CI_VERSION=$(golangci-lint version --format short) I noticed the variable was empty and I could see the version printed in the terminal.
After investigating I found out that golangci-lint uses Cobra's Println function:

RunE: func(cmd *cobra.Command, _ []string) error {
switch strings.ToLower(e.cfg.Version.Format) {
case "short":
cmd.Println(e.version)

According to Cobra, that function prints to Stderr per default:
https://github.com/spf13/cobra/blob/b55fa79836c63eab81e884e6ec1d7e4ae5c7f9b5/command.go#L1201

Version of golangci-lint Installed automatically with VS Code
$ golangci-lint --version
golangci-lint has version v1.38.0 built from (unknown, mod sum: "h1:hgZsLRzZrjhpp44Ak+fhXNzgrbDF39ETf22a+Jd3fJQ=") on (unknown)
Config file
$ cat .golangci.yml
run:
  modules-download-mode: readonly
Go environment
$ go version && go env
go version go1.16.2 darwin/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="<redacted>/Library/Caches/go-build"
GOENV="<redacted>/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="<redacted>/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="<redacted>"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.16.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/8c/qd3ywlk1039f53l5m8mnfg1w0000gn/T/go-build3420486587=/tmp/go-build -gno-record-gcc-switches -fno-common"
Verbose output of running
$ golangci-lint cache clean
$ golangci-lint run -v
NOT RELEVANT
Code example or link to a public repository
export CI_VERSION=$(golangci-lint version --format short)
echo "current: ${CI_VERSION}"
@clebs clebs added the bug Something isn't working label Mar 24, 2021
@boring-cyborg
Copy link

boring-cyborg bot commented Mar 24, 2021

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@clebs clebs changed the title Commands print to Stderr instead of StdOut version: prints to Stderr instead of StdOut Mar 24, 2021
@clebs
Copy link
Contributor Author

clebs commented Mar 24, 2021

Hi golangci-lint team,

I opened a PR fixing this issue since it is very easy to fix. Also checked all other commands and version is the only one facing this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant