ProductPromotion
Logo

Go.Lang

made by https://0x3d.site

GitHub - surullabs/lint: Run linters from Go code -
Run linters from Go code - . Contribute to surullabs/lint development by creating an account on GitHub.
Visit Site

GitHub - surullabs/lint: Run linters from Go code -

GitHub - surullabs/lint: Run linters from Go code -

Lint - run linters from Go

Build Status GoDoc Coverage StatusGo Report Card

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

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

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.

Articles
to learn more about the golang concepts.

Resources
which are currently available to browse on.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

FAQ's
to know more about the topic.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Queries
or most google FAQ's about GoLang.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory