-
-
Notifications
You must be signed in to change notification settings - Fork 428
/
fail_level.go
88 lines (79 loc) · 2.14 KB
/
fail_level.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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
}
}