Documentation ¶
Overview ¶
Package lint runs linters as part of go test.
It is intended to be used as a substitute for an external build step that runs tools such as go vet or golint.
Example ¶
package main import ( "log" "github.com/surullabs/lint" ) func main() { // Run the default set of linters err := lint.Default.Check("./...") // Ignore all errors from the file unused.go. // // This is intended as an example of how to skip errors and not a // recommendation that you skip these kinds of errors. err = lint.Skip(err, lint.RegexpMatch( `unused\.go:4:2: a blank import`, `unused\.go:7:7: don't use underscores in Go names`, )) if err != nil { // Record lint failures. // Use t.Fatal(err) when running in a test log.Fatal(err) } }
Output:
Example (Custom) ¶
package main import ( "log" "github.com/surullabs/lint" "github.com/surullabs/lint/gofmt" "github.com/surullabs/lint/govet" ) func main() { // Run a custom set of linters custom := lint.Group{ gofmt.Check{}, govet.Check{}, } if err := custom.Check("./..."); err != nil { // Record lint failures. // Use t.Fatal(err) when running in a test log.Fatal(err) } }
Output:
Example (Packages) ¶
package main import ( "log" "github.com/surullabs/lint" "github.com/surullabs/lint/gofmt" "github.com/surullabs/lint/govet" ) func main() { custom := lint.Group{gofmt.Check{}, govet.Check{}} // Specify a list of packages instead of the wildcard if err := custom.Check(".", "./checkers"); err != nil { // Record lint failures. // Use t.Fatal(err) when running in a test log.Fatal(err) } }
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var Default = Group{ gofmt.Check{}, govet.Shadow, golint.Check{}, gosimple.Check{}, gostaticcheck.Check{}, errcheck.Check{}, }
Default holds a default list of lint tools for convenient use. These include
- gofmt -d
- go tool vet -shadow
- golint
- gosimple (https://github.com/dominikh/go-simple)
- gostaticcheck (https://github.com/dominikh/go-staticcheck)
- errcheck (https://github.com/kisielk/errcheck)
Functions ¶
func Skip ¶
Skip filters errors using skippers. If err satisfies the below interface
type errors interface { Errors() []string }
the filters are applied to each string returned by Errors and then concatenated. If the error implements the above interface, it is guaranteed that any returned error will also implement the same.
Skippers are run in the order provided and a single skipper returning true will result in that error being skipped.
Types ¶
type Checker ¶
Checker is the interface that wraps the Check method.
Check lints all files in pkgs. Each item in pkgs may be a fully qualified import path, relative import path or a path with the wildcard suffix ...
type Group ¶
type Group []Checker
Group is a Checker list that is applied in sequence. See Check for details on how it is applied.
func (Group) Check ¶
Check applies each of checkers in g in the order provided.
The error returned is either nil or contains errors returned by each Checker. These are exposed using the errors interface described in Skip and prefixed with the type of the Checker that generated the error. For example, the following error generated by govet.Checker:
file.go:23: err is unintentionally shadowed.
is converted to:
govet.Checker: file.go:23: err is unintentionally shadowed.
A checker is not shorted-circuited by a previous checker returning an error.
Any error that implements errors is flattened into the final error list.
type Skipper ¶
Skipper is the interface that wraps the Skip method.
Skip returns true if err is an error that must be ignored.
func RegexpMatch ¶
RegexpMatch returns a Skipper that skips all errors which match any of the provided regular expression patterns. SkipRegexpMatch expects all patterns to be valid regexps and panics otherwise.
type StringSkipper ¶
StringSkipper implements Skipper and skips an error if Matcher(err, str) == true for any of Strings
func (StringSkipper) Skip ¶
func (s StringSkipper) Skip(check string) bool
Skip returns true if Matcher(check, str) == true for any of Strings.
Directories ¶
Path | Synopsis |
---|---|
Package aligncheck provides lint integration for the aligncheck linter
|
Package aligncheck provides lint integration for the aligncheck linter |
Package checkers provides utilities for implementing lint checkers.
|
Package checkers provides utilities for implementing lint checkers. |
Package errcheck provides lint integration for the errcheck linter
|
Package errcheck provides lint integration for the errcheck linter |
_vendored/src/github.com/alecthomas/template
Package template implements data-driven templates for generating textual output.
|
Package template implements data-driven templates for generating textual output. |
_vendored/src/github.com/alecthomas/template/parse
Package parse builds parse trees for templates as defined by text/template and html/template.
|
Package parse builds parse trees for templates as defined by text/template and html/template. |
_vendored/src/github.com/alecthomas/units
Package units provides helpful unit multipliers and functions for Go.
|
Package units provides helpful unit multipliers and functions for Go. |
_vendored/src/github.com/google/shlex
Package shlex implements a simple lexer which splits input in to tokens using shell-style rules for quoting and commenting.
|
Package shlex implements a simple lexer which splits input in to tokens using shell-style rules for quoting and commenting. |
_vendored/src/github.com/stretchr/testify/assert
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system.
|
Package assert provides a set of comprehensive testing tools for use with the normal Go testing system. |
_vendored/src/gopkg.in/alecthomas/kingpin.v2
Package kingpin provides command line interfaces like this: $ chat usage: chat [<flags>] <command> [<flags>] [<args> ...] Flags: --debug enable debug mode --help Show help.
|
Package kingpin provides command line interfaces like this: $ chat usage: chat [<flags>] <command> [<flags>] [<args> ...] Flags: --debug enable debug mode --help Show help. |
Package structcheck provides lint integration for the structcheck linter
|
Package structcheck provides lint integration for the structcheck linter |
Package testutil contains methods to test checkers.
|
Package testutil contains methods to test checkers. |
Package varcheck provides lint integration for the varcheck linter
|
Package varcheck provides lint integration for the varcheck linter |