Documentation ¶
Index ¶
- func Doc(node ast.Node) string
- func Parse(r io.Reader) (*ast.Program, *idl.Info, error)
- func ParseFile(filename string, dirs []string) (*ast.Program, *idl.Info, error)
- func Resolve(name string, program *ast.Program, dirs []string) (ast.Node, error)
- func ResolveConstant(ref ast.ConstantReference, program *ast.Program, dirs []string) (ast.Node, error)
- func ResolveType(ref ast.TypeReference, program *ast.Program, dirs []string) (ast.Node, error)
- type C
- func (c *C) Errorf(node ast.Node, message string, args ...interface{})
- func (c *C) Logf(message string, args ...interface{})
- func (c *C) Resolve(name string) ast.Node
- func (c *C) ResolveConstant(ref ast.ConstantReference) ast.Node
- func (c *C) ResolveType(ref ast.TypeReference) ast.Node
- func (c *C) Warningf(node ast.Node, message string, args ...interface{})
- type Check
- type Checks
- type Linter
- type Message
- type Messages
- type Option
- type Severity
- type VisitorFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseFile ¶
ParseFile parses a Thrift file. The filename must appear in one of the given directories.
func Resolve ¶
Resolve resolves a named reference to its target node.
The target can either be in the current program's scope or it can refer to an included file using dot notation. Included files must exist in one of the given search directories.
func ResolveConstant ¶
func ResolveConstant(ref ast.ConstantReference, program *ast.Program, dirs []string) (ast.Node, error)
ResolveConstant resolves an ast.ConstantReference to its target node.
The following name formats are supported:
- "Constant" (ast.Constant)
- "Enum.Value" (ast.EnumItem)
- "include.Constant" (ast.Constant)
- "include.Enum.Value" (ast.EnumItem)
func ResolveType ¶
ResolveType calls Resolve and goes one step further by attempting to resolve the target node's own type. This is useful when the reference points to an ast.Typedef or ast.Constant, for example, and the caller is primarily intererested in the target's ast.Type.
Types ¶
type C ¶
type C struct { Filename string Dirs []string Program *ast.Program Check string Messages Messages // contains filtered or unexported fields }
C is a type passed to all check functions to provide context.
func (*C) ResolveConstant ¶
func (c *C) ResolveConstant(ref ast.ConstantReference) ast.Node
ResolveConstant resolves a constant reference to its target.
func (*C) ResolveType ¶
func (c *C) ResolveType(ref ast.TypeReference) ast.Node
ResolveType resolves a type reference to its target type.
type Check ¶
type Check struct { Name string // contains filtered or unexported fields }
Check is a named check function.
func (*Check) Call ¶
Call the check function if its arguments end with the current node in the hierarchy and all other variable arguments are its strictly ordered parents.
The first argument is always a *C instance.
The nodes are ordered from the current node through it ancestors.
hierarchy = {*ast.EnumItem, *ast.Enum, *ast.Program}
The following functions would match:
f(*C, *ast.Program, *ast.Enum, *ast.EnumItem) f(*C, *ast.Enum, *ast.EnumItem) f(*C, *ast.EnumItem)
But these would not:
f(*C, *ast.Program) f(*C, *ast.Enum) f(*C, *ast.EnumItem, *ast.Enum) f(*C, *ast.Program, *ast.EnumItem)
Function arguments can also use the generic ast.Node interface type:
f(*C, ast.Node) f(*C, *ast.Program, ast.Node) f(*C, parent, node ast.Node)
type Checks ¶
type Checks []*Check
Checks is a list of checks.
func (Checks) SortedNames ¶
SortedNames returns a sorted list of the checks' names.
type Linter ¶
type Linter struct {
// contains filtered or unexported fields
}
Linter is a configured Thrift linter.
type Message ¶
type Message struct { Filename string Pos ast.Position Node ast.Node Check string Severity Severity Message string }
Message is a message produced by a Check.
type Option ¶
type Option func(*Linter)
Option represents a Linter option.
func WithIncludes ¶
WithIncludes is an Option that adds Thrift include paths to the linter.
func WithLogger ¶
WithLogger is an Option that sets the log.Logger object used by the linter.
type VisitorFunc ¶
type VisitorFunc func(ast.Walker, ast.Node) VisitorFunc
VisitorFunc adapts a function to the ast.Visitor interface. This differs from ast.VisitorFunc in that is supports an ast.Visitor-compativle return value.