Documentation ¶
Overview ¶
Package thriftlint is an extensible Linter for Thrift files, written in Go.
New() takes a set of checks and options and creates a linter. The linter checks can then be applied to a set of files with .Lint(files...).
See the README for details.
Package linter lints Thrift files.
Actual implementations of linter checks are in the subpackage "checks".
Index ¶
- Variables
- func Annotation(node interface{}, key, dflt string) string
- func AnnotationExists(node interface{}, key string) bool
- func Comment(v interface{}) []string
- func DotSuffix(pkg string) string
- func IsInitialism(s string) bool
- func LowerCamelCase(s string) string
- func LowerSnakeCase(s string) string
- func Parse(includeDirs []string, sources []string) (map[string]*parser.Thrift, error)
- func Pos(v interface{}) parser.Pos
- func Resolve(symbol string, file *parser.Thrift) interface{}
- func SplitSymbol(s string) []string
- func UpperCamelCase(s string) string
- func UpperSnakeCase(s string) string
- type Check
- type Checks
- type Linter
- type Message
- type Messages
- type Option
- type Severity
Constants ¶
This section is empty.
Variables ¶
var ( // BuiltinThriftTypes is a map of the basic builtin Thrift types. Useful in templates. BuiltinThriftTypes = map[string]bool{ "bool": true, "byte": true, "i16": true, "i32": true, "i64": true, "double": true, "string": true, } // BuiltinThriftCollections is the set of builtin collection types in Thrift. BuiltinThriftCollections = map[string]bool{ "map": true, "list": true, "set": true, "binary": true, } )
var ( TypeType = reflect.TypeOf(parser.Type{}) ThriftType = reflect.TypeOf(parser.Thrift{}) ServiceType = reflect.TypeOf(parser.Service{}) MethodType = reflect.TypeOf(parser.Method{}) EnumType = reflect.TypeOf(parser.Enum{}) EnumValueType = reflect.TypeOf(parser.EnumValue{}) StructType = reflect.TypeOf(parser.Struct{}) FieldType = reflect.TypeOf(parser.Field{}) ConstantType = reflect.TypeOf(parser.Constant{}) TypedefType = reflect.TypeOf(parser.Typedef{}) )
Types and their supported annotations.
Functions ¶
func Annotation ¶
Annotation returns the annotation value associated with "key" from the .Annotations field of a go-thrift AST node.
This will panic if node is not a struct with an Annotations field of the correct type.
func AnnotationExists ¶
AnnotationExists checks if an annotation is present at all.
func DotSuffix ¶
Extract the suffix from a . separated string (ie. namespace). Useful for getting the package reference from a files namespace.
func IsInitialism ¶
func LowerCamelCase ¶
LowerCamelCase converts a symbol to lowerCamelCase
func LowerSnakeCase ¶
LowerSnakeCase converts a symbol to snake_case
func SplitSymbol ¶
SplitSymbol splits an arbitrary symbol into parts. It accepts symbols in snake case and camel case, and correctly supports all-caps substrings.
eg. "some_snake_case_symbol" would become ["some", "snake", "case", "symbol"] and "someCamelCaseSymbol" would become ["some", "Camel", "Case", "Symbol"]
func UpperCamelCase ¶
UpperCamelCase converts a symbol to CamelCase
func UpperSnakeCase ¶
UpperSnakeCase converts a symbol to UPPER_SNAKE_CASE
Types ¶
type Check ¶
type Check interface { // ID of the Check. Must be unique across all checks. // // IDs may be hierarchical, separated by a period. eg. "enum", "enum.values" ID() string // Checker returns the checking function. // // The checking function has the signature "func(...) Messages", where "..." is a sequence of // Thrift AST types that are matched against the current node's ancestors as the linter walks // the AST of each file. "..." may also be "interface{}" in which case the checker function // will be called for each node in the AST. // // For example, the function: // // func (s *parser.Struct, f *parser.Field) (messages Messages) // // Will match all each struct field, but not union fields. Checker() interface{} }
Check implementations are used by the linter to check AST nodes.
type Checks ¶
type Checks []Check
Checks is a convenience wrapper around a slice of Checks.
func (Checks) CloneAndDisable ¶
CloneAndDisable returns a copy of this Checks slice with all checks matching prefix disabled.
type Message ¶
type Message struct { // File that resulted in the message. File *parser.Thrift // ID of the Checker that generated this message. Checker string Severity Severity Object interface{} Message string }
Message represents a single linter message.
type Messages ¶
type Messages []*Message
Messages is the set of messages each check should return.
Typically it will be used like so:
func MyCheck(...) (messages Messages) { messages.Warning(t, "some warning") }
type Option ¶
type Option func(*Linter)
func WithIncludeDirs ¶
WithIncludeDirs is an Option that sets the directories to use for searching when parsing Thrift includes.
func WithLogger ¶
func WithLogger(logger logger) Option
WithLogger is an Option that sets the logger object used by the linter.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package checks contains default checks included with the Thrift linter.
|
Package checks contains default checks included with the Thrift linter. |
cmd
|
|