mirror of
https://github.com/mgechev/revive.git
synced 2024-11-28 08:49:11 +02:00
40 lines
841 B
Go
40 lines
841 B
Go
package defaultrule
|
|
|
|
import (
|
|
"go/ast"
|
|
"strings"
|
|
|
|
"github.com/mgechev/revive/file"
|
|
)
|
|
|
|
const styleGuideBase = "https://golang.org/wiki/CodeReviewComments"
|
|
|
|
// isBlank returns whether id is the blank identifier "_".
|
|
// If id == nil, the answer is false.
|
|
func isBlank(id *ast.Ident) bool { return id != nil && id.Name == "_" }
|
|
|
|
func isTest(f *file.File) bool {
|
|
return strings.HasSuffix(f.Name, "_test.go")
|
|
}
|
|
|
|
var commonMethods = map[string]bool{
|
|
"Error": true,
|
|
"Read": true,
|
|
"ServeHTTP": true,
|
|
"String": true,
|
|
"Write": true,
|
|
}
|
|
|
|
func receiverType(fn *ast.FuncDecl) string {
|
|
switch e := fn.Recv.List[0].Type.(type) {
|
|
case *ast.Ident:
|
|
return e.Name
|
|
case *ast.StarExpr:
|
|
if id, ok := e.X.(*ast.Ident); ok {
|
|
return id.Name
|
|
}
|
|
}
|
|
// The parser accepts much more than just the legal forms.
|
|
return "invalid-type"
|
|
}
|