Golang lint and go vet: golangci-lint, formatting, and nolint:gosec

Golang linting with go vet and golangci-lint; go lint command meaning versus go vet; golang linter setup; nolint:gosec and targeted nolint directives; gofmt goimports; golint deprecated.

Published

Updated

Read time 3 min read

Reviewed byDeepak Prasad

Golang lint and go vet: golangci-lint, formatting, and nolint:gosec

Searches for golang lint, golang linter, golang linting, go linter, go linting, golanglint, go lint, go lint command, linter golang, and nolint:gosec usually mean one of three things: run the go vet analyzer that ships with Go, run a meta-linter such as golangci-lint, or suppress a specific finding (often from gosec) with a //nolint comment. This page separates vetting, formatting (gofmt / goimports), and inline directives, and notes that golint is deprecated. For tabs and style details, see Go formatting.

Tested with Go 1.24 on Linux.


go lint, go vet, and golang lint

  • go vet ./... — built into the Go toolchain; catches many real mistakes (Printf format mismatches, wrong struct tags, unreachable code).
  • golangci-lint run — community meta-linter that runs many analyzers with caching and config files (common answer for golang lint in larger repos).
  • staticcheck ./... — high-signal analyzer suite (go install honnef.co/go/tools/cmd/staticcheck@latest).
  • golint — deprecated; do not add it to new workflows (deprecation discussion).

There is no official go lint subcommand in the same sense as go test; when docs say “go lint” they usually mean one of the tools above.


go vet example

go vet flags format-string mistakes the compiler allows:

go
package main

import "fmt"

func main() {
	name := "Anna"
	score := 99.5
	fmt.Printf("%s got %s points in the Maths exam\n", name, score)
}
Output
bash
go vet ./...
text
./main.go:7:2: fmt.Printf format %s has arg score of wrong type float64

Fix the verb (%v or %f) instead of silencing the report.


gofmt and goimports (formatting, not lint)

gofmt applies standard formatting. goimports formats like gofmt and fixes import lines. Shell examples:

bash
gofmt -w .
goimports -w .

golangci-lint (golanglint-style workflow)

Install a release that matches your Go version (newer golangci-lint releases may require a newer toolchain than your module). The maintainers document binary installs and shell-based installers here: local installation. If you use go install, the v2 module path looks like:

bash
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.X.Y

Run from the module root:

bash
golangci-lint run ./...

Configuration lives in .golangci.yml, .golangci.yaml, .golangci.toml, or .golangci.json (see configuration). Start from a small enabled set (for example govet, errcheck, staticcheck) and grow deliberately—avoid copy-pasting huge enable/disable lists that contradict each other.


nolint directives and nolint:gosec

//nolint tells golangci-lint (and compatible tools) to skip issues on the next line (or the whole file if used as a file header). Prefer linter-specific suppressions.

//nolint:gosec limits the suppression to gosec findings—for example weak randomness from math/rand in non-crypto code:

go
package main

import (
	"fmt"
	"math/rand"
)

func main() {
	//nolint:gosec // demo only; use crypto/rand for secrets
	fmt.Println(rand.Int())
}
Output

A bare //nolint silences every linter on that line; use it rarely. File-level //nolint:govet,errcheck is possible but hides a lot—prefer config issues.exclude-rules for broad, reviewed exceptions.


Summary

Golang lint in 2026 usually means go vet plus golangci-lint run (and often staticcheck), not golint. The phrase go lint is not a first-class subcommand—clarify that when onboarding. //nolint:gosec is the targeted escape hatch for gosec noise; pair it with a short reason and keep formatting (gofmt, goimports) separate from analysis.


References


Frequently Asked Questions

1. Is there a go lint command in the Go toolchain?

There is no official go lint subcommand bundled like go vet. People saying go lint often mean go vet, golangci-lint run, staticcheck, or the deprecated golint tool.

2. What does nolint:gosec mean?

It is an end-of-line directive read by golangci-lint (and similar drivers) telling the gosec security linter to ignore findings on that line. Prefer //nolint:gosec with a short justification instead of a bare //nolint that silences every linter.

3. What is the difference between golang linting and gofmt?

gofmt and goimports change layout and imports; they do not deeply analyze bugs. go vet and golangci-lint report suspicious or policy issues without rewriting your logic.

4. Is golint still recommended?

No. golint is frozen and deprecated; use staticcheck, go vet, or golangci-lint presets instead.
Tuan Nguyen

Data Scientist

Proficient in Golang, Python, Java, MongoDB, Selenium, Spring Boot, Kubernetes, Scrapy, API development, Docker, Data Scraping, PrimeFaces, Linux, Data Structures, and Data Mining. With expertise …