Skip to content

Commit 4321df7

Browse files
adonovangopherbot
authored andcommitted
go/analysis/unitchecker: minor cleanups
- Update documentation of go vet <-> unitchecker protocol. The GOVET env. var. was abolished. - Relax versiontest to allow for the possibility of a suffix after each diagnostic message. - Remove the WarnDiagnostics bool from the .cfg file; it was obviated by the decision for go vet to always supply the -json flag and print diagnostics (and exit nonzero) itself. Updates golang/go#71859 Change-Id: I40351bb3b1f81cf80adbf3bc6eb7dd08002d2008 Reviewed-on: https://go-review.googlesource.com/c/tools/+/710615 Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Michael Matloob <matloob@google.com> Reviewed-by: Michael Matloob <matloob@golang.org>
1 parent 96d2e44 commit 4321df7

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

go/analysis/internal/versiontest/version_test.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestMultichecker(t *testing.T) {
7171
cmd.Dir = testDir(t)
7272
cmd.Env = append(os.Environ(), "VERSIONTEST_MULTICHECKER=1")
7373
out, err := cmd.CombinedOutput()
74-
if err == nil || !strings.Contains(string(out), "x.go:1:1: goversion=go1.20\n") {
74+
if err == nil || !strings.Contains(string(out), "x.go:1:1: goversion=go1.20") {
7575
t.Fatalf("multichecker: %v\n%s", err, out)
7676
}
7777
}
@@ -87,7 +87,7 @@ func TestSinglechecker(t *testing.T) {
8787
cmd.Dir = testDir(t)
8888
cmd.Env = append(os.Environ(), "VERSIONTEST_SINGLECHECKER=1")
8989
out, err := cmd.CombinedOutput()
90-
if err == nil || !strings.Contains(string(out), "x.go:1:1: goversion=go1.20\n") {
90+
if err == nil || !strings.Contains(string(out), "x.go:1:1: goversion=go1.20") {
9191
t.Fatalf("multichecker: %v\n%s", err, out)
9292
}
9393
}
@@ -103,12 +103,7 @@ func TestVettool(t *testing.T) {
103103
cmd.Dir = testDir(t)
104104
cmd.Env = append(os.Environ(), "VERSIONTEST_MULTICHECKER=1")
105105
out, err := cmd.CombinedOutput()
106-
if err != nil {
107-
// Before go1.25, vet exited nonzero after printing diagnostics.
108-
// TODO(adonovan): when go1.25 is assured, assert err == nil.
109-
t.Logf("go vet: %v", err)
110-
}
111-
if !strings.Contains(string(out), "x.go:1:1: goversion=go1.20\n") {
106+
if err == nil || !strings.Contains(string(out), "x.go:1:1: goversion=go1.20") {
112107
t.Fatalf("vettool: %v\n%s", err, out)
113108
}
114109
}

go/analysis/unitchecker/unitchecker.go

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type Config struct {
7575
VetxOutput string // where to write file of fact information
7676
Stdout string // write stdout (e.g. JSON, unified diff) to this file
7777
SucceedOnTypecheckFailure bool // obsolete awful hack; see #18395 and below
78-
WarnDiagnostics bool // printing diagnostics should not cause a non-zero exit
7978
}
8079

8180
// Main is the main function of a vet-like analysis tool that must be
@@ -87,18 +86,9 @@ type Config struct {
8786
// -V=full describe executable for build caching
8887
// foo.cfg perform separate modular analyze on the single
8988
// unit described by a JSON config file foo.cfg.
90-
//
91-
// Also, subject to approval of proposal #71859:
92-
//
9389
// -fix don't print each diagnostic, apply its first fix
9490
// -diff don't apply a fix, print the diff (requires -fix)
95-
//
96-
// Additionally, the environment variable GOVET has the value "vet" or
97-
// "fix" depending on whether the command is being invoked by "go vet",
98-
// to report diagnostics, or "go fix", to apply fixes. This is
99-
// necessary so that callers of Main can select their analyzer suite
100-
// before flag parsing. (Vet analyzers must report real code problems,
101-
// whereas Fix analyzers may fix non-problems such as style issues.)
91+
// -json print diagnostics and fixes in JSON form
10292
func Main(analyzers ...*analysis.Analyzer) {
10393
progname := filepath.Base(os.Args[0])
10494
log.SetFlags(0)
@@ -163,7 +153,7 @@ func Run(configFile string, analyzers []*analysis.Analyzer) {
163153

164154
// In VetxOnly mode, the analysis is run only for facts.
165155
if !cfg.VetxOnly {
166-
code = processResults(fset, cfg.ID, results, cfg.WarnDiagnostics)
156+
code = processResults(fset, cfg.ID, results)
167157
}
168158

169159
os.Exit(code)
@@ -187,7 +177,7 @@ func readConfig(filename string) (*Config, error) {
187177
return cfg, nil
188178
}
189179

190-
func processResults(fset *token.FileSet, id string, results []result, warnDiagnostics bool) (exit int) {
180+
func processResults(fset *token.FileSet, id string, results []result) (exit int) {
191181
if analysisflags.Fix {
192182
// Don't print the diagnostics,
193183
// but apply all fixes from the root actions.
@@ -236,9 +226,7 @@ func processResults(fset *token.FileSet, id string, results []result, warnDiagno
236226
for _, res := range results {
237227
for _, diag := range res.diagnostics {
238228
analysisflags.PrintPlain(os.Stderr, fset, analysisflags.Context, diag)
239-
if !warnDiagnostics {
240-
exit = 1
241-
}
229+
exit = 1
242230
}
243231
}
244232
}

0 commit comments

Comments
 (0)