Knaph

staticcheck

Vet's narrowness leaves a lot on the table. staticcheck is the other well-known Go analyzer: well over a hundred checks, still tuned hard against false positives, but willing to flag things vet considers out of scope.

go install honnef.co/go/tools/cmd/staticcheck@latest
staticcheck ./...

Here's a bug vet misses entirely:

package main
 
import (
	"fmt"
	"strings"
)
 
func main() {
	name := "  Haleh  "
	strings.TrimSpace(name)
	fmt.Println("hello, " + name + "!")
}
hello,   Haleh  !

go vet ./... reports nothing. staticcheck ./... reports:

main.go:10:2: TrimSpace doesn't have side effects and its return value is ignored (SA4017)

Go strings are immutable, so strings.TrimSpace hands you a new string rather than editing the one you passed in. Throw the return value away and the call accomplished nothing at all:

Before
name := "  Haleh  "
strings.TrimSpace(name)
fmt.Println("hello, " + name + "!")
After
name := "  Haleh  "
name = strings.TrimSpace(name)
fmt.Println("hello, " + name + "!")

Every finding carries a stable code, and its prefix tells you the kind: SA is a likely bug, S1 a simplification, ST a style convention. The code is what you cite to silence one deliberately — //lint:ignore SA4017 <reason> on the line above — and staticcheck requires that reason.

One piece of history, because you'll trip over it: if you find golint recommended in an old blog post or Stack Overflow answer, skip it. It was deprecated and frozen in 2021, and its own README now points at go vet and staticcheck instead.

Sign in to track your progress through this course.

Ask an AI

Open a ready-made prompt in ChatGPT or Claude — just press Enter.

SummarizeChatGPTClaude
Ask me questionsChatGPTClaude
Let's learn togetherChatGPTClaude