]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: support workspaces in vet
authorMichael Matloob <matloob@golang.org>
Fri, 11 Feb 2022 17:01:34 +0000 (12:01 -0500)
committerMichael Matloob <matloob@golang.org>
Fri, 11 Feb 2022 18:50:49 +0000 (18:50 +0000)
Add modload.InitWorkfile to runVet so that the vet command recognizes
and uses the workspace.

Fixes #51072

Change-Id: Ia6727eff9b80eb33627f5ae23e4d72cde581e75f
Reviewed-on: https://go-review.googlesource.com/c/go/+/385176
Trust: Michael Matloob <matloob@golang.org>
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/vet/vet.go
src/cmd/go/testdata/script/work_vet.txt [new file with mode: 0644]

index 88b3c570a03b5c52328eaf745dc795d86174c830..d3e0dd8116f481ef4d8e72e5c467a75110cde9bc 100644 (file)
@@ -13,6 +13,7 @@ import (
        "cmd/go/internal/base"
        "cmd/go/internal/cfg"
        "cmd/go/internal/load"
+       "cmd/go/internal/modload"
        "cmd/go/internal/trace"
        "cmd/go/internal/work"
 )
@@ -54,6 +55,7 @@ See also: go fmt, go fix.
 
 func runVet(ctx context.Context, cmd *base.Command, args []string) {
        vetFlags, pkgArgs := vetFlags(args)
+       modload.InitWorkfile() // The vet command does custom flag processing; initialize workspaces after that.
 
        if cfg.DebugTrace != "" {
                var close func() error
diff --git a/src/cmd/go/testdata/script/work_vet.txt b/src/cmd/go/testdata/script/work_vet.txt
new file mode 100644 (file)
index 0000000..e258fc0
--- /dev/null
@@ -0,0 +1,19 @@
+! go vet ./a
+stderr 'fmt.Println call has possible formatting directive'
+
+-- go.work --
+go 1.18
+
+use ./a
+-- a/go.mod --
+module example.com/a
+
+go 1.18
+-- a/a.go --
+package a
+
+import "fmt"
+
+func A() {
+    fmt.Println("%s")
+}
\ No newline at end of file