lint: github.com/surullabs/lint Index | Examples | Files | Directories

package lint

import "github.com/surullabs/lint"

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.

Code:

// 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)
}

Code:

// 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)
}

Code:

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)
}

Index

Examples

Package Files

lint.go skip.go unused.go

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)

func Skip Uses

func Skip(err error, skippers ...Skipper) error

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.

type Checker Uses

type Checker interface {
    Check(pkgs ...string) error
}

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 Uses

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 Uses

func (g Group) Check(pkgs ...string) error

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.

func (Group) With Uses

func (g Group) With(checkers ...Checker) Group

With returns a copy of g with checkers appended

type Skipper Uses

type Skipper interface {
    Skip(err string) bool
}

Skipper is the interface that wraps the Skip method.

Skip returns true if err is an error that must be ignored.

func RegexpMatch Uses

func RegexpMatch(regexps ...string) Skipper

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 Uses

type StringSkipper struct {
    Strings []string
    Matcher func(err, str string) bool
}

StringSkipper implements Skipper and skips an error if Matcher(err, str) == true for any of Strings

func (StringSkipper) Skip Uses

func (s StringSkipper) Skip(check string) bool

Skip returns true if Matcher(check, str) == true for any of Strings.

Directories

PathSynopsis
aligncheckPackage aligncheck provides lint integration for the aligncheck linter
checkersPackage checkers provides utilities for implementing lint checkers.
dupl
errcheckPackage errcheck provides lint integration for the errcheck linter
gofmt
golint
gometalinter
gosimple
gostaticcheck
govet
structcheckPackage structcheck provides lint integration for the structcheck linter
testutilPackage testutil contains methods to test checkers.
varcheckPackage varcheck provides lint integration for the varcheck linter

Package lint imports 10 packages (graph) and is imported by 2 packages. Updated 2017-10-09. Refresh now. Tools for package owners.