]> Cypherpunks repositories - gostls13.git/commit
cmd/go: unify "go fix" and "go vet"
authorAlan Donovan <adonovan@google.com>
Fri, 26 Sep 2025 17:33:09 +0000 (13:33 -0400)
committerAlan Donovan <adonovan@google.com>
Fri, 10 Oct 2025 20:10:21 +0000 (13:10 -0700)
commit6f4c63ba63fdec6e4a42e2e19ac71937973dedef
tree07de0c3fbb30da98e2f5ad260b06d1a7110449b6
parent955a5a0dc5dd68ed89200a08f17590c0a94c1e09
cmd/go: unify "go fix" and "go vet"

This change unifies the fix and vet subcommands; they use the
same run function, action graph, and external tool (-vettool
for go vet and -fixtool for go fix). go fix runs the tool
with the -fix flag, whereas although go vet also supports
-fix, it is not the default. The two tools have different
(overlapping) suites of analyzers.

The high-level parts are fully parameterized over the
vet/fix distinction; the lower-level parts (the action
graph) continue to use only the "vet" terminology.
The cmd/{vet,fix} executable is referred to as the "tool".

The tool is generally invoked in -json mode, regardless
of whether -json was requested, so that the tool produces
a cacheable JSON blob on stdout. When the go user did not
request -json, this blob is parsed and printed to stderr
by logic in the go vet command. (Formerly the tool would
print diagnostics to stderr, but this interacts poorly
with the build cache.)

go fix's legacy -fix=fixer,... flag is now a no-op that
prints a warning that the flag is obsolete.

The unitchecker's -c=n flag (to display n lines of context
around each diagnostic) is reimplemented in go vet based
on the JSON information, to avoid reliance on the stderr
output of the tool.

cmd/fix is added to dist's prebuilt set of tools since
go fix cannot build it dynamically (though ideally
it would).

Updates #71859
For #75432

Change-Id: I0a84746720b59d05d662ed57826747c5598dca44
Reviewed-on: https://go-review.googlesource.com/c/go/+/700795
Reviewed-by: Michael Matloob <matloob@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
TryBot-Bypass: Alan Donovan <adonovan@google.com>
20 files changed:
doc/next/3-tools.md
src/cmd/dist/build.go
src/cmd/fix/doc.go [deleted file]
src/cmd/fix/main.go
src/cmd/go/alldocs.go
src/cmd/go/internal/fix/fix.go [deleted file]
src/cmd/go/internal/test/test.go
src/cmd/go/internal/vet/vet.go
src/cmd/go/internal/vet/vetflag.go
src/cmd/go/internal/work/buildid.go
src/cmd/go/internal/work/exec.go
src/cmd/go/main.go
src/cmd/go/testdata/script/chdir.txt
src/cmd/go/testdata/script/vet_asm.txt
src/cmd/go/testdata/script/vet_basic.txt [new file with mode: 0644]
src/cmd/go/testdata/script/vet_cache.txt [new file with mode: 0644]
src/cmd/vet/doc.go
src/cmd/vet/main.go
src/cmd/vet/testdata/print/print.go
src/cmd/vet/vet_test.go