Documentation ¶
Overview ¶
Package lintutil contains utilities for writing linters.
For general documentation on linting, see dev/linters/README.md.
Index ¶
- func CallsSuper(funcDecl *ast.FuncDecl, typesInfo *types.Info) bool
- func FilterFuncs(files []*ast.File, predicate func(*ast.FuncDecl) bool) []*ast.FuncDecl
- func IsResolverFunc(funcDecl *ast.FuncDecl, typesInfo *types.Info) bool
- func NameOf(obj types.Object) string
- func ObjectFor(node ast.Node, typesInfo *types.Info) types.Object
- func ReceiversByType(files []*ast.File, typesInfo *types.Info) map[types.Type][]*ast.FuncDecl
- func TypeIs(typ types.Type, pkgPath string, name string) bool
- func UnwrapMaybePointer(typ types.Type) types.Type
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CallsSuper ¶
CallsSuper returns whether the given function body (which must be a receiver) calls its "super" -- that is, <receiver-var>.<superclass-name>.<receiver-name>().
This doesn't validate what the superclass name is; in the general case it's not clear what the correct rule would be as it's not necessarily the name of any field of the receiver-type (it may be a field of an intermediate embedded type). We just validate that you call some method of a field of your receiver, which has the same name; in practice you probably only have one option.
func FilterFuncs ¶
FilterFuncs returns the toplevel functions in the given files that match the predicate.
func IsResolverFunc ¶
Says whether the given function is a graphql resolver. A surprising number of linters want to special case graphql resolvers, which have a format dictated by gqlgen and thus may not follow our linting rules. This helps with that.
The conditions we use are: 1) having receiver whose name ends with "Resolver" 2) is exported 3a) either has a `context.Context` as the first argument (for resolvers) 3b) or returns an object whose name ends with Resolver (for federation)
func NameOf ¶
NameOf takes a node and returns the name of the symbol to which it refers, if any, in the form "package/path.UnqualifiedName". For built-in calls (such as `println()`) it uses a package name of "builtin" (so `builtin.println`).
This will return a name for functions (including builtin), types, package-vars, consts, and not necessarily other nodes like struct fields. If it can't determine the name, it returns "".
Note that methods have names like "(package/path.Interface).Method" or "(*package/path.Struct).Method".
func ObjectFor ¶
ObjectFor takes an AST node, and returns the corresponding types.Object, if there is one.
func ReceiversByType ¶
ReceiversByType returns all the receivers in the file, in a map by type.
Note that it may be more efficient to export this as an analyzer-result.
func TypeIs ¶
TypeIs takes a type object, and returns true if it is the given named type.
Returns false if pkgPath.name is not a type, or if it is not this type. Note that this includes cases where this type wraps pkgPath.name, or where they share an underlying type: this will only return true if the types are the same. Predeclared types will match the empty path.
Types ¶
This section is empty.