| name | go-vet |
| description | Fix go vet warnings |
go vet
Built-in static analyzer that catches common mistakes.
Usage
go vet ./...
go vet ./pkg/...
Common Warnings
Printf Format Mismatch
fmt.Printf("%d", "string")
fmt.Printf("%s", "string")
Unreachable Code
return value
fmt.Println("never runs")
fmt.Println("runs")
return value
Composite Literal Uses Unkeyed Fields
Person{"Alice", 30}
Person{Name: "Alice", Age: 30}
Nil Dereference
var p *int
fmt.Println(*p)
if p != nil {
fmt.Println(*p)
}
Suspicious Mutex Usage
func process(mu sync.Mutex) {
mu.Lock()
}
func process(mu *sync.Mutex) {
mu.Lock()
}
Lost Context
ctx := context.TODO()
ctx := context.Background()
Fix All Issues
go vet ./... 2>&1 | tee vet.log