mirror of
https://github.com/mgechev/revive.git
synced 2025-11-25 22:12:38 +02:00
chore: enable a few revive rules (#1330)
This commit is contained in:
@@ -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 (
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build !go1.18
|
||||
// +build !go1.18
|
||||
|
||||
package typeparams
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build go1.18
|
||||
// +build go1.18
|
||||
|
||||
package typeparams
|
||||
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user