diff --git a/cli/main.go b/cli/main.go index ab5b31d..07e0024 100644 --- a/cli/main.go +++ b/cli/main.go @@ -33,7 +33,7 @@ var ( func fail(err string) { fmt.Fprintln(os.Stderr, err) - os.Exit(1) + os.Exit(1) //revive:disable-line:deep-exit } // RunRevive runs the CLI for revive. @@ -44,7 +44,7 @@ func RunRevive(extraRules ...revivelib.ExtraRule) { if versionFlag { fmt.Print(getVersion(builtBy, date, commit, version)) - os.Exit(0) + return } conf, err := config.GetConfig(configPath) @@ -87,7 +87,7 @@ func RunRevive(extraRules ...revivelib.ExtraRule) { fmt.Println(output) } - os.Exit(exitCode) + os.Exit(exitCode) //revive:disable-line:deep-exit } var ( diff --git a/internal/typeparams/typeparams_go117.go b/internal/typeparams/typeparams_go117.go index 913a731..82ffaa4 100644 --- a/internal/typeparams/typeparams_go117.go +++ b/internal/typeparams/typeparams_go117.go @@ -1,5 +1,4 @@ //go:build !go1.18 -// +build !go1.18 package typeparams diff --git a/internal/typeparams/typeparams_go118.go b/internal/typeparams/typeparams_go118.go index 0f7fd88..d0ae7a1 100644 --- a/internal/typeparams/typeparams_go118.go +++ b/internal/typeparams/typeparams_go118.go @@ -1,5 +1,4 @@ //go:build go1.18 -// +build go1.18 package typeparams diff --git a/revive.toml b/revive.toml index 68085da..5e03ad7 100644 --- a/revive.toml +++ b/revive.toml @@ -9,8 +9,11 @@ warningCode = 1 [rule.bare-return] [rule.blank-imports] +[rule.comment-spacings] +[rule.constant-logical-expr] [rule.context-as-argument] [rule.context-keys-type] +[rule.deep-exit] [rule.dot-imports] [rule.empty-block] [rule.empty-lines] @@ -26,6 +29,7 @@ warningCode = 1 [rule.filename-format] # Override the default pattern to forbid .go files with uppercase letters and dashes. arguments=["^[_a-z][_a-z0-9]*\\.go$"] +[rule.identical-branches] [rule.increment-decrement] [rule.indent-error-flow] [rule.line-length-limit] @@ -34,12 +38,15 @@ warningCode = 1 [rule.range] [rule.receiver-naming] [rule.redefines-builtin-id] +[rule.redundant-build-tag] [rule.superfluous-else] [rule.time-naming] [rule.unexported-naming] [rule.unexported-return] +[rule.unnecessary-stmt] [rule.unreachable-code] [rule.unused-parameter] +[rule.unused-receiver] [rule.useless-break] [rule.use-any] [rule.var-declaration] diff --git a/rule/bool_literal_in_expr.go b/rule/bool_literal_in_expr.go index dd1e9be..c510ecc 100644 --- a/rule/bool_literal_in_expr.go +++ b/rule/bool_literal_in_expr.go @@ -36,8 +36,7 @@ type lintBoolLiteral struct { } func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.BinaryExpr: + if n, ok := node.(*ast.BinaryExpr); ok { if !isBoolOp(n.Op) { return w } diff --git a/rule/confusing_naming.go b/rule/confusing_naming.go index 8a8ea13..53a5997 100644 --- a/rule/confusing_naming.go +++ b/rule/confusing_naming.go @@ -159,8 +159,7 @@ func extractFromStarExpr(expr *ast.StarExpr) string { } func extractFromIndexExpr(expr *ast.IndexExpr) string { - switch v := expr.X.(type) { - case *ast.Ident: + if v, ok := expr.X.(*ast.Ident); ok { return v.Name } return defaultStructName diff --git a/rule/constant_logical_expr.go b/rule/constant_logical_expr.go index cb5dd74..38a5f3e 100644 --- a/rule/constant_logical_expr.go +++ b/rule/constant_logical_expr.go @@ -35,8 +35,7 @@ type lintConstantLogicalExpr struct { } func (w *lintConstantLogicalExpr) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.BinaryExpr: + if n, ok := node.(*ast.BinaryExpr); ok { if !w.isOperatorWithLogicalResult(n.Op) { return w } diff --git a/rule/context_keys_type.go b/rule/context_keys_type.go index 02e1f9f..398287b 100644 --- a/rule/context_keys_type.go +++ b/rule/context_keys_type.go @@ -42,8 +42,7 @@ type lintContextKeyTypes struct { } func (w lintContextKeyTypes) Visit(n ast.Node) ast.Visitor { - switch n := n.(type) { - case *ast.CallExpr: + if n, ok := n.(*ast.CallExpr); ok { checkContextKeyType(w, n) } diff --git a/rule/enforce_repeated_arg_type_style.go b/rule/enforce_repeated_arg_type_style.go index 8a5d9b3..726ee2c 100644 --- a/rule/enforce_repeated_arg_type_style.go +++ b/rule/enforce_repeated_arg_type_style.go @@ -111,8 +111,7 @@ func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, _ lint.Argument astFile := file.AST ast.Inspect(astFile, func(n ast.Node) bool { - switch fn := n.(type) { - case *ast.FuncDecl: + if fn, ok := n.(*ast.FuncDecl); ok { switch r.funcArgStyle { case enforceRepeatedArgTypeStyleTypeFull: if fn.Type.Params != nil { diff --git a/rule/if_return.go b/rule/if_return.go index d0f581f..62f4eb9 100644 --- a/rule/if_return.go +++ b/rule/if_return.go @@ -36,8 +36,7 @@ type lintElseError struct { } func (w *lintElseError) Visit(node ast.Node) ast.Visitor { - switch v := node.(type) { - case *ast.BlockStmt: + if v, ok := node.(*ast.BlockStmt); ok { for i := range len(v.List) - 1 { // if var := whatever; var != nil { return var } s, ok := v.List[i].(*ast.IfStmt) diff --git a/rule/max_public_structs.go b/rule/max_public_structs.go index f27edd7..c78116d 100644 --- a/rule/max_public_structs.go +++ b/rule/max_public_structs.go @@ -81,8 +81,7 @@ type lintMaxPublicStructs struct { } func (w *lintMaxPublicStructs) Visit(n ast.Node) ast.Visitor { - switch v := n.(type) { - case *ast.TypeSpec: + if v, ok := n.(*ast.TypeSpec); ok { name := v.Name.Name first := string(name[0]) if strings.ToUpper(first) == first { diff --git a/rule/struct_tag.go b/rule/struct_tag.go index 5cfa31c..c886315 100644 --- a/rule/struct_tag.go +++ b/rule/struct_tag.go @@ -136,8 +136,7 @@ type lintStructTagRule struct { } func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.StructType: + if n, ok := node.(*ast.StructType); ok { isEmptyStruct := n.Fields == nil || n.Fields.NumFields() < 1 if isEmptyStruct { return nil // skip empty structs diff --git a/rule/unhandled_error.go b/rule/unhandled_error.go index 6e2fb2d..94e8cd3 100644 --- a/rule/unhandled_error.go +++ b/rule/unhandled_error.go @@ -73,8 +73,7 @@ type lintUnhandledErrors struct { // Visit looks for statements that are function calls. // If the called function returns a value of type error a failure will be created. func (w *lintUnhandledErrors) Visit(node ast.Node) ast.Visitor { - switch n := node.(type) { - case *ast.ExprStmt: + if n, ok := node.(*ast.ExprStmt); ok { fCall, ok := n.X.(*ast.CallExpr) if !ok { return nil // not a function call