mirror of
https://github.com/valitydev/thriftlint.git
synced 2024-11-06 00:05:20 +00:00
An extensible linter for Thrift
1365ae24b0
Format output of naming checks more cleanly, and simplify regexes |
||
---|---|---|
checks | ||
cmd/thrift-lint | ||
.gitignore | ||
annotations.go | ||
api_test.go | ||
api.go | ||
context_test.go | ||
context.go | ||
doc.go | ||
LICENSE | ||
linter_test.go | ||
linter.go | ||
parse.go | ||
README.md | ||
symbol_test.go | ||
symbol.go | ||
types.go |
An extensible linter for Thrift
This is an extensible linter for Thrift. It includes a set of common lint checks, but allows for both customisation of those checks, and creation of new ones by implementing the Check interface.
For an example of how to build your own linter utility, please refer to the thrift-lint source.
Example checker
Here is an example of a checker utilising the MakeCheck()
convenience
function to ensure that fields are present in the file in the same order as
their field numbers:
func CheckStructFieldOrder() thriftlint.Check {
return thriftlint.MakeCheck("field.order", func(s *parser.Struct) (messages thriftlint.Messages) {
fields := sortedFields(s.Fields)
sort.Sort(fields)
for i := 0; i < len(fields)-1; i++ {
a := fields[i]
b := fields[i+1]
if a.Pos.Line > b.Pos.Line {
messages.Warning(fields[i], "field %d and %d are out of order", a.ID, b.ID)
}
}
return
})
}
thrift-lint tool
A binary is included that can be used to perform basic linting with the builtin checks:
$ go get github.com/UrbanCompass/thriftlint/cmd/thrift-lint
$ thrift-lint --help
usage: thrift-lint [<flags>] <sources>...
A linter for Thrift.
For details, please refer to https://github.com/UrbanCompass/thriftlint
Flags:
--help Show context-sensitive help (also try --help-long
and --help-man).
-I, --include=DIR ... Include directories to search.
--debug Enable debug logging.
--disable=LINTER ... Linters to disable.
--list List linter checks.
--errors Only show errors.
Args:
<sources> Thrift sources to lint.