-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
golangci-lint cli returning non-zero value for issues raised at a severity level not of error #1981
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
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
Hello, The severity configuration doesn't change the exit code but adds/changes the field There is no correlation between severity and exit code, then there is no bug. It kind of duplicate of #1856 |
I would say it's more a feature request than a question if it's not a bug. If we look at the general conventions around linting, non-errors shouldn't return an error code. This has been implemented in a few ways:
There's a few patterns in use here between these three and I believe it would be very useful to have at least some solution that allows for the reporting, however, and importantly, not the failing, of the outcome based on a desired level of failure. That could be adopting a flag on the severity level to drive the exit code, or alternatively to provide an approach like pylint where the exit code indicates which lints have failed at each of the severity types, then letting the user determine if that indeed represents a failure or not. If there's no correlation between severity and the exit code, what purpose does severity serve? Merely a presentation formatting of some of the linters? This seems short sighted in terms of the goal of having multiple severity levels. If that is indeed the case, then I believe the documentation should be updated to reflect this and emphasise that this is for decorative purposes and not to drive exit codes of the linter. |
An example of this can be found in the Ruby linter
Adding a flag such as this would enable the linter to fail on certain errors but return a zero value for other levels. This is important because if you exclude items from the linter they will not appear in the report. Later on you may decide you want to fail a particular error as the program matures and you want to restrict (or loosen) some of the linting properties. |
Some kind of exit-code-filtering feature would be very useful. For example, golangci-lint today can generate code quality reports for GitLab merge requests, which use the Code Climate format that golangci-lint supports. GitLab displays new issues on merge requests and breaks them down by severity level. I would really like to enable the godox linter with Today the workaround would be to enable the godox linter using a commandline flag in the CI/CD script, to override the config file. However this does not scale to more linters, where it would become necessary to manage two different configs. |
How about adding a new field to the I imagine this would be where you want to configure this, since golangci-lint doesn't know how to sort severities. golangci-lint/pkg/config/severity.go Lines 11 to 14 in ee30b44
Example: severity:
default-severity: major
rules:
- severity: minor
linters:
- funlen
- severity: info
issuesExitCode: 0
linters:
- godox |
I was going to work on this (and severity coloring) feature starting next month. Feel free to pick it up and make PR, if you don't want to wait. |
+1 for this - it needs to be command line configurable easily. The worst offenders are the documentation-type linters, which provide good actionable items, but shouldn't block builds in CI but also should be kept visible. The essence of the problem here is that the alternative is maintaining and synchronizing multiple, fairly complicated linter configs per project for different scenarios. i.e. issues with variable naming (revive and the like) really should block before people commit code. But documentation can be fixed at any time and won't effect interfaces...but it's nice to know about it. Currently though, there's no option: I can't have my linter scripts just say |
@wrouesnel I will return to this feature once war ends. |
You have far bigger concerns to focus on right now @butuzov. Stay safe. |
Would anyone else be able to work on this ticket while @butuzov is indisposed? I could take a look at it myself. |
I'd be happy to have a look at this if there's agreement on how it should work. We could add a new property to severity e.g. severity:
default-severity: error
severities:
error:
exit-code: 1
warning:
exit-code: 0 Alternatively, if we're certain there will never be more settings on the severities, it could also be like so: severity:
default-severity: error
exit-codes:
error: 1
warning: 0 Or it could be part of the rule config e.g. severity:
default-severity: error
rules:
- linters:
- godox
severity: warning
exit-code: 0 I'm not a huge fan of the latter though, as I feel the exit code should be tied to the severity, not the rule. |
I think it's important to allow certain linters to override the default setting. My use case is in CI I want some linters to be fails and some to be more like "Well you should get to this at some point" |
This is a perfect use case for us. We need some linters in warning mode and others to fail so we can integrate them into an old project, allowing for gradual improvements in small iterations. |
Any update? |
What is the point of severity if both warnings and errors yield the same result; a failing build? It only seems meaningful for code quality reporting tools; for anyone with a simpler setup (I imagine the majority of users), severity is pointless? |
|
It would still be a useful feature to be able to map severities to exit codes though. As mentioned last year I'd be happy to contribute that but would need some agreement on how it should be configured. |
I think I will close this issue, because, for now, we don't plan to do it. I will quote myself:
|
Running golangci-lint CLI with severity set to `info` for a given linter returns a non-0 value
v1.39.0, v1.40.0
Config file
Go environment
Verbose output of running
Code example or link to a public repository
https://github.com/jufemaiz/golangci-lint-check-exit
The text was updated successfully, but these errors were encountered: