Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/UrbanCompass/thriftlint

An extensible linter for Thrift
https://github.com/UrbanCompass/thriftlint

golang linter thrift thrift-lint

Last synced: 3 months ago
JSON representation

An extensible linter for Thrift

Awesome Lists containing this project

README

        

# An extensible linter for Thrift [![](https://godoc.org/github.com/UrbanCompass/thriftlint?status.svg)](http://godoc.org/github.com/UrbanCompass/thriftlint)

This is an extensible linter for [Thrift](https://thrift.apache.org/). 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](https://godoc.org/github.com/UrbanCompass/thriftlint#Check) interface.

For an example of how to build your own linter utility, please refer to the
[thrift-lint source](https://github.com/UrbanCompass/thriftlint/tree/master/cmd/thrift-lint).

## 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:

```go
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 [] ...

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:
Thrift sources to lint.
```