-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1854 from reviewdog/exit-code
introduce -fail-level flag and deprecate -fail-on-error
- Loading branch information
Showing
9 changed files
with
242 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package reviewdog | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/reviewdog/reviewdog/proto/rdf" | ||
) | ||
|
||
// FailLevel represents enumeration of available filter modes | ||
type FailLevel int | ||
|
||
const ( | ||
// FailLevelDefault represents default mode, which means users doesn't specify | ||
// fail-level. Basically, it's same as FailLevelNone. | ||
FailLevelDefault FailLevel = iota | ||
// FailLevelNone - Do not fail. | ||
FailLevelNone | ||
// FailLevelAny - Fail with any severity. | ||
FailLevelAny | ||
// FailLevelInfo - Fail with info or above severity. | ||
FailLevelInfo | ||
// FailLevelWarning - Fail with warning or above severity. | ||
FailLevelWarning | ||
// FailLevelError - Fail with error or above severity. | ||
FailLevelError | ||
) | ||
|
||
// String implements the flag.Value interface | ||
func (failLevel *FailLevel) String() string { | ||
names := [...]string{ | ||
"default", | ||
"none", | ||
"any", | ||
"info", | ||
"warning", | ||
"error", | ||
} | ||
if *failLevel < FailLevelDefault || *failLevel > FailLevelError { | ||
return "Unknown failLevel" | ||
} | ||
|
||
return names[*failLevel] | ||
} | ||
|
||
// Set implements the flag.Value interface | ||
func (failLevel *FailLevel) Set(value string) error { | ||
switch value { | ||
case "default", "": | ||
*failLevel = FailLevelDefault | ||
case "none": | ||
*failLevel = FailLevelNone | ||
case "any": | ||
*failLevel = FailLevelAny | ||
case "info": | ||
*failLevel = FailLevelInfo | ||
case "warning": | ||
*failLevel = FailLevelWarning | ||
case "error": | ||
*failLevel = FailLevelError | ||
default: | ||
return fmt.Errorf("invalid failLevel name: %s", value) | ||
} | ||
return nil | ||
} | ||
|
||
// ShouldFail returns true if reviewdog should exit with 1 with given rdf.Severity. | ||
func (failLevel FailLevel) ShouldFail(severity rdf.Severity) bool { | ||
if failLevel == FailLevelDefault || failLevel == FailLevelNone { | ||
return false | ||
} | ||
minSeverity := failLevel.minSeverity() | ||
return minSeverity == rdf.Severity_UNKNOWN_SEVERITY || severity <= minSeverity | ||
} | ||
|
||
func (failLevel FailLevel) minSeverity() rdf.Severity { | ||
switch failLevel { | ||
case FailLevelDefault, FailLevelNone, FailLevelAny: | ||
return rdf.Severity_UNKNOWN_SEVERITY | ||
case FailLevelInfo: | ||
return rdf.Severity_INFO | ||
case FailLevelWarning: | ||
return rdf.Severity_WARNING | ||
case FailLevelError: | ||
return rdf.Severity_ERROR | ||
default: | ||
return rdf.Severity_UNKNOWN_SEVERITY | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package reviewdog | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/reviewdog/reviewdog/proto/rdf" | ||
) | ||
|
||
func TestShouldFail(t *testing.T) { | ||
tests := []struct { | ||
failLevel FailLevel | ||
severity rdf.Severity | ||
want bool | ||
}{ | ||
{ | ||
failLevel: FailLevelDefault, severity: rdf.Severity_ERROR, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelDefault, severity: rdf.Severity_WARNING, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelDefault, severity: rdf.Severity_INFO, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelDefault, severity: rdf.Severity_UNKNOWN_SEVERITY, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelNone, severity: rdf.Severity_ERROR, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelError, severity: rdf.Severity_ERROR, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelError, severity: rdf.Severity_WARNING, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelError, severity: rdf.Severity_INFO, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelError, severity: rdf.Severity_UNKNOWN_SEVERITY, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelWarning, severity: rdf.Severity_ERROR, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelWarning, severity: rdf.Severity_WARNING, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelWarning, severity: rdf.Severity_INFO, want: false, | ||
}, | ||
{ | ||
failLevel: FailLevelWarning, severity: rdf.Severity_UNKNOWN_SEVERITY, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelInfo, severity: rdf.Severity_ERROR, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelInfo, severity: rdf.Severity_WARNING, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelInfo, severity: rdf.Severity_INFO, want: true, | ||
}, | ||
{ | ||
failLevel: FailLevelInfo, severity: rdf.Severity_UNKNOWN_SEVERITY, want: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
if got := tt.failLevel.ShouldFail(tt.severity); got != tt.want { | ||
t.Errorf("FailLevel(%s).ShouldFail(%s) = %v, want %v", tt.failLevel.String(), | ||
tt.severity, got, tt.want) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.