Skip to content

Commit a5e5d78

Browse files
authored
chore: enable a few revive rules (#1330)
1 parent dbcfd66 commit a5e5d78

13 files changed

+19
-23
lines changed

cli/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ var (
3333

3434
func fail(err string) {
3535
fmt.Fprintln(os.Stderr, err)
36-
os.Exit(1)
36+
os.Exit(1) //revive:disable-line:deep-exit
3737
}
3838

3939
// RunRevive runs the CLI for revive.
@@ -44,7 +44,7 @@ func RunRevive(extraRules ...revivelib.ExtraRule) {
4444

4545
if versionFlag {
4646
fmt.Print(getVersion(builtBy, date, commit, version))
47-
os.Exit(0)
47+
return
4848
}
4949

5050
conf, err := config.GetConfig(configPath)
@@ -87,7 +87,7 @@ func RunRevive(extraRules ...revivelib.ExtraRule) {
8787
fmt.Println(output)
8888
}
8989

90-
os.Exit(exitCode)
90+
os.Exit(exitCode) //revive:disable-line:deep-exit
9191
}
9292

9393
var (

internal/typeparams/typeparams_go117.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build !go1.18
2-
// +build !go1.18
32

43
package typeparams
54

internal/typeparams/typeparams_go118.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build go1.18
2-
// +build go1.18
32

43
package typeparams
54

revive.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ warningCode = 1
99

1010
[rule.bare-return]
1111
[rule.blank-imports]
12+
[rule.comment-spacings]
13+
[rule.constant-logical-expr]
1214
[rule.context-as-argument]
1315
[rule.context-keys-type]
16+
[rule.deep-exit]
1417
[rule.dot-imports]
1518
[rule.empty-block]
1619
[rule.empty-lines]
@@ -26,6 +29,7 @@ warningCode = 1
2629
[rule.filename-format]
2730
# Override the default pattern to forbid .go files with uppercase letters and dashes.
2831
arguments=["^[_a-z][_a-z0-9]*\\.go$"]
32+
[rule.identical-branches]
2933
[rule.increment-decrement]
3034
[rule.indent-error-flow]
3135
[rule.line-length-limit]
@@ -34,12 +38,15 @@ warningCode = 1
3438
[rule.range]
3539
[rule.receiver-naming]
3640
[rule.redefines-builtin-id]
41+
[rule.redundant-build-tag]
3742
[rule.superfluous-else]
3843
[rule.time-naming]
3944
[rule.unexported-naming]
4045
[rule.unexported-return]
46+
[rule.unnecessary-stmt]
4147
[rule.unreachable-code]
4248
[rule.unused-parameter]
49+
[rule.unused-receiver]
4350
[rule.useless-break]
4451
[rule.use-any]
4552
[rule.var-declaration]

rule/bool_literal_in_expr.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type lintBoolLiteral struct {
3636
}
3737

3838
func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor {
39-
switch n := node.(type) {
40-
case *ast.BinaryExpr:
39+
if n, ok := node.(*ast.BinaryExpr); ok {
4140
if !isBoolOp(n.Op) {
4241
return w
4342
}

rule/confusing_naming.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ func extractFromStarExpr(expr *ast.StarExpr) string {
159159
}
160160

161161
func extractFromIndexExpr(expr *ast.IndexExpr) string {
162-
switch v := expr.X.(type) {
163-
case *ast.Ident:
162+
if v, ok := expr.X.(*ast.Ident); ok {
164163
return v.Name
165164
}
166165
return defaultStructName

rule/constant_logical_expr.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ type lintConstantLogicalExpr struct {
3535
}
3636

3737
func (w *lintConstantLogicalExpr) Visit(node ast.Node) ast.Visitor {
38-
switch n := node.(type) {
39-
case *ast.BinaryExpr:
38+
if n, ok := node.(*ast.BinaryExpr); ok {
4039
if !w.isOperatorWithLogicalResult(n.Op) {
4140
return w
4241
}

rule/context_keys_type.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ type lintContextKeyTypes struct {
4242
}
4343

4444
func (w lintContextKeyTypes) Visit(n ast.Node) ast.Visitor {
45-
switch n := n.(type) {
46-
case *ast.CallExpr:
45+
if n, ok := n.(*ast.CallExpr); ok {
4746
checkContextKeyType(w, n)
4847
}
4948

rule/enforce_repeated_arg_type_style.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,7 @@ func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, _ lint.Argument
111111

112112
astFile := file.AST
113113
ast.Inspect(astFile, func(n ast.Node) bool {
114-
switch fn := n.(type) {
115-
case *ast.FuncDecl:
114+
if fn, ok := n.(*ast.FuncDecl); ok {
116115
switch r.funcArgStyle {
117116
case enforceRepeatedArgTypeStyleTypeFull:
118117
if fn.Type.Params != nil {

rule/if_return.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ type lintElseError struct {
3636
}
3737

3838
func (w *lintElseError) Visit(node ast.Node) ast.Visitor {
39-
switch v := node.(type) {
40-
case *ast.BlockStmt:
39+
if v, ok := node.(*ast.BlockStmt); ok {
4140
for i := range len(v.List) - 1 {
4241
// if var := whatever; var != nil { return var }
4342
s, ok := v.List[i].(*ast.IfStmt)

rule/max_public_structs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,7 @@ type lintMaxPublicStructs struct {
8181
}
8282

8383
func (w *lintMaxPublicStructs) Visit(n ast.Node) ast.Visitor {
84-
switch v := n.(type) {
85-
case *ast.TypeSpec:
84+
if v, ok := n.(*ast.TypeSpec); ok {
8685
name := v.Name.Name
8786
first := string(name[0])
8887
if strings.ToUpper(first) == first {

rule/struct_tag.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ type lintStructTagRule struct {
136136
}
137137

138138
func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
139-
switch n := node.(type) {
140-
case *ast.StructType:
139+
if n, ok := node.(*ast.StructType); ok {
141140
isEmptyStruct := n.Fields == nil || n.Fields.NumFields() < 1
142141
if isEmptyStruct {
143142
return nil // skip empty structs

rule/unhandled_error.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ type lintUnhandledErrors struct {
7373
// Visit looks for statements that are function calls.
7474
// If the called function returns a value of type error a failure will be created.
7575
func (w *lintUnhandledErrors) Visit(node ast.Node) ast.Visitor {
76-
switch n := node.(type) {
77-
case *ast.ExprStmt:
76+
if n, ok := node.(*ast.ExprStmt); ok {
7877
fCall, ok := n.X.(*ast.CallExpr)
7978
if !ok {
8079
return nil // not a function call

0 commit comments

Comments
 (0)