cmd/vet: move go vet checks out of golangci-lint

golangci-lint runs `go vet` analyzers like copylocks, but only
reports issues on lines changed by a PR, so adding a mutex to an
existing struct can silently make old copies of it wrong.

This patch removes this responsibility from golangci-lint and moves
the analyzers into our custom vettool. It also adds `go vet` checks
for platform-specific code.

Updates #22645
Updates #22647
Updates #22652
Fixes #22653

Change-Id: I28c890de2ac2744911a04e0704ebf47fca088a9e
Co-authored-by: Brad Fitzpatrick <[email protected]>
Signed-off-by: Simon Law <[email protected]>
This commit is contained in:
Simon LawandBrad Fitzpatrick committed 2026-11-25 02:46:39 -05:00
1 parent 012baddc17
commit 7108c87bfb
3 files changed
+103 -45

No files matched your search

+26 -2
View File
@@ -25,6 +25,27 @@ jobs:
vet:
runs-on: ubuntu-24.04
timeout-minutes: 10
name: vet (${{ matrix.name }})
strategy:
fail-fast: false # don't abort the entire matrix if one element fails
matrix:
include:
- name: "macOS"
goos: "darwin"
goarch: "arm64"
flags: "--with-tags-all=darwin"
- name: "Windows"
goos: "windows"
goarch: "amd64"
flags: "--with-tags-all=windows"
- name: "Linux"
goos: "linux"
goarch: "amd64"
flags: "--with-tags-all=linux"
- name: "Portable"
goos: "linux"
goarch: "amd64"
flags: "--without-tags-any=windows,darwin,linux"
steps:
- name: Check out code
@@ -34,7 +55,7 @@ jobs:
- name: Build 'go vet' tool
working-directory: src
run: ./tool/go build -o /tmp/vettool tailscale.com/cmd/vet
run: ./tool/go build -o $RUNNER_TEMP/vettool ./cmd/vet
- name: Run 'go vet'
working-directory: src
@@ -44,4 +65,7 @@ jobs:
# include the v2 go client (tailscale.com/client/tailscale/v2) if it's
# a dependency in our go.mod file. Possibly a go vet bug, but avoid
# cross-repo vetting for now so we can safely add the dependency.
run: ./tool/go vet -vettool=/tmp/vettool $(./tool/go run ./tool/listpkgs --ignore-3p ./...)
run: |
GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} \
./tool/go vet -vettool=$RUNNER_TEMP/vettool \
$(./tool/go run ./tool/listpkgs --ignore-3p --goos=${{ matrix.goos }} --goarch=${{ matrix.goarch }} ${{ matrix.flags }} ./...)
-42
View File
@@ -9,7 +9,6 @@ linters:
default: none
enable:
- bidichk
- govet
- importas
- misspell
- revive
@@ -19,47 +18,6 @@ linters:
alias:
- pkg: github.com/tailscale/gliderssh
alias: gliderssh
# Matches what we use in corp as of 2023-12-07
govet:
enable:
- asmdecl
- assign
- atomic
- bools
- buildtag
- cgocall
- copylocks
- deepequalerrors
- errorsas
- framepointer
- httpresponse
- ifaceassert
- loopclosure
- lostcancel
- nilfunc
- nilness
- printf
- reflectvaluecompare
- shift
- sigchanyzer
- sortslice
- stdmethods
- stringintconv
- structtag
- testinggoroutine
- tests
- unmarshal
- unreachable
- unsafeptr
- unusedresult
settings:
printf:
# List of print function names to check (in addition to default)
funcs:
- github.com/tailscale/tailscale/types/logger.Discard
# NOTE(andrew-d): this doesn't currently work because the printf
# analyzer doesn't support type declarations
#- github.com/tailscale/tailscale/types/logger.Logf
revive:
enable-all-rules: false
rules:
+77 -1
View File
@@ -6,7 +6,38 @@ package main
import (
_ "embed"
"strings"
"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/copylock"
"golang.org/x/tools/go/analysis/passes/deepequalerrors"
"golang.org/x/tools/go/analysis/passes/errorsas"
"golang.org/x/tools/go/analysis/passes/framepointer"
"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/nilness"
"golang.org/x/tools/go/analysis/passes/printf"
"golang.org/x/tools/go/analysis/passes/reflectvaluecompare"
"golang.org/x/tools/go/analysis/passes/shift"
"golang.org/x/tools/go/analysis/passes/sigchanyzer"
"golang.org/x/tools/go/analysis/passes/sortslice"
"golang.org/x/tools/go/analysis/passes/stdmethods"
"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/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/unitchecker"
"tailscale.com/cmd/vet/jsontags"
"tailscale.com/cmd/vet/lowerell"
@@ -22,5 +53,50 @@ func init() {
}
func main() {
unitchecker.Main(jsontags.Analyzer, lowerell.Analyzer, subtestnames.Analyzer)
// List of print function names to check (in addition to default)
if err := printf.Analyzer.Flags.Set("funcs", strings.Join([]string{
"github.com/tailscale/tailscale/types/logger.Discard",
// NOTE(andrew-d): this doesn't currently work because the printf
// analyzer doesn't support type declarations
// "github.com/tailscale/tailscale/types/logger.Logf",
}, ",")); err != nil {
panic(err)
}
unitchecker.Main(
asmdecl.Analyzer,
assign.Analyzer,
atomic.Analyzer,
bools.Analyzer,
buildtag.Analyzer,
cgocall.Analyzer,
copylock.Analyzer,
deepequalerrors.Analyzer,
errorsas.Analyzer,
framepointer.Analyzer,
httpresponse.Analyzer,
ifaceassert.Analyzer,
loopclosure.Analyzer,
lostcancel.Analyzer,
nilfunc.Analyzer,
nilness.Analyzer,
printf.Analyzer,
reflectvaluecompare.Analyzer,
shift.Analyzer,
sigchanyzer.Analyzer,
sortslice.Analyzer,
stdmethods.Analyzer,
stringintconv.Analyzer,
structtag.Analyzer,
testinggoroutine.Analyzer,
tests.Analyzer,
unmarshal.Analyzer,
unreachable.Analyzer,
unsafeptr.Analyzer,
unusedresult.Analyzer,
jsontags.Analyzer,
lowerell.Analyzer,
subtestnames.Analyzer,
)
}