Skip to content

Commit

Permalink
Update go vet with latest analyzers
Browse files Browse the repository at this point in the history
Upgrade golang.org/x/tools to v0.18.0.
Note that the latest v0.19.0 has a bug that we should avoid using.

Update the analyzers (passes) in TOOLS_NOGO and the ones automatically
included when `vet = True` is configured.
The vet analyzers are taken from `go tool vet help` documentation.
  • Loading branch information
sluongng committed Mar 27, 2024
1 parent 2343e4a commit 05860f6
Show file tree
Hide file tree
Showing 15 changed files with 115,212 additions and 110,238 deletions.
6 changes: 4 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ bazel_skylib_workspace()

http_archive(
name = "bazel_gazelle",
patch_args = ["-p1"],
patches = ["//third_party:bazel-gazelle.patch"],
sha256 = "b7387f72efb59f876e4daae42f1d3912d0d45563eac7cb23d1de0b094ab588cf",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/v0.34.0/bazel-gazelle-v0.34.0.tar.gz",
Expand Down Expand Up @@ -99,8 +101,8 @@ go_repository(
go_repository(
name = "org_golang_x_mod",
importpath = "golang.org/x/mod",
sum = "h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=",
version = "v0.9.0",
sum = "h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=",
version = "v0.15.0",
)

go_repository(
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.7.0-rc.1
github.com/golang/protobuf v1.5.3
golang.org/x/net v0.18.0
golang.org/x/tools v0.15.0
golang.org/x/net v0.21.0
golang.org/x/tools v0.18.0
google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013
google.golang.org/grpc v1.40.1
google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.3.0
google.golang.org/protobuf v1.31.0
)

require (
golang.org/x/mod v0.14.0 // indirect
golang.org/x/sys v0.15.0 // indirect
golang.org/x/mod v0.15.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHl
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.5.1/go.mod h1:5OXOZSfqPIIbmVBIIKWRFfZjPR0E5r58TLhUjH0a2Ro=
golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0=
golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand All @@ -81,8 +81,8 @@ golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg=
golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand All @@ -92,8 +92,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand All @@ -102,8 +102,8 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand All @@ -120,8 +120,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.8/go.mod h1:nABZi5QlRsZVlzPpHl034qft6wpY4eDcsTt5AaioBiU=
golang.org/x/tools v0.15.0 h1:zdAyfUGbYmuVokhzVmghFl2ZJh5QhcfebBgmVPFYA+8=
golang.org/x/tools v0.15.0/go.mod h1:hpksKq4dtpQWS1uQ61JkdqWM3LscIS6Slf+VVkm+wQk=
golang.org/x/tools v0.18.0 h1:k8NLag8AGHnn+PHbl7g43CtqZAwG60vZkLqgyZgIHgQ=
golang.org/x/tools v0.18.0/go.mod h1:GL7B4CwcLLeo59yx/9UWWuNOW1n3VZ4f5axWfML7Lcg=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
86 changes: 50 additions & 36 deletions go/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,49 +75,63 @@ load(
)

_TOOLS_NOGO = [
"@org_golang_x_tools//go/analysis/passes/asmdecl:go_default_library",
"@org_golang_x_tools//go/analysis/passes/assign:go_default_library",
"@org_golang_x_tools//go/analysis/passes/atomic:go_default_library",
"@org_golang_x_tools//go/analysis/passes/atomicalign:go_default_library",
"@org_golang_x_tools//go/analysis/passes/bools:go_default_library",
"@org_golang_x_tools//go/analysis/passes/buildssa:go_default_library",
"@org_golang_x_tools//go/analysis/passes/buildtag:go_default_library",
# keep sorted
"appends",
"asmdecl",
"assign",
"atomic",
"atomicalign",
"bools",
"buildssa",
"buildtag",
# TODO(#2396): pass raw cgo sources to cgocall and re-enable.
# "@org_golang_x_tools//go/analysis/passes/cgocall:go_default_library",
"@org_golang_x_tools//go/analysis/passes/composite:go_default_library",
"@org_golang_x_tools//go/analysis/passes/copylock:go_default_library",
"@org_golang_x_tools//go/analysis/passes/ctrlflow:go_default_library",
"@org_golang_x_tools//go/analysis/passes/deepequalerrors:go_default_library",
"@org_golang_x_tools//go/analysis/passes/errorsas:go_default_library",
"@org_golang_x_tools//go/analysis/passes/findcall:go_default_library",
"@org_golang_x_tools//go/analysis/passes/httpresponse:go_default_library",
"@org_golang_x_tools//go/analysis/passes/ifaceassert:go_default_library",
"@org_golang_x_tools//go/analysis/passes/inspect:go_default_library",
"@org_golang_x_tools//go/analysis/passes/loopclosure:go_default_library",
"@org_golang_x_tools//go/analysis/passes/lostcancel:go_default_library",
"@org_golang_x_tools//go/analysis/passes/nilfunc:go_default_library",
"@org_golang_x_tools//go/analysis/passes/nilness:go_default_library",
"@org_golang_x_tools//go/analysis/passes/pkgfact:go_default_library",
"@org_golang_x_tools//go/analysis/passes/printf:go_default_library",
"@org_golang_x_tools//go/analysis/passes/shadow:go_default_library",
"@org_golang_x_tools//go/analysis/passes/shift:go_default_library",
"@org_golang_x_tools//go/analysis/passes/sortslice:go_default_library",
"@org_golang_x_tools//go/analysis/passes/stdmethods:go_default_library",
"@org_golang_x_tools//go/analysis/passes/stringintconv:go_default_library",
"@org_golang_x_tools//go/analysis/passes/structtag:go_default_library",
"@org_golang_x_tools//go/analysis/passes/testinggoroutine:go_default_library",
"@org_golang_x_tools//go/analysis/passes/tests:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unmarshal:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unreachable:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unsafeptr:go_default_library",
"@org_golang_x_tools//go/analysis/passes/unusedresult:go_default_library",
# "cgocall",
"composite",
"copylock",
"ctrlflow",
"deepequalerrors",
"defers",
"directive",
"errorsas",
# Noisy and not actionable in some cases.
# "fieldalignment",
"findcall",
"framepointer",
"httpmux",
"httpresponse",
"ifaceassert",
"inspect",
"loopclosure",
"lostcancel",
"nilfunc",
"nilness",
"pkgfact",
"printf",
"reflectvaluecompare",
"shadow",
"shift",
"sigchanyzer",
"slog",
"sortslice",
"stdmethods",
"stringintconv",
"structtag",
"testinggoroutine",
"tests",
"timeformat",
"unmarshal",
"unreachable",
"unsafeptr",
"unusedresult",
"unusedwrite",
"usesgenerics",
]

# TOOLS_NOGO is a list of all analysis passes in
# golang.org/x/tools/go/analysis/passes.
# This is not backward compatible, so use caution when depending on this --
# new analyses may discover issues in existing builds.
TOOLS_NOGO = [str(Label(l)) for l in _TOOLS_NOGO]
TOOLS_NOGO = [str(Label("@org_golang_x_tools//go/analysis/passes/{}".format(p))) for p in _TOOLS_NOGO]

# Current version or next version to be tagged. Gazelle and other tools may
# check this to determine compatibility.
Expand Down
39 changes: 29 additions & 10 deletions go/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ def go_rules_dependencies(force = False):
wrapper(
http_archive,
name = "org_golang_x_tools",
# v0.15.0, latest as of 2023-11-16
# v0.18.0, latest as of 2024-03-26
urls = [
"https://mirror.bazel.build/github.com/golang/tools/archive/refs/tags/v0.15.0.zip",
"https://github.com/golang/tools/archive/refs/tags/v0.15.0.zip",
"https://mirror.bazel.build/github.com/golang/tools/archive/refs/tags/v0.18.0.zip",
"https://github.com/golang/tools/archive/refs/tags/v0.18.0.zip",
],
sha256 = "e76a03b11719138502c7fef44d5e1dc4469f8c2fcb2ee4a1d96fb09aaea13362",
strip_prefix = "tools-0.15.0",
sha256 = "5b79d9c1a66bd27fd5ba3db6b9f1e3e7dcc201df7d2a11281424129ac2db56ae",
strip_prefix = "tools-0.18.0",
patches = [
# deletegopls removes the gopls subdirectory. It contains a nested
# module with additional dependencies. It's not needed by rules_go.
Expand Down Expand Up @@ -106,20 +106,39 @@ def go_rules_dependencies(force = False):
wrapper(
http_archive,
name = "org_golang_x_sys",
# v0.15.0, latest as of 2023-12-15
# v0.18.0, latest as of 2024-03-26
urls = [
"https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.15.0.zip",
"https://github.com/golang/sys/archive/refs/tags/v0.15.0.zip",
"https://mirror.bazel.build/github.com/golang/sys/archive/refs/tags/v0.18.0.zip",
"https://github.com/golang/sys/archive/refs/tags/v0.18.0.zip",
],
sha256 = "36e7b6587b60eabebcd5102211ef5fabc6c6f40d93dd0db83dcefd13cdeb1b71",
strip_prefix = "sys-0.15.0",
sha256 = "d5ffb367cf0b672a6b97e2e0cf775dbae36276986485cf665cef5fd677563651",
strip_prefix = "sys-0.18.0",
patches = [
# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/sys -go_naming_convention import_alias
Label("//third_party:org_golang_x_sys-gazelle.patch"),
],
patch_args = ["-p1"],
)

# Needed by golang.org/x/tools
# releaser:upgrade-dep golang mod
wrapper(
http_archive,
name = "org_golang_x_mod",
# v0.16.0, latest as of 2024-03-26
urls = [
"https://mirror.bazel.build/github.com/golang/mod/archive/refs/tags/v0.16.0.zip",
"https://github.com/golang/mod/archive/refs/tags/v0.16.0.zip",
],
sha256 = "429f03a3eb0982540cc6b9bdfd1bc1e8dd07d43708a4e92aae6848b25316575e",
strip_prefix = "mod-0.16.0",
patches = [
# releaser:patch-cmd gazelle -repo_root . -go_prefix golang.org/x/mod -go_naming_convention import_alias
Label("//third_party:org_golang_x_mod-gazelle.patch"),
],
patch_args = ["-p1"],
)

# Needed by golang.org/x/tools/go/packages
# releaser:upgrade-dep golang xerrors
wrapper(
Expand Down
48 changes: 43 additions & 5 deletions go/private/rules/nogo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,49 @@ def nogo(name, visibility = None, **kwargs):
def nogo_wrapper(**kwargs):
if kwargs.get("vet"):
kwargs["deps"] = kwargs.get("deps", []) + [
Label("@org_golang_x_tools//go/analysis/passes/atomic:go_default_library"),
Label("@org_golang_x_tools//go/analysis/passes/bools:go_default_library"),
Label("@org_golang_x_tools//go/analysis/passes/buildtag:go_default_library"),
Label("@org_golang_x_tools//go/analysis/passes/nilfunc:go_default_library"),
Label("@org_golang_x_tools//go/analysis/passes/printf:go_default_library"),
Label("@org_golang_x_tools//go/analysis/passes/{}".format(p))
for p in [
# Taken from 'go tool vet help'.
# keep sorted
"appends",
"asmdecl",
"assign",
"atomic",
"bools",
"buildtag",
"cgocall",
# note that the 'go tool vet help' documented this
# with a plural name 'composites'.
# The actual package is singular.
"composite",
# note that the 'go tool vet help' documented this
# with a plural name 'copylocks'.
# The actual package is singular.
"copylock",
"defers",
"directive",
"errorsas",
"framepointer",
"httpresponse",
"ifaceassert",
"loopclosure",
"lostcancel",
"nilfunc",
"printf",
"shift",
"sigchanyzer",
"slog",
"stdmethods",
"stringintconv",
"structtag",
"testinggoroutine",
"tests",
"timeformat",
"unmarshal",
"unreachable",
"unsafeptr",
"unusedresult",
]
]
kwargs = {k: v for k, v in kwargs.items() if k != "vet"}
nogo(**kwargs)
Loading

0 comments on commit 05860f6

Please sign in to comment.