Skip to content

Commit

Permalink
feat: default rules severity adjustments (#95)
Browse files Browse the repository at this point in the history
fixes #93

This PR updates the default severity of all the rules based on the
convention.

It also refactor how default rules are added by checking if the rule is
set to SeverityOff
  • Loading branch information
0xtekgrinder authored Oct 17, 2024
1 parent 798dc04 commit 6baa00a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 22 deletions.
20 changes: 7 additions & 13 deletions internal/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,19 +79,13 @@ func (e *Engine) applyRules(rules map[string]tt.ConfigRule) {
}

func (e *Engine) registerDefaultRules() {
e.rules["golangci-lint"] = allRuleConstructors["golangci-lint"]()
e.rules["deprecated-function"] = allRuleConstructors["deprecated-function"]()
e.rules["early-return-opportunity"] = allRuleConstructors["early-return-opportunity"]()
e.rules["simplify-slice-range"] = allRuleConstructors["simplify-slice-range"]()
e.rules["unnecessary-type-conversion"] = allRuleConstructors["unnecessary-type-conversion"]()
e.rules["loop-allocation"] = allRuleConstructors["loop-allocation"]()
e.rules["emit-format"] = allRuleConstructors["emit-format"]()
e.rules["cycle-detection"] = allRuleConstructors["cycle-detection"]()
e.rules["unused-package"] = allRuleConstructors["unused-package"]()
e.rules["repeated-regex-compilation"] = allRuleConstructors["repeated-regex-compilation"]()
e.rules["useless-break"] = allRuleConstructors["useless-break"]()
e.rules["defer-issues"] = allRuleConstructors["defer-issues"]()
e.rules["gno-mod-tidy"] = allRuleConstructors["gno-mod-tidy"]()
// iterate over allRuleConstructors and add them to the rules map if severity is not off
for key, newRuleCstr := range allRuleConstructors {
newRule := newRuleCstr()
if newRule.Severity() != tt.SeverityOff {
e.rules[key] = newRule
}
}
}

func (e *Engine) findRule(name string) LintRule {
Expand Down
18 changes: 9 additions & 9 deletions internal/rule_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type GolangciLintRule struct {

func NewGolangciLintRule() LintRule {
return &GolangciLintRule{
severity: tt.SeverityError,
severity: tt.SeverityWarning,
}
}

Expand Down Expand Up @@ -111,7 +111,7 @@ type UnnecessaryConversionRule struct {

func NewUnnecessaryConversionRule() LintRule {
return &UnnecessaryConversionRule{
severity: tt.SeverityError,
severity: tt.SeverityWarning,
}
}

Expand All @@ -137,7 +137,7 @@ type LoopAllocationRule struct {

func NewLoopAllocationRule() LintRule {
return &LoopAllocationRule{
severity: tt.SeverityError,
severity: tt.SeverityWarning,
}
}

Expand All @@ -163,7 +163,7 @@ type DetectCycleRule struct {

func NewDetectCycleRule() LintRule {
return &DetectCycleRule{
severity: tt.SeverityError,
severity: tt.SeverityError, // TODO
}
}

Expand All @@ -189,7 +189,7 @@ type EmitFormatRule struct {

func NewEmitFormatRule() LintRule {
return &EmitFormatRule{
severity: tt.SeverityError,
severity: tt.SeverityInfo,
}
}

Expand Down Expand Up @@ -267,7 +267,7 @@ type EarlyReturnOpportunityRule struct {

func NewEarlyReturnOpportunityRule() LintRule {
return &EarlyReturnOpportunityRule{
severity: tt.SeverityError,
severity: tt.SeverityInfo,
}
}

Expand All @@ -293,7 +293,7 @@ type DeferRule struct {

func NewDeferRule() LintRule {
return &DeferRule{
severity: tt.SeverityError,
severity: tt.SeverityWarning,
}
}

Expand Down Expand Up @@ -348,7 +348,7 @@ type RepeatedRegexCompilationRule struct {

func NewRepeatedRegexCompilationRule() LintRule {
return &RepeatedRegexCompilationRule{
severity: tt.SeverityError,
severity: tt.SeverityWarning,
}
}

Expand Down Expand Up @@ -407,7 +407,7 @@ type GnoSpecificRule struct {

func NewGnoSpecificRule() LintRule {
return &GnoSpecificRule{
severity: tt.SeverityError,
severity: tt.SeverityWarning,
}
}

Expand Down

0 comments on commit 6baa00a

Please sign in to comment.