[mirror] This is a linter for Go source code.

Related tags

Code Analysis lint
Overview

Golint is a linter for Go source code.

Go Reference Build Status

Installation

Golint requires a supported release of Go.

go get -u golang.org/x/lint/golint

To find out where golint was installed you can run go list -f {{.Target}} golang.org/x/lint/golint. For golint to be used globally add that directory to the $PATH environment setting.

Usage

Invoke golint with one or more filenames, directories, or packages named by its import path. Golint uses the same import path syntax as the go command and therefore also supports relative import paths like ./.... Additionally the ... wildcard can be used as suffix on relative and absolute file paths to recurse into them.

The output of this tool is a list of suggestions in Vim quickfix format, which is accepted by lots of different editors.

Purpose

Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes.

Golint differs from govet. Govet is concerned with correctness, whereas golint is concerned with coding style. Golint is in use at Google, and it seeks to match the accepted style of the open source Go project.

The suggestions made by golint are exactly that: suggestions. Golint is not perfect, and has both false positives and false negatives. Do not treat its output as a gold standard. We will not be adding pragmas or other knobs to suppress specific warnings, so do not expect or require code to be completely "lint-free". In short, this tool is not, and will never be, trustworthy enough for its suggestions to be enforced automatically, for example as part of a build process. Golint makes suggestions for many of the mechanically checkable items listed in Effective Go and the CodeReviewComments wiki page.

Scope

Golint is meant to carry out the stylistic conventions put forth in Effective Go and CodeReviewComments. Changes that are not aligned with those documents will not be considered.

Contributions

Contributions to this project are welcome provided they are in scope, though please send mail before starting work on anything major. Contributors retain their copyright, so we need you to fill out a short form before we can accept your contribution.

Vim

Add this to your ~/.vimrc:

set rtp+=$GOPATH/src/golang.org/x/lint/misc/vim

If you have multiple entries in your GOPATH, replace $GOPATH with the right value.

Running :Lint will run golint on the current file and populate the quickfix list.

Optionally, add this to your ~/.vimrc to automatically run golint on :w

autocmd BufWritePost,FileWritePost *.go execute 'Lint' | cwindow

Emacs

Add this to your .emacs file:

