diff options
| author | Jonathan Amsterdam <jba@google.com> | 2023-05-16 13:47:46 -0400 |
|---|---|---|
| committer | Jonathan Amsterdam <jba@google.com> | 2023-05-22 18:11:19 +0000 |
| commit | 6d4d71c5abe104d95ede3aa2f3eaaef7bc613ebb (patch) | |
| tree | ea9311746e2420678a1af7a763dfc724c044b0c6 /src/cmd/vet | |
| parent | 1cfacfbe8ae7ed12eb798c84b53e1ebd0e3ed0b0 (diff) | |
| download | go-6d4d71c5abe104d95ede3aa2f3eaaef7bc613ebb.tar.xz | |
cmd/vet: add slog checker
Add the slog static analysis pass to `go vet`.
Vendor in golang.org/x/tools@master to pick up the pass.
Tweak a test in slog to avoid triggering the vet check.
Change-Id: I55ceac9a4e6876c8385897784542761ea0af2481
Reviewed-on: https://go-review.googlesource.com/c/go/+/496156
Reviewed-by: Alan Donovan <adonovan@google.com>
Run-TryBot: Jonathan Amsterdam <jba@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/vet')
| -rw-r--r-- | src/cmd/vet/doc.go | 1 | ||||
| -rw-r--r-- | src/cmd/vet/main.go | 2 | ||||
| -rw-r--r-- | src/cmd/vet/testdata/slog/slog.go | 13 | ||||
| -rw-r--r-- | src/cmd/vet/vet_test.go | 1 |
4 files changed, 17 insertions, 0 deletions
diff --git a/src/cmd/vet/doc.go b/src/cmd/vet/doc.go index e230d3be06..ba5b5ed967 100644 --- a/src/cmd/vet/doc.go +++ b/src/cmd/vet/doc.go @@ -41,6 +41,7 @@ To list the available checks, run "go tool vet help": nilfunc check for useless comparisons between functions and nil printf check consistency of Printf format strings and arguments shift check for shifts that equal or exceed the width of the integer + slog check for incorrect arguments to log/slog functions stdmethods check signature of methods of well-known interfaces structtag check that struct field tags conform to reflect.StructTag.Get tests check for common mistaken usages of tests and examples diff --git a/src/cmd/vet/main.go b/src/cmd/vet/main.go index 0bcee78b97..a90758f823 100644 --- a/src/cmd/vet/main.go +++ b/src/cmd/vet/main.go @@ -28,6 +28,7 @@ import ( "golang.org/x/tools/go/analysis/passes/printf" "golang.org/x/tools/go/analysis/passes/shift" "golang.org/x/tools/go/analysis/passes/sigchanyzer" + "golang.org/x/tools/go/analysis/passes/slog" "golang.org/x/tools/go/analysis/passes/stdmethods" "golang.org/x/tools/go/analysis/passes/stringintconv" "golang.org/x/tools/go/analysis/passes/structtag" @@ -63,6 +64,7 @@ func main() { printf.Analyzer, shift.Analyzer, sigchanyzer.Analyzer, + slog.Analyzer, stdmethods.Analyzer, stringintconv.Analyzer, structtag.Analyzer, diff --git a/src/cmd/vet/testdata/slog/slog.go b/src/cmd/vet/testdata/slog/slog.go new file mode 100644 index 0000000000..accb04361b --- /dev/null +++ b/src/cmd/vet/testdata/slog/slog.go @@ -0,0 +1,13 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// This file contains tests for the slog checker. + +package slog + +import "log/slog" + +func SlogTest() { + slog.Info("msg", "a") // ERROR "call to slog.Info missing a final value" +} diff --git a/src/cmd/vet/vet_test.go b/src/cmd/vet/vet_test.go index fca9cac8c2..8b29907e81 100644 --- a/src/cmd/vet/vet_test.go +++ b/src/cmd/vet/vet_test.go @@ -79,6 +79,7 @@ func TestVet(t *testing.T) { "print", "rangeloop", "shift", + "slog", "structtag", "testingpkg", // "testtag" has its own test |
