Skip to content

Commit 9fccddc

Browse files
adonovangopherbot
authored andcommitted
go/analysis/unitchecker: add cfg.WarnDiagnostics
This flag, set by go vet and go fix but not go test, allows unitchecker to exit successfully even when it prints diagnostics, allowing the go command to cache its output. The legacy behavior remains in place for other build systems. Updates golang/go#71859 Change-Id: I4e025ef896fe191795e6bc4f284ab739dc3b6abc Reviewed-on: https://go-review.googlesource.com/c/tools/+/703995 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Michael Matloob <[email protected]> Auto-Submit: Alan Donovan <[email protected]> Reviewed-by: Michael Matloob <[email protected]>
1 parent 32f06e9 commit 9fccddc

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

go/analysis/unitchecker/unitchecker.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ type Config struct {
7474
VetxOnly bool // run analysis only for facts, not diagnostics
7575
VetxOutput string // where to write file of fact information
7676
Stdout string // write stdout (e.g. JSON, unified diff) to this file
77-
SucceedOnTypecheckFailure bool
77+
SucceedOnTypecheckFailure bool // obsolete awful hack; see #18395 and below
78+
WarnDiagnostics bool // printing diagnostics should not cause a non-zero exit
7879
}
7980

8081
// Main is the main function of a vet-like analysis tool that must be
@@ -162,7 +163,7 @@ func Run(configFile string, analyzers []*analysis.Analyzer) {
162163

163164
// In VetxOnly mode, the analysis is run only for facts.
164165
if !cfg.VetxOnly {
165-
code = processResults(fset, cfg.ID, results)
166+
code = processResults(fset, cfg.ID, results, cfg.WarnDiagnostics)
166167
}
167168

168169
os.Exit(code)
@@ -186,7 +187,7 @@ func readConfig(filename string) (*Config, error) {
186187
return cfg, nil
187188
}
188189

189-
func processResults(fset *token.FileSet, id string, results []result) (exit int) {
190+
func processResults(fset *token.FileSet, id string, results []result, warnDiagnostics bool) (exit int) {
190191
if analysisflags.Fix {
191192
// Don't print the diagnostics,
192193
// but apply all fixes from the root actions.
@@ -235,7 +236,9 @@ func processResults(fset *token.FileSet, id string, results []result) (exit int)
235236
for _, res := range results {
236237
for _, diag := range res.diagnostics {
237238
analysisflags.PrintPlain(os.Stderr, fset, analysisflags.Context, diag)
238-
exit = 1
239+
if !warnDiagnostics {
240+
exit = 1
241+
}
239242
}
240243
}
241244
}

0 commit comments

Comments
 (0)