(add-to-list 'load-path (concat (getenv "GOPATH")  "/src/golang.org/x/lint/misc/emacs/"))
(require 'golint)

If you have multiple entries in your GOPATH, replace $GOPATH with the right value.

Running M-x golint will run golint on the current file.

For more usage, see Compilation-Mode.

Comments
  • Disable/Enable specific Rules

    Disable/Enable specific Rules

    Hi everyone 👋

    golint is great but sometimes you want all the rules except one and it would be wonderful to specify it somewhere. Other modern linters like ESLint support it, would be good to have it supported in golint as well.

    opened by steelbrain 59
  • Unexpected module path

    Unexpected module path

    Unable to fetch golang/lint because of unexpected module path error.

    go get -u golang.org/x/lint
    go: finding golang.org/x/lint latest
    go: finding golang.org/x/sync latest
    go: finding google.golang.org/genproto latest
    go: finding golang.org/x/net latest
    go: finding github.com/golang/glog latest
    go: finding golang.org/x/tools latest
    go: finding github.com/golang/lint latest
    go: github.com/golang/[email protected]: parsing go.mod: unexpected module path "golang.org/x/lint"
    go: finding golang.org/x/exp latest
    go: finding golang.org/x/oauth2 latest
    go: finding honnef.co/go/tools latest
    go: finding golang.org/x/sys latest
    go get: error loading module requirements
    
    bug 
    opened by bill-rich 56
  • should have comment or be unexported

    should have comment or be unexported

    screen shot 2016-02-03 at 18 20 59

    I've just started learning Golang and while I do want to follow best practises and follow this linter, I'm not sure how to fix these warnings. When I put some random comment above some function or a type nothing really happens.

    For instance, if I put a comment above "type Saturation struct" I get another warning message :

    comment on exported type Salutation should be of the form "Salutation ..." (with optional leading article)

    Please if you can, guide me on how to comment my code properly so I can avoid these warnings, they are freaking me out like hell.

    opened by agjs 33
  • Added the ability to scanning directories singularly and recursively.

    Added the ability to scanning directories singularly and recursively.

    As a build step it's often useful to run a linter over your whole project and see what needs linting. I added the command line option -recursive to set recursive scanning and also added the requisite stuff for dealing with directories.

    opened by AeroNotix 33
  • should omit type uint32

    should omit type uint32

    should omit type uint32 from declaration of var flags; it will be inferred from the right-hand side

    This is technically incorrect, as type inference assumes int.

    This is similar to #7.

    The line in question is this ugly bit of code:

    var flags uint32 = syscall.IN_MOVED_TO | syscall.IN_MOVED_FROM |
        syscall.IN_CREATE | syscall.IN_ATTRIB | syscall.IN_MODIFY |
        syscall.IN_MOVE_SELF | syscall.IN_DELETE | syscall.IN_DELETE_SELF
    

    Note: I updated to latest to confirm that this is still an issue, ae65d273b9f43866a987aed78633d2c9ff1966ce.

    bug 
    opened by nathany 27
  • lint: avoid false positives with custom errors-package

    lint: avoid false positives with custom errors-package

    When using errors.New(fmt.Sprintf(...)), lint will alert that you should use fmt.Errorf(...).

    Before this patch, this alert was also displayed when using a custom errors-package. There are valid use cases to use errors.New(fmt.Sprintf(...)) in a custom errors-package context.

    This patch avoids the "false positive" alert when a custom errors-package is imported in the current file.

    Fixes golang/lint#350

    cla: yes 
    opened by leonelquinteros 25
  • Ignore `/vendor/` by default when linting

    Ignore `/vendor/` by default when linting

    I'd like to continue from #303. All credits go to @dvyukov's work.

    This PR will ignore /vendor/ by default when linting. But golint ./vendor/... will still lint that vendor directory normally.

    This'll fix #320 and fix #151.

    cla: yes 
    opened by lukyth 25
  • Where did golint go?

    Where did golint go?

    $ go get -u golang.org/x/lint/golint
    package golang.org/x/lint/golint: unrecognized import path "golang.org/x/lint/golint" (parse https://golang.org/x/lint/golint?go-get=1: no go-import meta tags ())
    

    Seeing this locally and from our ci server.

    opened by technoweenie 24
  • Master doesn't build anymore: undefined: types.NewInterface2

    Master doesn't build anymore: undefined: types.NewInterface2

    └> go get -u golang.org/x/lint/golint
    # golang.org/x/tools/go/internal/gcimporter
    Projects/Go/src/golang.org/x/tools/go/internal/gcimporter/bimport.go:541:8: undefined: types.NewInterface2
    Projects/Go/src/golang.org/x/tools/go/internal/gcimporter/iimport.go:540:10: undefined: types.NewInterface2
    
    opened by Soulou 22
  • Disable

    Disable "should have comment or be unexported" check

    Please delete the message should have comment or be unexported . This message will hurt my nerve in vscode and I'm not endearing these messages in my code yet.

    Whenever necessary, I add to my comment code and do not need to display this message. What is the reason why you decide for me and make sure you comment on the code?

    opened by aaaamirabbas 21
  • lint: analyze missing package comment globally

    lint: analyze missing package comment globally

    Fixes golang/lint#381

    This change analyses all files in the package upfront. It reports a single error if no valid package comment was found and at least one non-test file is present.

    Malformed package comments will still produce per-file errors, whether the missing package comment error is generated or not.

    Because this largely eliminates false positives, the confidence has been bumped to golint's default value of 0.8.

    cla: yes 
    opened by marcelocantos 21
Owner
Go
The Go Programming Language
Go
a simple golang SSA viewer tool use for code analysis or make a linter

ssaviewer A simple golang SSA viewer tool use for code analysis or make a linter ssa.html generate code modify from src/cmd/compile/internal/ssa/html.

null 7 May 17, 2022
Staticcheck - The advanced Go linter

The advanced Go linter Staticcheck is a state of the art linter for the Go programming language. Using static analysis, it finds bugs and performance

Dominik Honnef 5k Sep 26, 2022
A Go linter to check that errors from external packages are wrapped

Wrapcheck A simple Go linter to check that errors from external packages are wrapped during return to help identify the error source during debugging.

Tom Arrell 166 Sep 15, 2022
A linter that handles struct tags.

Tagliatelle A linter that handles struct tags. Supported string casing: camel pascal kebab snake goCamel Respects Go's common initialisms (e.g. HttpRe

Ludovic Fernandez 18 Aug 15, 2022
The Golang linter that checks that there is no simultaneous return of `nil` error and an invalid value.

nilnil Checks that there is no simultaneous return of nil error and an invalid value. Installation & usage $ go install github.com/Antonboom/[email protected]

Anton Telyshev 12 Aug 30, 2022
Go linter which checks for dangerous unicode character sequences

bidichk - checks for dangerous unicode character sequences bidichk finds dangerous unicode character sequences in Go source files. Considered dangerou

Lucas Bremgartner 24 Jul 5, 2022
Go linter that checks types that are json encoded - reports unsupported types and unnecessary error checks

Checks types passed to the json encoding functions. Reports unsupported types and reports occations, where the check for the returned error can be omited.

Lucas Bremgartner 26 Jun 17, 2022
Linter for PostgreSQL

Использование Проверить миграции: oh-my-pg-linter check ./migrations/*.sql Добавить директории с дополнительными проверками (переопределение - кто пос

Denis Kayumov 0 Nov 25, 2021
containedctx detects is a linter that detects struct contained context.Context field

containedctx containedctx detects is a linter that detects struct contained context.Context field Instruction go install github.com/sivchari/contained

sivchari 9 Jun 19, 2022
World's spookiest linter

nosleep The world's spookiest linter nosleep is a golang-ci compatible linter which checks for and fails if it detects usages of time.Sleep. Why did y

Elliot Williams 0 Jan 17, 2022
Go linter to analyze expression groups: require 'import' declaration groups

grouper — a Go linter to analyze expression groups Installation

null 0 Jun 19, 2022
funcresult — a Go linter to analyze function result parameters

Go linter to analyze function result parameters: require named / unnamed function result parameters

null 0 Jan 27, 2022
nostdglobals is a simple Go linter that checks for usages of global variables defined in the go standard library

nostdglobals is a simple Go linter that checks for usages of global variables defined in the go standard library

Nassos Kat 1 Feb 17, 2022
Goalinter-v1: Goa framework (version1) linter

goavl: Goa framework (ver1) linter goavlは、goa version1(フォーク版)のlinterです。開発目的は、goa

CHIKAMATSU Naohiro 1 Jul 28, 2022
Linter for Go's fmt.Errorf message

wrapmsg wrapmsg is Go code linter. this enforces fmt.Errorf's message when you wrap error. Example // OK ???? if err := pkg.Cause(); err != nil { re

Shinnosuke Sawada 9 Jul 4, 2022
misspelled word linter for Go comments, string literals and embedded files

gospel The gospel program lints Go source files for misspellings in comments, strings and embedded files. It uses hunspell to identify misspellings an

Dan Kortschak 30 Aug 6, 2022
octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

octocov is a tool for collecting code metrics (code coverage, code to test ratio and test execution time).

Ken’ichiro Oyama 130 Sep 22, 2022
[mirror] Performance measurement, storage, and analysis.

Go performance measurement, storage, and analysis tools This subrepository holds the source for various packages and tools related to performance meas

Go 319 Sep 23, 2022
depth is tool to retrieve and visualize Go source code dependency trees.

depth is tool to retrieve and visualize Go source code dependency trees. Install Download the appropriate binary for your platform from the Rele

Kyle Banks 784 Sep 25, 2022