aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/vet
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/vet')
-rw-r--r--src/cmd/vet/doc.go1
-rw-r--r--src/cmd/vet/main.go2
-rw-r--r--src/cmd/vet/testdata/slog/slog.go13
-rw-r--r--src/cmd/vet/vet_test.go1
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