An extensible linter for Thrift
Go to file
2017-02-23 15:50:21 -05:00
checks Format output of naming checks more cleanly, and simplify regexes 2017-02-23 15:50:21 -05:00
cmd/thrift-lint Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
.gitignore Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
annotations.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
api_test.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
api.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
context_test.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
context.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
doc.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
LICENSE Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
linter_test.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
linter.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
parse.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
README.md Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
symbol_test.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
symbol.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00
types.go Initial export of Thrift linter. 2017-01-11 15:39:49 +11:00

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.