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) {
|
func fail(err string) {
|
||||||
fmt.Fprintln(os.Stderr, err)
|
fmt.Fprintln(os.Stderr, err)
|
||||||
os.Exit(1)
|
os.Exit(1) //revive:disable-line:deep-exit
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunRevive runs the CLI for revive.
|
// RunRevive runs the CLI for revive.
|
||||||
@@ -44,7 +44,7 @@ func RunRevive(extraRules ...revivelib.ExtraRule) {
|
|||||||
|
|
||||||
if versionFlag {
|
if versionFlag {
|
||||||
fmt.Print(getVersion(builtBy, date, commit, version))
|
fmt.Print(getVersion(builtBy, date, commit, version))
|
||||||
os.Exit(0)
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
conf, err := config.GetConfig(configPath)
|
conf, err := config.GetConfig(configPath)
|
||||||
@@ -87,7 +87,7 @@ func RunRevive(extraRules ...revivelib.ExtraRule) {
|
|||||||
fmt.Println(output)
|
fmt.Println(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
os.Exit(exitCode)
|
os.Exit(exitCode) //revive:disable-line:deep-exit
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build !go1.18
|
//go:build !go1.18
|
||||||
// +build !go1.18
|
|
||||||
|
|
||||||
package typeparams
|
package typeparams
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
//go:build go1.18
|
//go:build go1.18
|
||||||
// +build go1.18
|
|
||||||
|
|
||||||
package typeparams
|
package typeparams
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ warningCode = 1
|
|||||||
|
|
||||||
[rule.bare-return]
|
[rule.bare-return]
|
||||||
[rule.blank-imports]
|
[rule.blank-imports]
|
||||||
|
[rule.comment-spacings]
|
||||||
|
[rule.constant-logical-expr]
|
||||||
[rule.context-as-argument]
|
[rule.context-as-argument]
|
||||||
[rule.context-keys-type]
|
[rule.context-keys-type]
|
||||||
|
[rule.deep-exit]
|
||||||
[rule.dot-imports]
|
[rule.dot-imports]
|
||||||
[rule.empty-block]
|
[rule.empty-block]
|
||||||
[rule.empty-lines]
|
[rule.empty-lines]
|
||||||
@@ -26,6 +29,7 @@ warningCode = 1
|
|||||||
[rule.filename-format]
|
[rule.filename-format]
|
||||||
# Override the default pattern to forbid .go files with uppercase letters and dashes.
|
# Override the default pattern to forbid .go files with uppercase letters and dashes.
|
||||||
arguments=["^[_a-z][_a-z0-9]*\\.go$"]
|
arguments=["^[_a-z][_a-z0-9]*\\.go$"]
|
||||||
|
[rule.identical-branches]
|
||||||
[rule.increment-decrement]
|
[rule.increment-decrement]
|
||||||
[rule.indent-error-flow]
|
[rule.indent-error-flow]
|
||||||
[rule.line-length-limit]
|
[rule.line-length-limit]
|
||||||
@@ -34,12 +38,15 @@ warningCode = 1
|
|||||||
[rule.range]
|
[rule.range]
|
||||||
[rule.receiver-naming]
|
[rule.receiver-naming]
|
||||||
[rule.redefines-builtin-id]
|
[rule.redefines-builtin-id]
|
||||||
|
[rule.redundant-build-tag]
|
||||||
[rule.superfluous-else]
|
[rule.superfluous-else]
|
||||||
[rule.time-naming]
|
[rule.time-naming]
|
||||||
[rule.unexported-naming]
|
[rule.unexported-naming]
|
||||||
[rule.unexported-return]
|
[rule.unexported-return]
|
||||||
|
[rule.unnecessary-stmt]
|
||||||
[rule.unreachable-code]
|
[rule.unreachable-code]
|
||||||
[rule.unused-parameter]
|
[rule.unused-parameter]
|
||||||
|
[rule.unused-receiver]
|
||||||
[rule.useless-break]
|
[rule.useless-break]
|
||||||
[rule.use-any]
|
[rule.use-any]
|
||||||
[rule.var-declaration]
|
[rule.var-declaration]
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ type lintBoolLiteral struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor {
|
func (w *lintBoolLiteral) Visit(node ast.Node) ast.Visitor {
|
||||||
switch n := node.(type) {
|
if n, ok := node.(*ast.BinaryExpr); ok {
|
||||||
case *ast.BinaryExpr:
|
|
||||||
if !isBoolOp(n.Op) {
|
if !isBoolOp(n.Op) {
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -159,8 +159,7 @@ func extractFromStarExpr(expr *ast.StarExpr) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func extractFromIndexExpr(expr *ast.IndexExpr) string {
|
func extractFromIndexExpr(expr *ast.IndexExpr) string {
|
||||||
switch v := expr.X.(type) {
|
if v, ok := expr.X.(*ast.Ident); ok {
|
||||||
case *ast.Ident:
|
|
||||||
return v.Name
|
return v.Name
|
||||||
}
|
}
|
||||||
return defaultStructName
|
return defaultStructName
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ type lintConstantLogicalExpr struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *lintConstantLogicalExpr) Visit(node ast.Node) ast.Visitor {
|
func (w *lintConstantLogicalExpr) Visit(node ast.Node) ast.Visitor {
|
||||||
switch n := node.(type) {
|
if n, ok := node.(*ast.BinaryExpr); ok {
|
||||||
case *ast.BinaryExpr:
|
|
||||||
if !w.isOperatorWithLogicalResult(n.Op) {
|
if !w.isOperatorWithLogicalResult(n.Op) {
|
||||||
return w
|
return w
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,8 +42,7 @@ type lintContextKeyTypes struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w lintContextKeyTypes) Visit(n ast.Node) ast.Visitor {
|
func (w lintContextKeyTypes) Visit(n ast.Node) ast.Visitor {
|
||||||
switch n := n.(type) {
|
if n, ok := n.(*ast.CallExpr); ok {
|
||||||
case *ast.CallExpr:
|
|
||||||
checkContextKeyType(w, n)
|
checkContextKeyType(w, n)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,8 +111,7 @@ func (r *EnforceRepeatedArgTypeStyleRule) Apply(file *lint.File, _ lint.Argument
|
|||||||
|
|
||||||
astFile := file.AST
|
astFile := file.AST
|
||||||
ast.Inspect(astFile, func(n ast.Node) bool {
|
ast.Inspect(astFile, func(n ast.Node) bool {
|
||||||
switch fn := n.(type) {
|
if fn, ok := n.(*ast.FuncDecl); ok {
|
||||||
case *ast.FuncDecl:
|
|
||||||
switch r.funcArgStyle {
|
switch r.funcArgStyle {
|
||||||
case enforceRepeatedArgTypeStyleTypeFull:
|
case enforceRepeatedArgTypeStyleTypeFull:
|
||||||
if fn.Type.Params != nil {
|
if fn.Type.Params != nil {
|
||||||
|
|||||||
@@ -36,8 +36,7 @@ type lintElseError struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *lintElseError) Visit(node ast.Node) ast.Visitor {
|
func (w *lintElseError) Visit(node ast.Node) ast.Visitor {
|
||||||
switch v := node.(type) {
|
if v, ok := node.(*ast.BlockStmt); ok {
|
||||||
case *ast.BlockStmt:
|
|
||||||
for i := range len(v.List) - 1 {
|
for i := range len(v.List) - 1 {
|
||||||
// if var := whatever; var != nil { return var }
|
// if var := whatever; var != nil { return var }
|
||||||
s, ok := v.List[i].(*ast.IfStmt)
|
s, ok := v.List[i].(*ast.IfStmt)
|
||||||
|
|||||||
@@ -81,8 +81,7 @@ type lintMaxPublicStructs struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *lintMaxPublicStructs) Visit(n ast.Node) ast.Visitor {
|
func (w *lintMaxPublicStructs) Visit(n ast.Node) ast.Visitor {
|
||||||
switch v := n.(type) {
|
if v, ok := n.(*ast.TypeSpec); ok {
|
||||||
case *ast.TypeSpec:
|
|
||||||
name := v.Name.Name
|
name := v.Name.Name
|
||||||
first := string(name[0])
|
first := string(name[0])
|
||||||
if strings.ToUpper(first) == first {
|
if strings.ToUpper(first) == first {
|
||||||
|
|||||||
@@ -136,8 +136,7 @@ type lintStructTagRule struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
|
func (w lintStructTagRule) Visit(node ast.Node) ast.Visitor {
|
||||||
switch n := node.(type) {
|
if n, ok := node.(*ast.StructType); ok {
|
||||||
case *ast.StructType:
|
|
||||||
isEmptyStruct := n.Fields == nil || n.Fields.NumFields() < 1
|
isEmptyStruct := n.Fields == nil || n.Fields.NumFields() < 1
|
||||||
if isEmptyStruct {
|
if isEmptyStruct {
|
||||||
return nil // skip empty structs
|
return nil // skip empty structs
|
||||||
|
|||||||
@@ -73,8 +73,7 @@ type lintUnhandledErrors struct {
|
|||||||
// Visit looks for statements that are function calls.
|
// Visit looks for statements that are function calls.
|
||||||
// If the called function returns a value of type error a failure will be created.
|
// If the called function returns a value of type error a failure will be created.
|
||||||
func (w *lintUnhandledErrors) Visit(node ast.Node) ast.Visitor {
|
func (w *lintUnhandledErrors) Visit(node ast.Node) ast.Visitor {
|
||||||
switch n := node.(type) {
|
if n, ok := node.(*ast.ExprStmt); ok {
|
||||||
case *ast.ExprStmt:
|
|
||||||
fCall, ok := n.X.(*ast.CallExpr)
|
fCall, ok := n.X.(*ast.CallExpr)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil // not a function call
|
return nil // not a function call
|
||||||
|
|||||||
Reference in New Issue
Block a user