lint alternatives and similar packages
Based on the "Code Analysis" category.
Alternatively, view lint alternatives based on common mentions on social networks and blogs.
-
Go Metalinter
Metalinter is a tool to automatically apply all static analysis tool and report their output in normalized form. -
go-cleanarch
Clean architecture validator for go, like a The Dependency Rule and interaction between packages in your Go projects. -
go-mod-outdated
Find outdated dependencies of your Go projects. go-mod-outdated provides a table view of the go list -u -m -json all command which lists all dependencies of a Go project and their available minor and patch updates. It also provides a way to filter indirect dependencies and dependencies without updates. -
goreturns
A gofmt/goimports-like tool for Go programmers that fills in Go return statements with zero values to match the func return types -
tickgit
Manage your repository's TODOs, tickets and checklists as config in your codebase. -
GoCover.io
GoCover.io offers the code coverage of any golang package as a service. -
apicompat
apicompat checks recent changes to a Go project for backwards incompatible changes -
ChainJacking
Find which of your direct GitHub dependencies is susceptible to RepoJacking attacks -
usestdlibvars
A linter that detect the possibility to use variables/constants from the Go standard library. -
tarp
tarp finds functions and methods without direct unit tests in Go source code. -
staticcheck
staticcheck is go vet on steroids, applying a ton of static analysis checks you might be used to from tools like ReSharper for C#. -
gosimple
gosimple is a linter for Go source code that specialises on simplifying code. -
Golint online
Lints online Go source files on GitHub, Bitbucket and Google Project Hosting using the golint package. -
unused
unused checks Go code for unused constants, variables, functions and types.
Clean code begins in your IDE with SonarLint
Do you think we are missing an alternative of lint or a related project?
Popular Comparisons
README
Lint - run linters from Go
Lint makes it easy to run linters from Go code. This allows lint checks to be part of a regular go build
+ go test
workflow. False positives are easily ignored and linters are automatically integrated into CI pipelines without any extra effort. Check the project website to learn more about how it can be useful.
Quick Start
Download using
go get -t github.com/surullabs/lint
Run the default linters by adding a new test at the top level of your repository
func TestLint(t *testing.T) {
// Run default linters
err := lint.Default.Check("./...")
// Ignore lint errors from auto-generated files
err = lint.Skip(err, lint.RegexpMatch(`_string\.go`, `\.pb\.go`))
if err != nil {
t.Fatal("lint failures: %v", err)
}
}
How it works
lint
runs linters using the excellent os/exec
package. It searches all Go binary directories for the needed binaries and when they don't exist it downloads them using go get
. Errors generated by running linters are split by newline and can be skipped as needed.
Default linters
gofmt
- Rungofmt -d
and report any differences as errorsgovet
- Rungo tool vet -shadow
golint
- https://github.com/golang/lintgosimple
- Code simplificationgostaticcheck
- Verify function argumentserrcheck
- Find ignored errors
Using gometalinter
Gometalinter runs a number of linters concurrently. It also vendors each of these and uses the vendored versions automatically. A vendored version of gometalinter
is included and can be used in the following manner. Please note that not all linters used by gometalinter have been tested.
import (
"testing"
"github.com/surullabs/lint/gometalinter"
)
func TestLint(t *testing.T) {
// Run default linters
metalinter := gometalinter.Check{
Args: []string{
// Arguments to gometalinter. Do not include the package names here.
},
}
if err := metalinter.Check("./..."); err != nil {
t.Fatal("lint failures: %v", err)
}
}
Other available linters
varcheck
- Detect unused variables and constantsstructcheck
- Detect unused struct fieldsaligncheck
- Detect suboptimal struct alignmentdupl
- Detect duplicated code
Why lint
?
There are a number of excellent linters available for Go and Lint makes it easy to run them from tests. While building our mobile calendar app TimeFerret, (which is built primarily in Go), including scripts that run linters as part of every repository grew tiresome very soon. Using lint
to create tests that ran on each commit made the codebase much more stable, since any unneeded false positives were easily skipped. The main advantages of using lint
over running tools manually is:
- Skip false positives explicitly in your tests - This makes it easy to run only needed checks.
- Enforce linter usage with no overhead - No special build scripts are needed to install linters on each developer machine as they are automatically downloaded.
- Simple CI integration - Since linters are run as part of tests, there are no extra steps needed to integrate them into your CI pipeline.
Adding a custom linter
Please check if you can use the gometalinter package first. If not, adding a new linter is made dead simple by the github.com/surullabs/lint/checkers
package. The entire source for the golint
integration is
import "github.com/surullabs/lint/checkers"
type Check struct {
}
func (Check) Check(pkgs ...string) error {
return checkers.Lint("golint", "", github.com/golang/lint/golint", pkgs)
}
The github.com/surullabs/lint/testutil
package contains utilities for testing custom linters.
You can also take a look at this CL which adds varcheck
for an example of how to add a linter.
If you'd like to vendor the linter source, please use the same method as the gometalinter
package.
License
Lint is available under the Apache License. See the LICENSE file for details.
Contributing
Pull requests are always welcome! Please ensure any changes you send have an accompanying test case.
*Note that all licence references and agreements mentioned in the lint README section above
are relevant to that project's source code only.