Skip to content

chore: enable a few revive rules #1330

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)
Expand Down Expand Up @@ -87,7 +87,7 @@ func RunRevive(extraRules ...revivelib.ExtraRule) {
fmt.Println(output)
}

os.Exit(exitCode)
os.Exit(exitCode) //revive:disable-line:deep-exit
}

var (
Expand Down
1 change: 0 additions & 1 deletion internal/typeparams/typeparams_go117.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build !go1.18
// +build !go1.18

package typeparams

Expand Down
1 change: 0 additions & 1 deletion internal/typeparams/typeparams_go118.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build go1.18
// +build go1.18

package typeparams

Expand Down
7 changes: 7 additions & 0 deletions revive.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand All @@ -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]
Expand Down
3 changes: 1 addition & 2 deletions rule/bool_literal_in_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions rule/confusing_naming.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions rule/constant_logical_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions rule/context_keys_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions rule/enforce_repeated_arg_type_style.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions rule/if_return.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 1 addition & 2 deletions rule/max_public_structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions rule/struct_tag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions rule/unhandled_error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down