Skip to content

Commit

Permalink
Add type FailureCategory; add comments for constants
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandear committed Jan 6, 2025
1 parent 9805dde commit 5a0c2cc
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
65 changes: 44 additions & 21 deletions lint/failure.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,52 @@ import (
)

const (
FailureCategoryArgOrder = "arg-order"
FailureCategoryBadPractice = "bad practice"
FailureCategoryCodeStyle = "code-style"
FailureCategoryComments = "comments"
FailureCategoryComplexity = "complexity"
FailureCategoryContent = "content"
FailureCategoryErrors = "errors"
FailureCategoryImports = "imports"
FailureCategoryLogic = "logic"
FailureCategoryMaintenance = "maintenance"
FailureCategoryNaming = "naming"
FailureCategoryOptimization = "optimization"
FailureCategoryStyle = "style"
FailureCategoryTime = "time"
FailureCategoryTypeInference = "type-inference"
FailureCategoryUnaryOp = "unary-op"
FailureCategoryUnexportedTypeInAPI = "unexported-type-in-api"
FailureCategoryZeroValue = "zero-value"
// FailureCategoryArgOrder indicates argument order issues.
FailureCategoryArgOrder FailureCategory = "arg-order"
// FailureCategoryBadPractice indicates bad practice issues.
FailureCategoryBadPractice FailureCategory = "bad practice"
// FailureCategoryCodeStyle indicates code style issues.
FailureCategoryCodeStyle FailureCategory = "code-style"
// FailureCategoryComments indicates comment issues.
FailureCategoryComments FailureCategory = "comments"
// FailureCategoryComplexity indicates complexity issues.
FailureCategoryComplexity FailureCategory = "complexity"
// FailureCategoryContent indicates content issues.
FailureCategoryContent FailureCategory = "content"
// FailureCategoryErrors indicates error handling issues.
FailureCategoryErrors FailureCategory = "errors"
// FailureCategoryImports indicates import issues.
FailureCategoryImports FailureCategory = "imports"
// FailureCategoryLogic indicates logic issues.
FailureCategoryLogic FailureCategory = "logic"
// FailureCategoryMaintenance indicates maintenance issues.
FailureCategoryMaintenance FailureCategory = "maintenance"
// FailureCategoryNaming indicates naming issues.
FailureCategoryNaming FailureCategory = "naming"
// FailureCategoryOptimization indicates optimization issues.
FailureCategoryOptimization FailureCategory = "optimization"
// FailureCategoryStyle indicates style issues.
FailureCategoryStyle FailureCategory = "style"
// FailureCategoryTime indicates time-related issues.
FailureCategoryTime FailureCategory = "time"
// FailureCategoryTypeInference indicates type inference issues.
FailureCategoryTypeInference FailureCategory = "type-inference"
// FailureCategoryUnaryOp indicates unary operation issues.
FailureCategoryUnaryOp FailureCategory = "unary-op"
// FailureCategoryUnexportedTypeInAPI indicates unexported type in API issues.
FailureCategoryUnexportedTypeInAPI FailureCategory = "unexported-type-in-api"
// FailureCategoryZeroValue indicates zero value issues.
FailureCategoryZeroValue FailureCategory = "zero-value"

failureCategoryInternal = "REVIVE_INTERNAL"
failureCategoryValidity = "validity"
// failureCategoryInternal indicates internal failures.
failureCategoryInternal FailureCategory = "REVIVE_INTERNAL"
// failureCategoryValidity indicates validity issues.
failureCategoryValidity FailureCategory = "validity"
)

// FailureCategory is the type for the failure categories.
type FailureCategory string

const (
// SeverityWarning declares failures of type warning
SeverityWarning = "warning"
Expand All @@ -49,7 +72,7 @@ type FailurePosition struct {
type Failure struct {
Failure string
RuleName string
Category string
Category FailureCategory
Position FailurePosition
Node ast.Node `json:"-"`
Confidence float64
Expand Down
2 changes: 1 addition & 1 deletion rule/bool_literal_in_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor {
return w
}

func (w lintBoolLiteral) addFailure(node ast.Node, msg, cat string) {
func (w lintBoolLiteral) addFailure(node ast.Node, msg string, cat lint.FailureCategory) {
w.onFailure(lint.Failure{
Confidence: 1,
Node: node,
Expand Down
2 changes: 1 addition & 1 deletion rule/defer.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (w lintDeferRule) visitSubtree(n ast.Node, inADefer, inALoop, inAFuncLit bo
ast.Walk(nw, n)
}

func (w lintDeferRule) newFailure(msg string, node ast.Node, confidence float64, cat, subcase string) {
func (w lintDeferRule) newFailure(msg string, node ast.Node, confidence float64, cat lint.FailureCategory, subcase string) {
if !w.allow[subcase] {
return
}
Expand Down

0 comments on commit 5a0c2cc

Please sign in to comment.