Skip to content

Commit

Permalink
Use enum instead of string as issue severity
Browse files Browse the repository at this point in the history
  • Loading branch information
wata727 committed Feb 23, 2022
1 parent 014d05e commit 22f3db6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 12 deletions.
2 changes: 1 addition & 1 deletion helper/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ type dummyRule struct {

func (r *dummyRule) Name() string { return "dummy_rule" }
func (r *dummyRule) Enabled() bool { return true }
func (r *dummyRule) Severity() string { return tflint.ERROR }
func (r *dummyRule) Severity() tflint.Severity { return tflint.ERROR }
func (r *dummyRule) Check(tflint.Runner) error { return nil }

func Test_EmitIssueOnExpr(t *testing.T) {
Expand Down
8 changes: 4 additions & 4 deletions plugin/fromproto/fromproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type RuleObject struct {
Data struct {
Name string
Enabled bool
Severity string
Severity tflint.Severity
Link string
}
}
Expand All @@ -101,7 +101,7 @@ func (r *RuleObject) Name() string { return r.Data.Name }
func (r *RuleObject) Enabled() bool { return r.Data.Enabled }

// Severity returns the severify of the rule
func (r *RuleObject) Severity() string { return r.Data.Severity }
func (r *RuleObject) Severity() tflint.Severity { return r.Data.Severity }

// Link returns the link of the rule documentation if exists
func (r *RuleObject) Link() string { return r.Data.Link }
Expand All @@ -119,7 +119,7 @@ func Rule(rule *proto.EmitIssue_Rule) *RuleObject {
Data: struct {
Name string
Enabled bool
Severity string
Severity tflint.Severity
Link string
}{
Name: rule.Name,
Expand All @@ -131,7 +131,7 @@ func Rule(rule *proto.EmitIssue_Rule) *RuleObject {
}

// Severity converts proto.EmitIssue_Severity to severity
func Severity(severity proto.EmitIssue_Severity) string {
func Severity(severity proto.EmitIssue_Severity) tflint.Severity {
switch severity {
case proto.EmitIssue_SEVERITY_ERROR:
return tflint.ERROR
Expand Down
2 changes: 1 addition & 1 deletion plugin/toproto/toproto.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func Rule(rule tflint.Rule) *proto.EmitIssue_Rule {
}

// Severity converts severity to proto.EmitIssue_Severity
func Severity(severity string) proto.EmitIssue_Severity {
func Severity(severity tflint.Severity) proto.EmitIssue_Severity {
switch severity {
case tflint.ERROR:
return proto.EmitIssue_SEVERITY_ERROR
Expand Down
2 changes: 1 addition & 1 deletion tflint/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ type Rule interface {
Enabled() bool

// Severity indicates the severity of the rule.
Severity() string
Severity() Severity

// Link allows you to add a reference link to the rule.
Link() string
Expand Down
10 changes: 6 additions & 4 deletions tflint/issue.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package tflint

// List of issue severity levels. The rules implemented by a plugin can be set to any severity.
// Severity indicates the severity of the issue.
type Severity int32

const (
// ERROR is possible errors
ERROR = "Error"
ERROR Severity = iota
// WARNING doesn't cause problem immediately, but not good
WARNING = "Warning"
WARNING
// NOTICE is not important, it's mentioned
NOTICE = "Notice"
NOTICE
)
2 changes: 1 addition & 1 deletion tflint/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ type embedDefaultRule struct {

func (r *embedDefaultRule) Name() string { return "" }
func (r *embedDefaultRule) Enabled() bool { return true }
func (r *embedDefaultRule) Severity() string { return ERROR }
func (r *embedDefaultRule) Severity() Severity { return ERROR }
func (r *embedDefaultRule) Check(runner Runner) error { return nil }

0 comments on commit 22f3db6

Please sign in to comment.