mirror of
https://github.com/golang/go.git
synced 2026-06-27 19:30:52 +00:00
cmd/{vet,fix}: use new constants from /x/tools/go/analysis/suite
This change causes the vet and fix tools to take their inventory of analyzers from the published suite constants in x/tools. This will make it easier for others to make their own tools that track these suites with minor variations. Also, vendor x/tools@6923890 (master). For #35487 Change-Id: Iafcd256999cc98caa40ad60a463182abd892dc27 Reviewed-on: https://go-review.googlesource.com/c/go/+/780900 Reviewed-by: Mark Freeman <markfreeman@google.com> Auto-Submit: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
parent
60f0ced65b
commit
1bcea1df64
7 changed files with 153 additions and 112 deletions
|
|
@ -22,13 +22,8 @@ package main
|
|||
import (
|
||||
"cmd/internal/objabi"
|
||||
"cmd/internal/telemetry/counter"
|
||||
"slices"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
"golang.org/x/tools/go/analysis/passes/buildtag"
|
||||
"golang.org/x/tools/go/analysis/passes/hostport"
|
||||
"golang.org/x/tools/go/analysis/passes/inline"
|
||||
"golang.org/x/tools/go/analysis/passes/modernize"
|
||||
"golang.org/x/tools/go/analysis/suite/fix"
|
||||
"golang.org/x/tools/go/analysis/unitchecker"
|
||||
)
|
||||
|
||||
|
|
@ -38,26 +33,5 @@ func main() {
|
|||
objabi.AddVersionFlag()
|
||||
counter.Inc("fix/invocations")
|
||||
|
||||
unitchecker.Main(suite...) // (never returns)
|
||||
unitchecker.Main(fix.Suite...) // (never returns)
|
||||
}
|
||||
|
||||
// The fix suite analyzers produce fixes are unambiguously safe to apply,
|
||||
// even if the diagnostics might not describe actual problems.
|
||||
var suite = slices.Concat(
|
||||
[]*analysis.Analyzer{
|
||||
buildtag.Analyzer,
|
||||
hostport.Analyzer,
|
||||
inline.Analyzer,
|
||||
},
|
||||
modernize.Suite,
|
||||
// TODO(adonovan): add any other vet analyzers whose fixes are always safe.
|
||||
// Candidates to audit: sigchanyzer, printf, assign, unreachable.
|
||||
// Many of staticcheck's analyzers would make good candidates
|
||||
// (e.g. rewriting WriteString(fmt.Sprintf()) to Fprintf.)
|
||||
// Rejected:
|
||||
// - composites: some types (e.g. PointXY{1,2}) don't want field names.
|
||||
// - timeformat: flipping MM/DD is a behavior change, but the code
|
||||
// could potentially be a workaround for another bug.
|
||||
// - stringintconv: offers two fixes, user input required to choose.
|
||||
// - fieldalignment: poor signal/noise; fix could be a regression.
|
||||
)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ require (
|
|||
golang.org/x/sys v0.44.0
|
||||
golang.org/x/telemetry v0.0.0-20260508192327-42602be52be6
|
||||
golang.org/x/term v0.39.0
|
||||
golang.org/x/tools v0.45.1-0.20260520205638-b38156a7a9f5
|
||||
golang.org/x/tools v0.45.1-0.20260520211234-69238901bf50
|
||||
)
|
||||
|
||||
require (
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ golang.org/x/term v0.39.0 h1:RclSuaJf32jOqZz74CkPA9qFuVTX7vhLlpfj/IGWlqY=
|
|||
golang.org/x/term v0.39.0/go.mod h1:yxzUCTP/U+FzoxfdKmLaA0RV1WgE0VY7hXBwKtY/4ww=
|
||||
golang.org/x/text v0.37.0 h1:Cqjiwd9eSg8e0QAkyCaQTNHFIIzWtidPahFWR83rTrc=
|
||||
golang.org/x/text v0.37.0/go.mod h1:a5sjxXGs9hsn/AJVwuElvCAo9v8QYLzvavO5z2PiM38=
|
||||
golang.org/x/tools v0.45.1-0.20260520205638-b38156a7a9f5 h1:jqdNq3qAaJT9zQL5Cbq/TRYEdoLZmystI2hoCyAsAuw=
|
||||
golang.org/x/tools v0.45.1-0.20260520205638-b38156a7a9f5/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
|
||||
golang.org/x/tools v0.45.1-0.20260520211234-69238901bf50 h1:IAxGea+Jam/B7I2Pg6Gc+ooeN74JYZv+2bhgGGqB2aw=
|
||||
golang.org/x/tools v0.45.1-0.20260520211234-69238901bf50/go.mod h1:LuUGqqaXcXMEFEruIVJVm5mgDD8vww/z/SR1gQ4uE/0=
|
||||
rsc.io/markdown v0.0.0-20240306144322-0bf8f97ee8ef h1:mqLYrXCXYEZOop9/Dbo6RPX11539nwiCNBb1icVPmw8=
|
||||
rsc.io/markdown v0.0.0-20240306144322-0bf8f97ee8ef/go.mod h1:8xcPgWmwlZONN1D9bjxtHEjrUtSEa3fakVF8iaewYKQ=
|
||||
|
|
|
|||
46
src/cmd/vendor/golang.org/x/tools/go/analysis/suite/fix/fix.go
generated
vendored
Normal file
46
src/cmd/vendor/golang.org/x/tools/go/analysis/suite/fix/fix.go
generated
vendored
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
// Copyright 2026 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.
|
||||
|
||||
// The fix package defines the suite of analyzers used by cmd/fix,
|
||||
// the default analysis tool run by "go fix".
|
||||
// Its behavior is equivalent to:
|
||||
//
|
||||
// func main() { unitchecker.Main(fix.Suite...) }
|
||||
//
|
||||
// If you need a different suite, define your own tool
|
||||
// and run "go vet -vettool=mytool".
|
||||
package fix
|
||||
|
||||
import (
|
||||
"slices"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
"golang.org/x/tools/go/analysis/passes/buildtag"
|
||||
"golang.org/x/tools/go/analysis/passes/hostport"
|
||||
"golang.org/x/tools/go/analysis/passes/inline"
|
||||
"golang.org/x/tools/go/analysis/passes/modernize"
|
||||
)
|
||||
|
||||
// Suite is the suite of analyzers run by cmd/fix.
|
||||
//
|
||||
// The fix suite analyzers produce fixes are unambiguously safe to apply,
|
||||
// even if the diagnostics might not describe actual problems.
|
||||
var Suite = slices.Concat(
|
||||
[]*analysis.Analyzer{
|
||||
buildtag.Analyzer,
|
||||
hostport.Analyzer,
|
||||
inline.Analyzer,
|
||||
},
|
||||
modernize.Suite,
|
||||
// TODO(adonovan): add any other vet analyzers whose fixes are always safe.
|
||||
// Candidates to audit: sigchanyzer, printf, assign, unreachable.
|
||||
// Many of staticcheck's analyzers would make good candidates
|
||||
// (e.g. rewriting WriteString(fmt.Sprintf()) to Fprintf.)
|
||||
// Rejected:
|
||||
// - composites: some types (e.g. PointXY{1,2}) don't want field names.
|
||||
// - timeformat: flipping MM/DD is a behavior change, but the code
|
||||
// could potentially be a workaround for another bug.
|
||||
// - stringintconv: offers two fixes, user input required to choose.
|
||||
// - fieldalignment: poor signal/noise; fix could be a regression.
|
||||
)
|
||||
97
src/cmd/vendor/golang.org/x/tools/go/analysis/suite/vet/vet.go
generated
vendored
Normal file
97
src/cmd/vendor/golang.org/x/tools/go/analysis/suite/vet/vet.go
generated
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// Copyright 2026 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.
|
||||
|
||||
// The vet package defines the suite of analyzers used by cmd/vet,
|
||||
// the default analysis tool run by "go vet".
|
||||
// Its behavior is equivalent to:
|
||||
//
|
||||
// func main() { unitchecker.Main(vet.Suite...) }
|
||||
//
|
||||
// If you need a different suite, define your own tool
|
||||
// and run "go vet -vettool=mytool".
|
||||
package vet
|
||||
|
||||
import (
|
||||
"golang.org/x/tools/go/analysis"
|
||||
"golang.org/x/tools/go/analysis/passes/appends"
|
||||
"golang.org/x/tools/go/analysis/passes/asmdecl"
|
||||
"golang.org/x/tools/go/analysis/passes/assign"
|
||||
"golang.org/x/tools/go/analysis/passes/atomic"
|
||||
"golang.org/x/tools/go/analysis/passes/bools"
|
||||
"golang.org/x/tools/go/analysis/passes/buildtag"
|
||||
"golang.org/x/tools/go/analysis/passes/cgocall"
|
||||
"golang.org/x/tools/go/analysis/passes/composite"
|
||||
"golang.org/x/tools/go/analysis/passes/copylock"
|
||||
"golang.org/x/tools/go/analysis/passes/defers"
|
||||
"golang.org/x/tools/go/analysis/passes/directive"
|
||||
"golang.org/x/tools/go/analysis/passes/errorsas"
|
||||
"golang.org/x/tools/go/analysis/passes/framepointer"
|
||||
"golang.org/x/tools/go/analysis/passes/hostport"
|
||||
"golang.org/x/tools/go/analysis/passes/httpresponse"
|
||||
"golang.org/x/tools/go/analysis/passes/ifaceassert"
|
||||
"golang.org/x/tools/go/analysis/passes/loopclosure"
|
||||
"golang.org/x/tools/go/analysis/passes/lostcancel"
|
||||
"golang.org/x/tools/go/analysis/passes/nilfunc"
|
||||
"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/stdversion"
|
||||
"golang.org/x/tools/go/analysis/passes/stringintconv"
|
||||
"golang.org/x/tools/go/analysis/passes/structtag"
|
||||
"golang.org/x/tools/go/analysis/passes/testinggoroutine"
|
||||
"golang.org/x/tools/go/analysis/passes/tests"
|
||||
"golang.org/x/tools/go/analysis/passes/timeformat"
|
||||
"golang.org/x/tools/go/analysis/passes/unmarshal"
|
||||
"golang.org/x/tools/go/analysis/passes/unreachable"
|
||||
"golang.org/x/tools/go/analysis/passes/unsafeptr"
|
||||
"golang.org/x/tools/go/analysis/passes/unusedresult"
|
||||
"golang.org/x/tools/go/analysis/passes/waitgroup"
|
||||
)
|
||||
|
||||
// Suite is the suite of analyzers run by cmd/vet.
|
||||
//
|
||||
// The vet suite analyzers report diagnostics.
|
||||
// (Diagnostics must describe real problems, but need not
|
||||
// suggest fixes, and fixes are not necessarily safe to apply.)
|
||||
var Suite = []*analysis.Analyzer{
|
||||
appends.Analyzer,
|
||||
asmdecl.Analyzer,
|
||||
assign.Analyzer,
|
||||
atomic.Analyzer,
|
||||
bools.Analyzer,
|
||||
buildtag.Analyzer,
|
||||
cgocall.Analyzer,
|
||||
composite.Analyzer,
|
||||
copylock.Analyzer,
|
||||
defers.Analyzer,
|
||||
directive.Analyzer,
|
||||
errorsas.Analyzer,
|
||||
// fieldalignment.Analyzer omitted: too noisy
|
||||
framepointer.Analyzer,
|
||||
httpresponse.Analyzer,
|
||||
hostport.Analyzer,
|
||||
ifaceassert.Analyzer,
|
||||
loopclosure.Analyzer,
|
||||
lostcancel.Analyzer,
|
||||
nilfunc.Analyzer,
|
||||
printf.Analyzer,
|
||||
// shadow.Analyzer omitted: too noisy
|
||||
shift.Analyzer,
|
||||
sigchanyzer.Analyzer,
|
||||
slog.Analyzer,
|
||||
stdmethods.Analyzer,
|
||||
stdversion.Analyzer,
|
||||
stringintconv.Analyzer,
|
||||
structtag.Analyzer,
|
||||
tests.Analyzer,
|
||||
testinggoroutine.Analyzer,
|
||||
timeformat.Analyzer,
|
||||
unmarshal.Analyzer,
|
||||
unreachable.Analyzer,
|
||||
unsafeptr.Analyzer,
|
||||
unusedresult.Analyzer,
|
||||
waitgroup.Analyzer,
|
||||
}
|
||||
4
src/cmd/vendor/modules.txt
vendored
4
src/cmd/vendor/modules.txt
vendored
|
|
@ -73,7 +73,7 @@ golang.org/x/text/internal/tag
|
|||
golang.org/x/text/language
|
||||
golang.org/x/text/transform
|
||||
golang.org/x/text/unicode/norm
|
||||
# golang.org/x/tools v0.45.1-0.20260520205638-b38156a7a9f5
|
||||
# golang.org/x/tools v0.45.1-0.20260520211234-69238901bf50
|
||||
## explicit; go 1.25.0
|
||||
golang.org/x/tools/cmd/bisect
|
||||
golang.org/x/tools/cover
|
||||
|
|
@ -119,6 +119,8 @@ golang.org/x/tools/go/analysis/passes/unreachable
|
|||
golang.org/x/tools/go/analysis/passes/unsafeptr
|
||||
golang.org/x/tools/go/analysis/passes/unusedresult
|
||||
golang.org/x/tools/go/analysis/passes/waitgroup
|
||||
golang.org/x/tools/go/analysis/suite/fix
|
||||
golang.org/x/tools/go/analysis/suite/vet
|
||||
golang.org/x/tools/go/analysis/unitchecker
|
||||
golang.org/x/tools/go/ast/astutil
|
||||
golang.org/x/tools/go/ast/edge
|
||||
|
|
|
|||
|
|
@ -8,42 +8,7 @@ import (
|
|||
"cmd/internal/objabi"
|
||||
"cmd/internal/telemetry/counter"
|
||||
|
||||
"golang.org/x/tools/go/analysis"
|
||||
"golang.org/x/tools/go/analysis/passes/appends"
|
||||
"golang.org/x/tools/go/analysis/passes/asmdecl"
|
||||
"golang.org/x/tools/go/analysis/passes/assign"
|
||||
"golang.org/x/tools/go/analysis/passes/atomic"
|
||||
"golang.org/x/tools/go/analysis/passes/bools"
|
||||
"golang.org/x/tools/go/analysis/passes/buildtag"
|
||||
"golang.org/x/tools/go/analysis/passes/cgocall"
|
||||
"golang.org/x/tools/go/analysis/passes/composite"
|
||||
"golang.org/x/tools/go/analysis/passes/copylock"
|
||||
"golang.org/x/tools/go/analysis/passes/defers"
|
||||
"golang.org/x/tools/go/analysis/passes/directive"
|
||||
"golang.org/x/tools/go/analysis/passes/errorsas"
|
||||
"golang.org/x/tools/go/analysis/passes/framepointer"
|
||||
"golang.org/x/tools/go/analysis/passes/hostport"
|
||||
"golang.org/x/tools/go/analysis/passes/httpresponse"
|
||||
"golang.org/x/tools/go/analysis/passes/ifaceassert"
|
||||
"golang.org/x/tools/go/analysis/passes/loopclosure"
|
||||
"golang.org/x/tools/go/analysis/passes/lostcancel"
|
||||
"golang.org/x/tools/go/analysis/passes/nilfunc"
|
||||
"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/stdversion"
|
||||
"golang.org/x/tools/go/analysis/passes/stringintconv"
|
||||
"golang.org/x/tools/go/analysis/passes/structtag"
|
||||
"golang.org/x/tools/go/analysis/passes/testinggoroutine"
|
||||
"golang.org/x/tools/go/analysis/passes/tests"
|
||||
"golang.org/x/tools/go/analysis/passes/timeformat"
|
||||
"golang.org/x/tools/go/analysis/passes/unmarshal"
|
||||
"golang.org/x/tools/go/analysis/passes/unreachable"
|
||||
"golang.org/x/tools/go/analysis/passes/unsafeptr"
|
||||
"golang.org/x/tools/go/analysis/passes/unusedresult"
|
||||
"golang.org/x/tools/go/analysis/passes/waitgroup"
|
||||
"golang.org/x/tools/go/analysis/suite/vet"
|
||||
"golang.org/x/tools/go/analysis/unitchecker"
|
||||
)
|
||||
|
||||
|
|
@ -53,48 +18,5 @@ func main() {
|
|||
objabi.AddVersionFlag()
|
||||
counter.Inc("vet/invocations")
|
||||
|
||||
unitchecker.Main(suite...) // (never returns)
|
||||
}
|
||||
|
||||
// The vet suite analyzers report diagnostics.
|
||||
// (Diagnostics must describe real problems, but need not
|
||||
// suggest fixes, and fixes are not necessarily safe to apply.)
|
||||
var suite = []*analysis.Analyzer{
|
||||
appends.Analyzer,
|
||||
asmdecl.Analyzer,
|
||||
assign.Analyzer,
|
||||
atomic.Analyzer,
|
||||
bools.Analyzer,
|
||||
buildtag.Analyzer,
|
||||
cgocall.Analyzer,
|
||||
composite.Analyzer,
|
||||
copylock.Analyzer,
|
||||
defers.Analyzer,
|
||||
directive.Analyzer,
|
||||
errorsas.Analyzer,
|
||||
// fieldalignment.Analyzer omitted: too noisy
|
||||
framepointer.Analyzer,
|
||||
httpresponse.Analyzer,
|
||||
hostport.Analyzer,
|
||||
ifaceassert.Analyzer,
|
||||
loopclosure.Analyzer,
|
||||
lostcancel.Analyzer,
|
||||
nilfunc.Analyzer,
|
||||
printf.Analyzer,
|
||||
// shadow.Analyzer omitted: too noisy
|
||||
shift.Analyzer,
|
||||
sigchanyzer.Analyzer,
|
||||
slog.Analyzer,
|
||||
stdmethods.Analyzer,
|
||||
stdversion.Analyzer,
|
||||
stringintconv.Analyzer,
|
||||
structtag.Analyzer,
|
||||
tests.Analyzer,
|
||||
testinggoroutine.Analyzer,
|
||||
timeformat.Analyzer,
|
||||
unmarshal.Analyzer,
|
||||
unreachable.Analyzer,
|
||||
unsafeptr.Analyzer,
|
||||
unusedresult.Analyzer,
|
||||
waitgroup.Analyzer,
|
||||
unitchecker.Main(vet.Suite...) // (never returns)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue