Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Suppress output to stdout in case of 0 issues found #5734

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

Closed
2 of 3 tasks
sdavids opened this issue Apr 15, 2025 · 11 comments
Closed
2 of 3 tasks

Suppress output to stdout in case of 0 issues found #5734

sdavids opened this issue Apr 15, 2025 · 11 comments
Labels
area: CLI Related to CLI question Further information is requested

Comments

@sdavids
Copy link

sdavids commented Apr 15, 2025

Welcome

How did you install golangci-lint?

Brew

Your feature request related to a problem? Please describe

I am not sure if this is a bug, regression, or feature request.

$ golangci-lint --version
golangci-lint has version 2.1.1 built with go1.24.2 from 93dabf9 on 2025-04-12T18:12:29Z
$ golangci-lint run
0 issues.
$ echo $?
0

I would like the option to suppress output to stdout in case of no issues found.

Describe the solution you'd like

$ golangci-lint --version
golangci-lint has version 2.1.1 built with go1.24.2 from 93dabf9 on 2025-04-12T18:12:29Z
$ golangci-lint run
$ echo $?
0

Maybe via -q/--quiet or -s/--silent.

Describe alternatives you've considered

1>/dev/null and explicit check of $?

Additional context

No response

Supporter

@sdavids sdavids added the enhancement New feature or improvement label Apr 15, 2025
Copy link

boring-cyborg bot commented Apr 15, 2025

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

@ldez ldez added area: CLI Related to CLI question Further information is requested and removed enhancement New feature or improvement labels Apr 15, 2025
@ldez
Copy link
Member

ldez commented Apr 15, 2025

Hello,

The stats can be disabled with the following option:

output:
  show-stats: false

https://golangci-lint.run/usage/configuration/#output-configuration

or

golangci-lint run --show-stats=false

https://golangci-lint.run/usage/configuration/#run

@ldez ldez closed this as completed Apr 15, 2025
@deitch
Copy link

deitch commented Apr 17, 2025

Can I ask that we reopen this? What I think the original poster is asking for (or at least, I am 😁 ) is that it shows no stats only if there are no errors.

I think there are lots of programs out there that built around the output of golangci-lint run, in addition to exit codes. Those stats are really useful when there are errors, but we might want no output if there are no errors. So something like:

$ golangci-lint run ./...                   
....
...                                       
1 issues:
* staticcheck: 1
$ echo $?
1
$ 

But:

$ golangci-lint run ./...                   
$ echo $?
0
$ 

Thanks

@sdavids
Copy link
Author

sdavids commented Apr 17, 2025

It used to be a common Unix practice to output nothing if you modified/found nothing.

@sdavids
Copy link
Author

sdavids commented Apr 17, 2025

I just checked:

$ docker run --rm -it golang:1.24.2
# curl -sOL https://github.com/golangci/golangci-lint/releases/download/v1.64.8/golangci-lint-1.64.8-linux-amd64.deb
# apt install ./golangci-lint-1.64.8-linux-amd64.deb
# printf 'package main\nimport "fmt"\nfunc main(){fmt.Println("Test")}' >src/main.go
# golangci-lint --version
golangci-lint has version 1.64.8 built with go1.24.1 from 8b37f141 on 2025-03-17T20:41:53Z
# golangci-lint run src/main.go
# echo $?
0
$ docker run --rm -it golang:1.24.2
# curl -sOL https://github.com/golangci/golangci-lint/releases/download/v2.1.2/golangci-lint-2.1.2-linux-amd64.deb
# apt install ./golangci-lint-2.1.2-linux-amd64.deb
# printf 'package main\nimport "fmt"\nfunc main(){fmt.Println("Test")}' >src/main.go
# golangci-lint --version
golangci-lint has version 2.1.2 built with go1.24.2 from 00a561d9 on 2025-04-15T13:26:47Z
# golangci-lint run src/main.go
0 issues.
# echo $?
0

I would say this is either a regression or an undocumented change in behavior.

@ldez
Copy link
Member

ldez commented Apr 17, 2025

show-stats was already an option inside v1, but false by default.

The "0 issues." is the expected behavior; it's not a regression because this is the same behavior as v1 with show-stats: true.

@bombsimon
Copy link
Member

bombsimon commented Apr 17, 2025

You are comparing two major versions, 1.0 and 2.0, so there are a bunch of breaking changes between them and this being one of them. It's mentioned in the migration guide

issues.show-stats: the existing value is ignored because, in v2, stats are enabled by default.

› docker run --rm -it golangci/golangci-lint:v1.64.8 /bin/bash
root@7f255dd6f820:/go# printf 'package main\nimport "fmt"\nfunc main(){fmt.Println("Test")}' >src/main.go && cd src
root@7f255dd6f820:/go/src# go mod init x
go: creating new go.mod: module x
root@7f255dd6f820:/go/src# golangci-lint run --show-stats
0 issues.

EDIT Oops 🐢, @ldez beat me to it 🏎

@deitch
Copy link

deitch commented Apr 17, 2025

I was not as focused on whether or not it is a regression; heaven knows I am responsible for enough software with behavioural changes between major versions that people complained about. 😁

I was focused on, it is good to have the ability to show stats when there are errors, but to have empty output when there are none. Right now, it is either: show stats whether or not there are errors; or do not show stats whether or not there are errors.

Does that make sense?

@ldez
Copy link
Member

ldez commented Apr 17, 2025

The "0 issues" is the expected behavior. For now, I don't think adding another option only to hide the "0 issues" is worth it.

@deitch
Copy link

deitch commented Apr 17, 2025

expected behaviour

I get that. I am suggesting that another behaviour may be more user-friendly in many cases (and hopefully get other people off your back). Would --show-stats-errors-only be bad?

@ldez
Copy link
Member

ldez commented Apr 17, 2025

I think I answered in the previous comment:

For now, I don't think adding another option only to hide the "0 issues" is worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: CLI Related to CLI question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants