Skip to content

Commit

Permalink
cleanup rules, remove error from return signature
Browse files Browse the repository at this point in the history
  • Loading branch information
mfederowicz committed Dec 8, 2024
1 parent ea832f4 commit d6f17ff
Show file tree
Hide file tree
Showing 87 changed files with 233 additions and 230 deletions.
6 changes: 2 additions & 4 deletions lint/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,8 @@ func (f *File) lint(rules []Rule, config Config, failures chan Failure) error {
if ruleConfig.MustExclude(f.Name) {
continue
}
currentFailures, err := currentRule.Apply(f, ruleConfig.Arguments)
if err != nil {
return err
}
currentFailures := currentRule.Apply(f, ruleConfig.Arguments)

for idx, failure := range currentFailures {
if failure.IsInternal() {
return errors.New(failure.Failure)
Expand Down
2 changes: 1 addition & 1 deletion lint/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type DisabledInterval struct {
// Rule defines an abstract rule interface
type Rule interface {
Name() string
Apply(*File, Arguments) ([]Failure, error)
Apply(*File, Arguments) ([]Failure)
}

// ToFailurePosition returns the failure position.
Expand Down
4 changes: 2 additions & 2 deletions revivelib/core_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ func (*mockRule) Name() string {
return "mock-rule"
}

func (*mockRule) Apply(_ *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
return nil, nil
func (*mockRule) Apply(_ *lint.File, _ lint.Arguments) []lint.Failure {
return nil
}

func getMockRevive(t *testing.T) *Revive {
Expand Down
4 changes: 2 additions & 2 deletions revivelib/core_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ func (r *mockRule) Name() string {
return "mock-rule"
}

func (r *mockRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
return nil, nil
func (r *mockRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
return nil
}

func getMockRevive(t *testing.T) *revivelib.Revive {
Expand Down
6 changes: 3 additions & 3 deletions rule/argument_limit.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (r *ArgumentsLimitRule) configure(arguments lint.Arguments) error {
}

// Apply applies the rule to given file.
func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

if configureErr != nil {
return nil, configureErr
return []lint.Failure{lint.NewInternalFailure(configureErr.Error())}
}

var failures []lint.Failure
Expand All @@ -65,7 +65,7 @@ func (r *ArgumentsLimitRule) Apply(file *lint.File, arguments lint.Arguments) ([
})
}

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
4 changes: 2 additions & 2 deletions rule/atomic.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type AtomicRule struct{}

// Apply applies the rule to given file.
func (*AtomicRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*AtomicRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
walker := atomic{
pkgTypesInfo: file.Pkg.TypesInfo(),
Expand All @@ -23,7 +23,7 @@ func (*AtomicRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, err

ast.Walk(walker, file.AST)

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
6 changes: 3 additions & 3 deletions rule/banned_characters.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func (r *BannedCharsRule) configure(arguments lint.Arguments) error {
}

// Apply applied the rule to the given file.
func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

if configureErr != nil {
return nil, configureErr
return []lint.Failure{lint.NewInternalFailure(configureErr.Error())}
}

var failures []lint.Failure
Expand All @@ -54,7 +54,7 @@ func (r *BannedCharsRule) Apply(file *lint.File, arguments lint.Arguments) ([]li
}

ast.Walk(w, file.AST)
return failures, nil
return failures
}

// Name returns the rule name
Expand Down
4 changes: 2 additions & 2 deletions rule/bare_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type BareReturnRule struct{}

// Apply applies the rule to given file.
func (*BareReturnRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*BareReturnRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand All @@ -19,7 +19,7 @@ func (*BareReturnRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure,

w := lintBareReturnRule{onFailure: onFailure}
ast.Walk(w, file.AST)
return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
6 changes: 3 additions & 3 deletions rule/blank_imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ func (*BlankImportsRule) Name() string {
}

// Apply applies the rule to given file.
func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
if file.Pkg.IsMain() || file.IsTest() {
return nil, nil
return nil
}

const (
Expand Down Expand Up @@ -59,7 +59,7 @@ func (r *BlankImportsRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Fail
}
}

return failures, nil
return failures
}

func (*BlankImportsRule) fileHasValidEmbedComment(fileAst *ast.File) bool {
Expand Down
4 changes: 2 additions & 2 deletions rule/bool_literal_in_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type BoolLiteralRule struct{}

// Apply applies the rule to given file.
func (*BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand All @@ -22,7 +22,7 @@ func (*BoolLiteralRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure
w := &lintBoolLiteral{astFile, onFailure}
ast.Walk(w, astFile)

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
4 changes: 2 additions & 2 deletions rule/call_to_gc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type CallToGCRule struct{}

// Apply applies the rule to given file.
func (*CallToGCRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*CallToGCRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
onFailure := func(failure lint.Failure) {
failures = append(failures, failure)
Expand All @@ -23,7 +23,7 @@ func (*CallToGCRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, e
w := lintCallToGC{onFailure, gcTriggeringFunctions}
ast.Walk(w, file.AST)

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
6 changes: 3 additions & 3 deletions rule/cognitive_complexity.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func (r *CognitiveComplexityRule) configure(arguments lint.Arguments) error {
}

// Apply applies the rule to given file.
func (r *CognitiveComplexityRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
func (r *CognitiveComplexityRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

if configureErr != nil {
return nil, configureErr
return []lint.Failure{lint.NewInternalFailure(configureErr.Error())}
}

var failures []lint.Failure
Expand All @@ -55,7 +55,7 @@ func (r *CognitiveComplexityRule) Apply(file *lint.File, arguments lint.Argument

linter.lintCognitiveComplexity()

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
6 changes: 3 additions & 3 deletions rule/comment_spacings.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ func (r *CommentSpacingsRule) configure(arguments lint.Arguments) error {
}

// Apply the rule.
func (r *CommentSpacingsRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
func (r *CommentSpacingsRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

if configureErr != nil {
return nil, configureErr
return []lint.Failure{lint.NewInternalFailure(configureErr.Error())}
}

var failures []lint.Failure
Expand Down Expand Up @@ -69,7 +69,7 @@ func (r *CommentSpacingsRule) Apply(file *lint.File, arguments lint.Arguments) (
})
}
}
return failures, nil
return failures
}

// Name yields this rule name.
Expand Down
8 changes: 4 additions & 4 deletions rule/comments_density.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ func (r *CommentsDensityRule) configure(arguments lint.Arguments) error {
}

// Apply applies the rule to given file.
func (r *CommentsDensityRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
func (r *CommentsDensityRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

if configureErr != nil {
return nil, configureErr
return []lint.Failure{lint.NewInternalFailure(configureErr.Error())}
}

commentsLines := countDocLines(file.AST.Comments)
Expand All @@ -53,10 +53,10 @@ func (r *CommentsDensityRule) Apply(file *lint.File, arguments lint.Arguments) (
Failure: fmt.Sprintf("the file has a comment density of %2.f%% (%d comment lines for %d code lines) but expected a minimum of %d%%",
density, commentsLines, statementsCount, r.minimumCommentsDensity),
},
}, nil
}
}

return nil, nil
return nil
}

// Name returns the rule name.
Expand Down
4 changes: 2 additions & 2 deletions rule/confusing_naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ var allPkgs = packages{pkgs: make([]pkgMethods, 1)}
type ConfusingNamingRule struct{}

// Apply applies the rule to given file.
func (*ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure
fileAst := file.AST
pkgm := allPkgs.methodNames(file.Pkg)
Expand All @@ -61,7 +61,7 @@ func (*ConfusingNamingRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Fai

ast.Walk(&walker, fileAst)

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
4 changes: 2 additions & 2 deletions rule/confusing_results.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
type ConfusingResultsRule struct{}

// Apply applies the rule to given file.
func (*ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

for _, decl := range file.AST.Decls {
Expand Down Expand Up @@ -45,7 +45,7 @@ func (*ConfusingResultsRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Fa
}
}

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
4 changes: 2 additions & 2 deletions rule/constant_logical_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type ConstantLogicalExprRule struct{}

// Apply applies the rule to given file.
func (*ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

onFailure := func(failure lint.Failure) {
Expand All @@ -21,7 +21,7 @@ func (*ConstantLogicalExprRule) Apply(file *lint.File, _ lint.Arguments) ([]lint
astFile := file.AST
w := &lintConstantLogicalExpr{astFile, onFailure}
ast.Walk(w, astFile)
return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
6 changes: 3 additions & 3 deletions rule/context_as_argument.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ type ContextAsArgumentRule struct {
}

// Apply applies the rule to given file.
func (r *ContextAsArgumentRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
func (r *ContextAsArgumentRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

if configureErr != nil {
return nil, configureErr
return []lint.Failure{lint.NewInternalFailure(configureErr.Error())}
}

var failures []lint.Failure
Expand Down Expand Up @@ -56,7 +56,7 @@ func (r *ContextAsArgumentRule) Apply(file *lint.File, arguments lint.Arguments)
}
}

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
4 changes: 2 additions & 2 deletions rule/context_keys_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type ContextKeysType struct{}

// Apply applies the rule to given file.
func (*ContextKeysType) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (*ContextKeysType) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
var failures []lint.Failure

fileAst := file.AST
Expand All @@ -27,7 +27,7 @@ func (*ContextKeysType) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure
file.Pkg.TypeCheck()
ast.Walk(walker, fileAst)

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
6 changes: 3 additions & 3 deletions rule/cyclomatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ func (r *CyclomaticRule) configure(arguments lint.Arguments) error {
}

// Apply applies the rule to given file.
func (r *CyclomaticRule) Apply(file *lint.File, arguments lint.Arguments) ([]lint.Failure, error) {
func (r *CyclomaticRule) Apply(file *lint.File, arguments lint.Arguments) []lint.Failure {
var configureErr error
r.configureOnce.Do(func() { configureErr = r.configure(arguments) })

if configureErr != nil {
return nil, configureErr
return []lint.Failure{lint.NewInternalFailure(configureErr.Error())}
}

var failures []lint.Failure
Expand All @@ -62,7 +62,7 @@ func (r *CyclomaticRule) Apply(file *lint.File, arguments lint.Arguments) ([]lin
}
}

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
4 changes: 2 additions & 2 deletions rule/datarace.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type DataRaceRule struct{}

// Apply applies the rule to given file.
func (r *DataRaceRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure, error) {
func (r *DataRaceRule) Apply(file *lint.File, _ lint.Arguments) []lint.Failure {
isGo122 := file.Pkg.IsAtLeastGo122()
var failures []lint.Failure
for _, decl := range file.AST.Decls {
Expand Down Expand Up @@ -41,7 +41,7 @@ func (r *DataRaceRule) Apply(file *lint.File, _ lint.Arguments) ([]lint.Failure,
ast.Walk(fl, funcDecl.Body)
}

return failures, nil
return failures
}

// Name returns the rule name.
Expand Down
Loading

0 comments on commit d6f17ff

Please sign in to comment.