-
Notifications
You must be signed in to change notification settings - Fork 359
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
Add --minimum-failure-severity
flag, sets minimum issue severity for non-zero exit
#1654
Conversation
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.
Thank you for your contributions. Left some comments.
By the way, the naming may have room for improvement. The --minimum-seveirty
is the same as present in tfsec, but tfsec filters the issues. This difference in behavior may confuse users.
We have several options:
- Filter issues like tfsec
- Rename (e.g. Ben's suggestion is
--min-failure
, any other good name would be nice) - Assume no confusion and adopt
--minimum-severity
What do you think?
cmd/inspect.go
Outdated
} | ||
|
||
for _, i := range issues { | ||
if i.Rule.Severity() >= minSeverity { |
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 severity numbers are not intentional and are assigned mechanically, so avoid comparing them.
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.
Well they are defined in order, just arguably backwards, and definitely not the way this code expects:
Error is 0 and Notice is 2.
They're also re-declared which should be resolved:
Lines 24 to 31 in 7b4785d
const ( | |
// ERROR is possible errors | |
ERROR Severity = iota | |
// WARNING doesn't cause problem immediately, but not good | |
WARNING | |
// NOTICE is not important, it's mentioned | |
NOTICE | |
) |
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.
Ah I made a hasty assumption here, my bad! I do think it would make more sense to have them in an order from info to error, which would allow for these kinds of comparisons. For now I've implemented a function to convert them to the values I need, but it of course necessitates changing that method if you were to add new severities... But in general it looks like sweeping changes would be needed to add new severities, since there are switch statements using them all over the codebase.
I also removed the redeclared severity constant and references the SDK everywhere instead. Let me know if this is something that should be saved for another PR 🤪
My thought was https://www.gnu.org/software/bash/manual/html_node/Exit-Status.html |
cmd/inspect.go
Outdated
} | ||
|
||
for _, i := range issues { | ||
if i.Rule.Severity() >= minSeverity { |
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.
Well they are defined in order, just arguably backwards, and definitely not the way this code expects:
Error is 0 and Notice is 2.
They're also re-declared which should be resolved:
Lines 24 to 31 in 7b4785d
const ( | |
// ERROR is possible errors | |
ERROR Severity = iota | |
// WARNING doesn't cause problem immediately, but not good | |
WARNING | |
// NOTICE is not important, it's mentioned | |
NOTICE | |
) |
cmd/inspect.go
Outdated
var minSeverity tflint.Severity | ||
switch strings.ToLower(opts.MinimumSeverity) { | ||
case "warning": | ||
minSeverity = 1 | ||
case "error": | ||
minSeverity = 2 |
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.
This should be handled alongside the severity type, e.g. func NewSeverity(s string) (Severity, error)
. An error would be returned if s
is not a recognized severity. Handling it here is too error prone, e.g. if a new severity is added someone has to find and update this code.
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 guess with the addition of choice
to the struct tag an update is required anyway, but it would still be good to not hardcode this. At a minimum these severity codes should be exported/referenced instead of directly hardcoding the ints.
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.
Like I mentioned above I think adding a new severity would be a task requiring many changes anyway, but I do agree the logic around severity should not be in inspect.go. I the functions which handle the conversion from the string into Severity and into in32 for comparison into the issue.go file. Not sure if this is the best space for it, but that seemed to be the home of severity.
I also removed the redeclaration of severity and changed references to point to the declaration in the SDK.
I went with |
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.
👍
--minimum-failure-severity
flag, sets minimum issue severity for non-zero exit
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.
Nice work on all the refactoring!
Somehow this new flag does not seem to be working as expected in the latest release. If I only have a bunch of warnings, I get return code zero, no matter what I set |
Can you open an issue? There are integration tests against this behavior so it's not obvious how it wouldn't be working. |
Resolves #1556
Add the --minimum-severity option allowing only certain severities to result in a non-zero exit code