-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(severity): color warning severity, non-zero exit when issue != default severity #2595
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
feat(severity): color warning severity, non-zero exit when issue != default severity #2595
Conversation
Hey, thank you for opening your first Pull Request ! |
@@ -29,6 +29,7 @@ type Output struct { | |||
Color string | |||
PrintIssuedLine bool `mapstructure:"print-issued-lines"` | |||
PrintLinterName bool `mapstructure:"print-linter-name"` | |||
PrintSeverity bool `mapstructure:"print-severity"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like this print-severity
field in general, but I want to try to maintain older behaviour if possible. I was thinking of adding something like exit-non-zero-severity
to replace the default severity field usage in this PR. Still need to look at this codebase more to figure out how that's implemented.
if p.printLinterName { | ||
text += fmt.Sprintf(" (%s)", i.FromLinter) | ||
} | ||
if p.printSeverity { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only time I really found this useful is if coloring is turned off, so I'm happy to remove it / restructure this.
@@ -56,10 +58,18 @@ func (p *Text) Print(ctx context.Context, issues []result.Issue) error { | |||
} | |||
|
|||
func (p Text) printIssue(i *result.Issue) { | |||
text := p.SprintfColored(color.FgRed, "%s", strings.TrimSpace(i.Text)) | |||
issueColor := color.FgRed | |||
if i.Severity == "warning" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure this isn't great because this seems to attach to specific severity levels -- which I don't see well defined in this repository. Let me know if we want to define coloring a different way, if at all. I like this, personally.
Hello, I have a problem with your PR because it contains 2 topics:
It's 2 different topics, so it means 2 different PRs/issues. Regarding the exit code, as far as I remember, discussions have already taken place on this subject and overall the decision was made not to correlate severity and exit code. Related to: |
Hi, I did some related work in the past, so cannot really review this code as I am biased. I have tested both (actually one) features on myself and the company I was working for at that moment. I am also not aware of the discussion on exit codes and did my own research. However, I can give a small intro on the topic: Both
What I found after using this on my own flow:
Problems:
IMO, this feature is a bit controversial. I did implement that for myself, I didn't like that it gives a bit more space than needed. And tbh I didn't look for the answers from the community. The support for the idea itself was low at(hat)m, I am not even talking about implementation and support. |
As suggested by my previous comment the PR cannot be merged like this, you have to split your work. I will close the PR. |
What this PR does: This PR adds a new
print-severity
field that toggles printing severity information on thetext
printer. By default, we now change the color of the error if the severity is set towarning
. Also changed is when issues are discovered, we only return a non-zero exit code if it's equal to the default severity (e.g.error
). If it's a non-default severity, e.g.warning
, we return a zero exit code.Imporant Note: I know this is super opinionated, so let me know if there's a different direction we want to take this. I'm not attached to this implementation at all! Also happy to split this into multiple PRs 😄