Commit 6b5c4f5c45 for golang

commit 6b5c4f5c455ced01bb9f1c8ac4037f1c6c39b837
Author: Alan Donovan <adonovan@google.com>
Date:   Wed Nov 25 13:48:05 2026 -0500

    cmd/go: honor go.vet files outside std

    This CL opens the floodgates: 'go test' (with GOEXPERIMENT=vetfiles)
    will now respect go.vet files outside the standard library,
    and arbitrary Go users may declare analyzers that will be
    automatically executed by go test.

    The logic essentially deletes the restriction, and adds a second
    call to the module loader for analyzer implementation packages.
    The bulk of the CL is just tests.

    Known limitation: because of the second call:
    - if any earlier error was reported (a package that failed to load,
      or a bad go.vet file), go test exits without running any tests;
    - -gcflags and -asmflags without a package pattern also apply to the
      analyzer packages, and to tests that import them.
    A follow-up CL will load the analyzer packages along with the packages
    under test.

    For #82464

    Change-Id: Ica2f59f37f613e494874075672954257d2ddc869
    Reviewed-on: https://go-review.googlesource.com/c/go/+/857003
    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>
    Reviewed-by: PJ Malloy <pjmalloy@google.com>
    Reviewed-by: t hepudds <thepudds1460@gmail.com>

diff --git a/src/cmd/go/internal/load/analysis.go b/src/cmd/go/internal/load/analysis.go
index e89929b851..5108e969fe 100644
--- a/src/cmd/go/internal/load/analysis.go
+++ b/src/cmd/go/internal/load/analysis.go
@@ -36,6 +36,7 @@ import (

 	"cmd/go/internal/build"
 	"cmd/go/internal/modload"
+	"cmd/go/internal/search"
 	"cmd/go/internal/vetfile"
 )

@@ -168,8 +169,9 @@ var vetLegacyNames = map[string]string{
 // A negated variable is linked only if its package is already in the
 // import closure of the packages of the positive references, since
 // otherwise there is nothing for the negation to match. The package
-// of a negation that is not linked must still resolve, unless the
-// negation textually matched a positive reference.
+// of a negation that is not linked must still resolve against the
+// build list, unless the negation textually matched a positive
+// reference.
 //
 // A disable by name is not linked, and needs no checks.
 //
@@ -178,9 +180,9 @@ var vetLegacyNames = map[string]string{
 //
 // The package's imports are loaded without regard to the rule for
 // internal packages, like the generated testmain: the tool must
-// import analyzers (and negated variables) from internal packages,
-// and the driver itself is an internal package of the standard
-// library.
+// import analyzers (and negated variables) from internal packages of
+// the main module and its dependencies, and the driver itself is an
+// internal package of the standard library.
 func AnalysisToolPackage(ld *modload.Loader, ctx context.Context, opts PackageOpts, refs []*VetRef) (pmain *Package, src []byte) {
 	pmain = &Package{
 		// Avoid de-nesting this literal until bootstrap has go1.27.
@@ -202,14 +204,51 @@ func AnalysisToolPackage(ld *modload.Loader, ctx context.Context, opts PackageOp
 	defer stk.Pop()

 	// Load the driver and the packages of positive references.
-	// (For now, all are standard packages.)
+	// Standard packages are loaded directly. Others are loaded as
+	// if named on the command line, so that they are added to the
+	// module loader's package graph. Either way, they are exempt
+	// from the rule for internal packages.
 	//
-	// TODO(adonovan): relax this restriction (see CL 857003).
+	// TODO(adonovan): loading non-standard packages calls
+	// modload.LoadPackages again, which mutates state shared with
+	// the rest of the command, with observable consequences:
+	//
+	//  - It exits if errors have already been reported
+	//    (base.ExitIfErrors). So if any package under test failed
+	//    setup, or any go.vet file has an error, go test exits
+	//    here, having built and run no tests, and reports nothing
+	//    but those errors.
+	//
+	//  - It replaces the loader's package graph and requirements
+	//    with those of these packages, so a later lookup of a
+	//    package under test (or of its imports) would fail. For now,
+	//    nothing in go test loads packages after this point.
+	//
+	//  - It marks these packages as named on the command line, so
+	//    pattern-less -gcflags and -asmflags apply to them. As
+	//    Packages are shared, that changes the build of the tests
+	//    that import them, too.
+	//
+	// (So packages are loaded in batches, not one at a time.)
+	// The fix is for the module loader to load the analyzer
+	// packages along with the packages under test, or to extend its
+	// package graph without replacing it.
 	pkgs := make(map[string]*Package)
 	load := func(paths []string) {
+		var missing []string
 		for _, path := range paths {
-			if _, ok := pkgs[path]; !ok {
+			if _, ok := pkgs[path]; ok {
+				continue
+			}
+			if search.IsStandardImportPath(path) {
 				pkgs[path], _ = loadImport(ld, ctx, opts, nil, path, "", nil, &stk, nil, 0)
+			} else {
+				missing = append(missing, path)
+			}
+		}
+		if len(missing) > 0 {
+			for _, p1 := range PackagesAndErrors(ld, ctx, opts, missing) {
+				pkgs[p1.ImportPath] = p1
 			}
 		}
 	}
@@ -277,8 +316,9 @@ func AnalysisToolPackage(ld *modload.Loader, ctx context.Context, opts PackageOp
 	// Pass 2: disable
 	//
 	// Link the negative references in the (now complete) import closure.
-	// The package of each other negation must resolve,
+	// The package of each other negation must resolve (against the build list),
 	// unless the negation textually matched a positive reference.
+	// (Those packages are loaded in a single batch; see load.)
 	var unlinked []*VetRef
 	for _, ref := range negative {
 		switch {
diff --git a/src/cmd/go/internal/load/vetfile.go b/src/cmd/go/internal/load/vetfile.go
index 5808389b78..d5b291914d 100644
--- a/src/cmd/go/internal/load/vetfile.go
+++ b/src/cmd/go/internal/load/vetfile.go
@@ -7,10 +7,11 @@ package load
 // This file implements workspace-specified analyzers in go test:
 // directories enable analyzers with directives (enable and disable
 // declarations) in a file named go.vet, whose syntax follows that of
-// go.mod, and go test runs them over the relevant packages (with
-// GOEXPERIMENT=vetfiles; see cfg.Experiment.VetFiles). For now, only
-// the go.vet files of the standard library (GOROOT/src) are read;
-// they declare go test's vet checks.
+// go.mod, and go test runs them over the relevant packages. go test's
+// own vet checks are declared the same way, by the go.vet files of the
+// standard library (GOROOT/src), which enable analyzers of the vet
+// suite. No go.vet file is read without GOEXPERIMENT=vetfiles (see
+// cfg.Experiment.VetFiles); go test then runs cmd/vet, as before.
 //
 // This file implements the static stage of resolution for the
 // declarations: parsing them, and computing which apply to each
@@ -54,10 +55,6 @@ import (
 // [vetfile.EnclosingDirs].)
 func readVetFile(dir, dirPath string, std bool) []*VetRef {
 	return vetFileCache.Do(dir, func() []*VetRef {
-		if !std {
-			// TODO(adonovan): relax this restriction (see CL 857003).
-			return nil // only the go.vet files of std are read
-		}
 		f, err := vetfile.Read(dir, dirPath, std)
 		if err != nil {
 			if list, ok := errors.AsType[modfile.ErrorList](err); ok {
diff --git a/src/cmd/go/testdata/script/test_vetfiles.txt b/src/cmd/go/testdata/script/test_vetfiles.txt
new file mode 100644
index 0000000000..f1e5bf1591
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_vetfiles.txt
@@ -0,0 +1,231 @@
+# Tests of annotation-driven analysis in go test (GOEXPERIMENT=vetfiles).
+# The test analyzers report their name on the package declaration
+# of the first file.
+
+[short] skip 'builds and runs an analysis tool'
+
+# Without GOEXPERIMENT=vetfiles, go test runs cmd/vet, and go.vet files
+# are ignored.
+go test ./a
+env GOEXPERIMENT=vetfiles
+
+# The root analyzers of package a are reported. beta requires helper,
+# which uses facts, so helper runs on a's dependency lib.
+# As with vet, the test does not run if the analysis fails.
+! go test ./a
+stderr 'a.go:1:1: alpha$'
+stderr 'a.go:1:1: beta: 1 imports analyzed$'
+stdout '^FAIL\s+example.com/m/a\s.*\[build failed\]$'
+
+# A second run uses cached results: the tool analyzes no packages,
+# and its metadata query is not executed.
+! go test -x ./a
+stderr 'a.go:1:1: alpha$'
+stderr 'a.go:1:1: beta: 1 imports analyzed$'
+! stderr 'analysistool.* .*analysis\.cfg'
+! stderr 'analysistool(\.exe)?"? "?-describe='
+
+# A change to lib that preserves its API and facts re-analyzes lib
+# but not a (early cutoff). The change must also preserve the size and
+# line count of lib.go, which the export data records.
+cp lib_v2.go.txt lib/lib.go
+! go test -x ./a
+stderr 'a.go:1:1: beta: 1 imports analyzed$'
+stderr -count=1 'analysistool.* .*analysis\.cfg'
+
+# A change to a re-analyzes only a.
+cp a_v2.go.txt a/a.go
+! go test -x ./a
+stderr 'a.go:1:1: beta: 1 imports analyzed$'
+stderr -count=1 'analysistool.* .*analysis\.cfg'
+
+# A change to the root analyzer beta re-runs beta on a. Its
+# prerequisite helper, reached only through Requires, takes its
+# identity from the package of the variable beta.Analyzer, which
+# changed, so helper re-runs too, on a and on its dependency lib.
+cp beta_v2.go.txt beta/beta.go
+! go test -x ./a
+stderr 'a.go:1:1: beta v2: 1 imports analyzed$'
+stderr -count=2 'analysistool.* .*analysis\.cfg'
+
+# helper is required by two roots, beta (enabled for a) and gamma
+# (enabled for b). Its identity derives from the packages of the
+# variables from which it is reachable, so it depends on which of
+# them are linked into the tool: after go test ./..., which links
+# both, go test ./b, which links only gamma, re-analyzes b and lib.
+# Repeating it analyzes nothing.
+! go test ./...
+stderr 'b.go:1:1: gamma: 1 imports analyzed$'
+! go test -x ./b
+stderr 'b.go:1:1: gamma: 1 imports analyzed$'
+stderr 'analysistool(\.exe)?"? "?-describe='
+stderr -count=2 'analysistool.* .*analysis\.cfg'
+! go test -x ./b
+stderr 'b.go:1:1: gamma: 1 imports analyzed$'
+! stderr 'analysistool.* .*analysis\.cfg'
+
+# Declarations in an ancestor directory apply to the packages beneath
+# it ("./..."), but not to those in testdata or _ directories. The
+# ancestor (tree) need not contain a package.
+! go test ./tree/...
+stderr 'sub[/\\]sub.go:1:1: alpha$'
+go test ./tree/_hidden
+stdout '^ok\s+example.com/m/tree/_hidden'
+! stderr 'alpha'
+
+-- go.mod --
+module example.com/m
+
+go 1.26
+-- alpha/alpha.go --
+// Package alpha defines an analyzer that uses no facts.
+package alpha
+
+import "go/analysis"
+
+var Analyzer = &analysis.Analyzer{
+	Name: "alpha",
+	Doc:  "report the analyzer name",
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s", pass.Analyzer.Name)
+		return nil, nil
+	},
+}
+-- helper/helper.go --
+// Package helper defines an analyzer that uses facts.
+// Its result is the number of direct imports that have its fact.
+package helper
+
+import (
+	"go/analysis"
+	"reflect"
+)
+
+type seen struct{ Path string }
+
+func (*seen) AFact() {}
+
+var Analyzer = &analysis.Analyzer{
+	Name:       "helper",
+	Doc:        "count the imports analyzed by helper",
+	FactTypes:  []analysis.Fact{new(seen)},
+	ResultType: reflect.TypeFor[int](),
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.ExportPackageFact(&seen{pass.Pkg.Path()})
+		n := 0
+		for _, imp := range pass.Pkg.Imports() {
+			if pass.ImportPackageFact(imp, new(seen)) {
+				n++
+			}
+		}
+		return n, nil
+	},
+}
+-- beta/beta.go --
+// Package beta defines an analyzer that requires helper.
+package beta
+
+import (
+	"go/analysis"
+
+	"example.com/m/helper"
+)
+
+var Analyzer = &analysis.Analyzer{
+	Name:     "beta",
+	Doc:      "report the analyzer name and the result of helper",
+	Requires: []*analysis.Analyzer{helper.Analyzer},
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s: %d imports analyzed", pass.Analyzer.Name, pass.ResultOf[helper.Analyzer].(int))
+		return nil, nil
+	},
+}
+-- beta_v2.go.txt --
+// Package beta defines an analyzer that requires helper.
+package beta
+
+import (
+	"go/analysis"
+
+	"example.com/m/helper"
+)
+
+var Analyzer = &analysis.Analyzer{
+	Name:     "beta",
+	Doc:      "report the analyzer name and the result of helper",
+	Requires: []*analysis.Analyzer{helper.Analyzer},
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s v2: %d imports analyzed", pass.Analyzer.Name, pass.ResultOf[helper.Analyzer].(int))
+		return nil, nil
+	},
+}
+-- gamma/gamma.go --
+// Package gamma defines another analyzer that requires helper.
+package gamma
+
+import (
+	"go/analysis"
+
+	"example.com/m/helper"
+)
+
+var Analyzer = &analysis.Analyzer{
+	Name:     "gamma",
+	Doc:      "report the analyzer name and the result of helper",
+	Requires: []*analysis.Analyzer{helper.Analyzer},
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s: %d imports analyzed", pass.Analyzer.Name, pass.ResultOf[helper.Analyzer].(int))
+		return nil, nil
+	},
+}
+-- lib/lib.go --
+package lib
+
+func F() {}
+
+// Version 1 of lib.
+-- lib_v2.go.txt --
+package lib
+
+func F() {}
+
+// Version 2 of lib.
+-- a/a.go --
+package a
+
+import "example.com/m/lib"
+
+func G() { lib.F() }
+-- a_v2.go.txt --
+package a
+
+import "example.com/m/lib"
+
+func G() { lib.F() }
+
+// A trailing comment.
+-- a/a_test.go --
+package a
+-- a/go.vet --
+enable . example.com/m/alpha.Analyzer
+enable . example.com/m/beta.Analyzer
+
+// A comment.
+-- b/b.go --
+package b
+
+import "example.com/m/lib"
+
+func G() { lib.F() }
+-- b/b_test.go --
+package b
+-- b/go.vet --
+enable . example.com/m/gamma.Analyzer
+-- tree/go.vet --
+enable ./... example.com/m/alpha.Analyzer
+-- tree/sub/sub.go --
+package sub
+-- tree/_hidden/hidden.go --
+package hidden
+-- tree/_hidden/hidden_test.go --
+package hidden
diff --git a/src/cmd/go/testdata/script/test_vetfiles_byname.txt b/src/cmd/go/testdata/script/test_vetfiles_byname.txt
new file mode 100644
index 0000000000..67f6f8d1da
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_vetfiles_byname.txt
@@ -0,0 +1,142 @@
+# Tests of disable declarations that name analyzers by Analyzer.Name
+# in annotation-driven analysis in go test (GOEXPERIMENT=vetfiles).
+# Each test analyzer reports its name on the package declaration of
+# the first file.
+
+[short] skip 'builds and runs an analysis tool'
+
+env GOEXPERIMENT=vetfiles
+
+# A disable by name removes a suite member enabled by reference.
+! go test ./member
+stderr 'member.go:1:1: alpha$'
+! stderr 'member.go:1:1: beta$'
+stderr 'member.go:1:1: gamma$'
+
+# A "./..." disable by name in an ancestor applies to the subtree.
+! go test ./tree/...
+stderr 'tree[/\\]tree.go:1:1: alpha$'
+! stderr 'tree.go:1:1: gamma$'
+stderr 'sub[/\\]sub.go:1:1: alpha$'
+! stderr 'sub.go:1:1: gamma$'
+
+# A disable by name removes an analyzer enabled by an "importers"
+# declaration of a dependency.
+! go test ./user
+stderr 'user.go:1:1: alpha$'
+! stderr 'user.go:1:1: gamma$'
+
+# An "importers" declaration applies even to importers that cannot
+# see its (internal) analyzer, and they can disable it by name.
+! go test ./mixed
+stderr 'mixed.go:1:1: alpha$'
+go test ./mixedquiet
+! stderr 'mixedquiet.go:1:1: alpha$'
+
+# A disable by name that matches nothing is not an error.
+! go test ./nomatch
+stderr 'nomatch.go:1:1: alpha$'
+! stderr 'nosuch'
+
+# A disable by name needs no enabled analyzers.
+go test ./alone
+
+# Names may not be used in enable declarations.
+! go test ./enablename
+stderr 'enablename[/\\]go.vet:1: invalid reference "alpha": enable requires a qualified name pkgpath.Var \(analyzer names may be used only in disable\)$'
+
+-- go.mod --
+module example.com/m
+
+go 1.26
+-- checks/checks.go --
+// Package checks defines a suite of analyzers.
+package checks
+
+import "go/analysis"
+
+func mk(name string) *analysis.Analyzer {
+	return &analysis.Analyzer{
+		Name: name,
+		Doc:  "report the analyzer name",
+		Run: func(pass *analysis.Pass) (any, error) {
+			pass.Reportf(pass.Files[0].Package, "%s", pass.Analyzer.Name)
+			return nil, nil
+		},
+	}
+}
+
+var (
+	Alpha = mk("alpha")
+	Beta  = mk("beta")
+	Gamma = mk("gamma")
+)
+
+var Suite = []*analysis.Analyzer{Alpha, Beta, Gamma}
+-- member/member.go --
+package member
+-- member/go.vet --
+enable  . example.com/m/checks.Suite[*]
+disable . "beta"
+-- tree/go.vet --
+enable  ./... example.com/m/checks.Alpha
+enable  ./... example.com/m/checks.Gamma
+disable ./... "gamma"
+-- tree/tree.go --
+package tree
+-- tree/sub/sub.go --
+package sub
+-- prov/prov.go --
+package prov
+-- prov/go.vet --
+enable importers example.com/m/checks.Gamma
+-- user/user.go --
+package user
+
+import _ "example.com/m/prov"
+-- user/go.vet --
+enable  . example.com/m/checks.Alpha
+disable . "gamma"
+-- prov2/prov2.go --
+package prov2
+-- prov2/go.vet --
+enable importers example.com/m/prov2/internal/alpha.Analyzer
+-- prov2/internal/alpha/alpha.go --
+// Package alpha defines an internal analyzer of prov2 that has the
+// same name as checks.Alpha.
+package alpha
+
+import "go/analysis"
+
+var Analyzer = &analysis.Analyzer{
+	Name: "alpha",
+	Doc:  "report the analyzer name",
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s", pass.Analyzer.Name)
+		return nil, nil
+	},
+}
+-- mixed/mixed.go --
+package mixed
+
+import _ "example.com/m/prov2"
+-- mixedquiet/mixedquiet.go --
+package mixedquiet
+
+import _ "example.com/m/prov2"
+-- mixedquiet/go.vet --
+enable  . example.com/m/checks.Alpha
+disable . "alpha"
+-- nomatch/nomatch.go --
+package nomatch
+-- nomatch/go.vet --
+enable  . example.com/m/checks.Alpha
+disable . "nosuch"
+-- alone/alone.go --
+package alone
+-- alone/go.vet --
+disable . "alpha"
+-- enablename/enablename.go --
+package enablename
+-- enablename/go.vet --
+enable . "alpha"
diff --git a/src/cmd/go/testdata/script/test_vetfiles_errors.txt b/src/cmd/go/testdata/script/test_vetfiles_errors.txt
new file mode 100644
index 0000000000..652f9d7114
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_vetfiles_errors.txt
@@ -0,0 +1,237 @@
+# Tests of errors in go.vet files for annotation-driven analysis
+# in go test (GOEXPERIMENT=vetfiles). Each error is positioned at the
+# offending declaration.
+
+[short] skip 'builds and runs an analysis tool'
+
+env GOEXPERIMENT=vetfiles
+
+# Malformed declarations.
+! go test ./malformed
+stderr '^go: malformed[/\\]go.vet:1: malformed enable declaration: want scope and reference'
+stderr '^go: malformed[/\\]go.vet:2: malformed enable declaration: want scope and reference'
+stderr '^go: malformed[/\\]go.vet:3: malformed enable declaration: extra operand "extra"'
+stderr '^go: malformed[/\\]go.vet:4: invalid scope "everywhere" in enable declaration \(want ., ./..., or importers\)'
+stderr '^go: malformed[/\\]go.vet:5: disable does not accept scope "importers" \(want . or ./...\)'
+stderr '^go: malformed[/\\]go.vet:6: invalid reference "Analyzer": enable requires a qualified name pkgpath.Var \(analyzer names may be used only in disable\)$'
+stderr '^go: malformed[/\\]go.vet:7: invalid reference "example.com/m/alpha.analyzer": "analyzer" is not an exported identifier'
+stderr '^go: malformed[/\\]go.vet:8: invalid reference "example.com/m/alpha.Suite\[": missing '']'''
+stderr '^go: malformed[/\\]go.vet:9: invalid reference "example.com/m/alpha.Suite\[\]": empty member name'
+stderr '^go: malformed[/\\]go.vet:10: invalid reference "example.com/m/alpha.Suite\[A,,B\]": empty member name'
+stderr '^go: malformed[/\\]go.vet:11: invalid reference "example.com/m/alpha.Suite\[A,A\]": duplicate member name "A"'
+stderr '^go: malformed[/\\]go.vet:12: invalid reference ".Analyzer": empty package path'
+stderr '^go: malformed[/\\]go.vet:13: malformed disable declaration: extra operand "example.com/m/alpha.Analyzer"'
+! stderr 'go.vet:14'
+stderr '^go: malformed[/\\]go.vet:15: unknown directive: enabler \(want enable or disable\)'
+stderr '^go: malformed[/\\]go.vet:16: unknown block type: frobnicate'
+! stderr 'go.vet:17'
+stderr '^go: malformed[/\\]go.vet:20:2: invalid reference "example.com/m/alpha.analyzer": "analyzer" is not an exported identifier'
+stderr '^go: malformed[/\\]go.vet:22: invalid reference "alpha": want qualified name pkgpath.Var \(to disable analyzers by name, quote it: "alpha"\)$'
+stderr '^go: malformed[/\\]go.vet:23: invalid analyzer name "alpha"\[A\]: want a quoted identifier$'
+
+# go.vet files are not subject to build constraints:
+# a //go:build line is merely a comment.
+! go test ./constrained
+stderr 'constrained.go:1:1: alpha'
+
+# A go.vet file may be in a directory that contains no package.
+! go test ./nopkg/...
+stderr 'nopkg[/\\]sub[/\\]sub.go:1:1: alpha'
+
+# References whose packages do not load are reported at their
+# annotations, and dropped; the others still run. A reference to a
+# function compiles, and is rejected by the tool for its type.
+! go test ./resolve
+stderr '^resolve[/\\]go.vet:2:1: enable example.com/m/nonesuch.Analyzer: cannot load package example.com/m/nonesuch: '
+stderr '^resolve[/\\]go.vet:3:1: enable example.com/m/cmd.Analyzer: package example.com/m/cmd is a program, not an importable package$'
+stderr '^resolve[/\\]go.vet:1:1: enable example.com/m/alpha.Func: variable has type func\(\), want \*go/analysis.Analyzer or \[\]\*go/analysis.Analyzer$'
+stderr 'resolve.go:1:1: alpha$'
+
+# References that do not resolve dynamically (the wrong type or kind,
+# or a missing member) are reported at their annotations, for the
+# packages that enable them.
+! go test ./dynamic
+stderr '^dynamic[/\\]go.vet:1:1: enable example.com/m/alpha.NotAnalyzer: variable has type int, want \*go/analysis.Analyzer or \[\]\*go/analysis.Analyzer$'
+stderr '^dynamic[/\\]go.vet:2:1: enable example.com/m/alpha.Suite: example.com/m/alpha.Suite is a suite \(use example.com/m/alpha.Suite\[\*\] or select members by name\)$'
+stderr '^dynamic[/\\]go.vet:3:1: enable example.com/m/alpha.Analyzer\[\*\]: example.com/m/alpha.Analyzer is an analyzer, not a suite \(remove the brackets\)$'
+stderr '^dynamic[/\\]go.vet:4:1: enable example.com/m/alpha.Suite\[alpha,nonesuch\]: suite example.com/m/alpha.Suite has no member named nonesuch$'
+stderr '^dynamic[/\\]go.vet:5:1: disable example.com/m/alpha.Suite\[nonesuch2\]: suite example.com/m/alpha.Suite has no member named nonesuch2$'
+stderr 'dynamic.go:1:1: alpha$'
+
+# An invalid analyzer is reported only for the packages that enable it.
+! go test ./bad
+stderr '^bad[/\\]go.vet:1:1: enable example.com/m/bad.Analyzer: analyzer "bad" \(via bad\) is undocumented$'
+
+# Distinct analyzers with the same Name and Run function ("twins") in
+# the Requires closure of one member make it invalid.
+! go test ./twins
+stderr '^twins[/\\]go.vet:1:1: enable example.com/m/twins.Analyzer: analyzer "twin" \(via twins -> twin\) and another Analyzer conflict in both Name and Run function \(example.com/m/twins.run\)$'
+
+# But as members of different variables they are valid, and both run.
+# (They have the same cache identity, though, so a second, cached run
+# would report the diagnostics of one of them twice. This is a known
+# limitation; see planAnalysis.)
+! go test ./twinrefs
+stderr 'twinrefs.go:1:1: twin one$'
+stderr 'twinrefs.go:1:1: twin two$'
+
+# Composition: errors for bad do not affect the analysis of ok.
+! go test ./ok ./bad
+stderr 'ok.go:1:1: alpha$'
+stderr 'analyzer "bad" \(via bad\) is undocumented'
+! go test ./bad ./ok
+stdout '^FAIL\s+example.com/m/ok\s.*\[build failed\]$'
+stdout '^FAIL\s+example.com/m/bad\s.*\[build failed\]$'
+
+# The global scope (go test's default checks) is permitted only in
+# GOROOT/src/go.vet; disable does not accept it at all.
+! go test ./globalbad
+stderr 'globalbad[/\\]go.vet:1: ''global'' scope is permitted only in GOROOT/src/go.vet$'
+stderr 'globalbad[/\\]go.vet:2: disable does not accept scope "global" \(want . or ./...\)$'
+
+-- go.mod --
+module example.com/m
+
+go 1.26
+-- alpha/alpha.go --
+package alpha
+
+import "go/analysis"
+
+var Analyzer = &analysis.Analyzer{
+	Name: "alpha",
+	Doc:  "report the analyzer name",
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s", pass.Analyzer.Name)
+		return nil, nil
+	},
+}
+
+var Suite = []*analysis.Analyzer{Analyzer}
+
+var NotAnalyzer = 42
+
+func Func() {}
+-- bad/bad.go --
+// Package bad defines an invalid (undocumented) analyzer.
+package bad
+
+import "go/analysis"
+
+var Analyzer = &analysis.Analyzer{
+	Name: "bad",
+	Run:  func(pass *analysis.Pass) (any, error) { return nil, nil },
+}
+-- bad/go.vet --
+enable . example.com/m/bad.Analyzer
+-- bad/bad_test.go --
+package bad
+-- twins/twins.go --
+// Package twins defines distinct analyzers with the same Name and Run
+// function.
+package twins
+
+import "go/analysis"
+
+func run(pass *analysis.Pass) (any, error) {
+	pass.Reportf(pass.Files[0].Package, "%s %s", pass.Analyzer.Name, pass.Analyzer.Doc)
+	return nil, nil
+}
+
+var One = &analysis.Analyzer{Name: "twin", Doc: "one", Run: run}
+
+var Two = &analysis.Analyzer{Name: "twin", Doc: "two", Run: run}
+
+var Analyzer = &analysis.Analyzer{
+	Name:     "twins",
+	Doc:      "requires both twins",
+	Run:      func(pass *analysis.Pass) (any, error) { return nil, nil },
+	Requires: []*analysis.Analyzer{One, Two},
+}
+-- twins/go.vet --
+enable . example.com/m/twins.Analyzer
+-- twins/twins_test.go --
+package twins
+-- twinrefs/twinrefs.go --
+package twinrefs
+-- twinrefs/twinrefs_test.go --
+package twinrefs
+-- twinrefs/go.vet --
+enable . example.com/m/twins.One
+enable . example.com/m/twins.Two
+-- ok/ok.go --
+package ok
+-- ok/ok_test.go --
+package ok
+-- ok/go.vet --
+enable . example.com/m/alpha.Analyzer
+-- cmd/main.go --
+package main
+
+import "go/analysis"
+
+var Analyzer *analysis.Analyzer
+
+func main() {}
+-- malformed/go.vet --
+enable
+enable .
+enable . example.com/m/alpha.Analyzer extra
+enable everywhere example.com/m/alpha.Analyzer
+disable importers example.com/m/alpha.Analyzer
+enable . "Analyzer"
+enable . example.com/m/alpha.analyzer
+enable . example.com/m/alpha.Suite[
+enable . example.com/m/alpha.Suite[]
+enable . example.com/m/alpha.Suite[A,,B]
+enable . example.com/m/alpha.Suite[A,A]
+enable . .Analyzer
+disable importers, example.com/m/alpha.Analyzer
+//go:analyzer . not.an.annotation
+enabler . example.com/m/alpha.Analyzer
+frobnicate (
+	. example.com/m/alpha.Analyzer
+)
+enable (
+	. example.com/m/alpha.analyzer
+)
+disable . alpha
+disable . "alpha"[A]
+-- malformed/malformed_test.go --
+package malformed
+-- constrained/constrained.go --
+package constrained
+-- constrained/constrained_test.go --
+package constrained
+-- constrained/go.vet --
+//go:build ignore
+
+enable . example.com/m/alpha.Analyzer
+-- nopkg/go.vet --
+enable ./... example.com/m/alpha.Analyzer
+-- nopkg/sub/sub.go --
+package sub
+-- resolve/resolve.go --
+package resolve
+-- resolve/resolve_test.go --
+package resolve
+-- resolve/go.vet --
+enable . example.com/m/alpha.Func
+enable . example.com/m/nonesuch.Analyzer
+enable . example.com/m/cmd.Analyzer
+enable . example.com/m/alpha.Analyzer
+-- dynamic/dynamic.go --
+package dynamic
+-- dynamic/dynamic_test.go --
+package dynamic
+-- dynamic/go.vet --
+enable . example.com/m/alpha.NotAnalyzer
+enable . example.com/m/alpha.Suite
+enable . example.com/m/alpha.Analyzer[*]
+enable . example.com/m/alpha.Suite[alpha,nonesuch]
+disable . example.com/m/alpha.Suite[nonesuch2]
+-- globalbad/go.vet --
+enable global example.com/m/alpha.Analyzer
+disable global "alpha"
+-- globalbad/globalbad.go --
+package globalbad
diff --git a/src/cmd/go/testdata/script/test_vetfiles_exec.txt b/src/cmd/go/testdata/script/test_vetfiles_exec.txt
new file mode 100644
index 0000000000..4c4431b145
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_vetfiles_exec.txt
@@ -0,0 +1,129 @@
+# Tests of the execution policy of annotation-driven analysis in
+# go test (GOEXPERIMENT=vetfiles).
+
+[short] skip 'builds and runs an analysis tool'
+
+env GOEXPERIMENT=vetfiles
+
+# go test -c runs no analysis, neither the declared analyzers
+# (otherwise the failure of facty on lib would be reported)
+# nor the vet suite.
+go test -c -o=$WORK/a.test ./a
+! stderr 'facty|dependent'
+exists $WORK/a.test
+
+# The analysis tool is built in this process.
+! go test -x ./a
+stderr 'analysistool(\.exe)?"? .*analysis\.cfg'
+
+# Under an exec wrapper, which may run the tests in an emulator or a
+# sandbox, go test does not run the analysis tool on the host but uses
+# cmd/vet, so the declared analyzers do not run.
+[exec:echo] go test -exec=echo ./a
+[exec:echo] ! stderr 'facty|dependent'
+
+# A failure of a fact-producing pass on a dependency is reported once,
+# at the package on which it occurred, and prevents the dependent
+# passes, which are not reported. The root package fails quietly.
+! go test ./a
+stderr -count=1 '^analysis of example.com/m/lib by facty failed: oops$'
+! stderr 'dependent'
+stdout '^FAIL\s+example.com/m/a\s.*\[build failed\]$'
+
+# A cached failure is reported again.
+! go test ./a
+stderr -count=1 '^analysis of example.com/m/lib by facty failed: oops$'
+
+# A panic in an analyzer is a failure, reported at the package on
+# which it occurred. Other analyzers still run.
+! go test ./b
+stderr '^analysis of example.com/m/b( \[example.com/m/b.test\])? by panicky failed: panic: boom$'
+stderr '^example.com/m/panicky.init.func1'
+! stderr 'runtime/debug.Stack|gotestchecker.runPass'
+stderr 'b.go:1:1: dependent ran$'
+
+-- go.mod --
+module example.com/m
+
+go 1.26
+-- facty/facty.go --
+// Package facty defines an analyzer that uses facts, and fails on
+// package lib.
+package facty
+
+import (
+	"errors"
+	"go/analysis"
+)
+
+type fact struct{}
+
+func (*fact) AFact() {}
+
+var Analyzer = &analysis.Analyzer{
+	Name:      "facty",
+	Doc:       "export a fact, or fail on package lib",
+	FactTypes: []analysis.Fact{new(fact)},
+	Run: func(pass *analysis.Pass) (any, error) {
+		if pass.Pkg.Path() == "example.com/m/lib" {
+			return nil, errors.New("oops")
+		}
+		pass.ExportPackageFact(new(fact))
+		return nil, nil
+	},
+}
+-- dependent/dependent.go --
+// Package dependent defines an analyzer that requires facty.
+package dependent
+
+import (
+	"go/analysis"
+
+	"example.com/m/facty"
+)
+
+var Analyzer = &analysis.Analyzer{
+	Name:     "dependent",
+	Doc:      "report that it ran",
+	Requires: []*analysis.Analyzer{facty.Analyzer},
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "dependent ran")
+		return nil, nil
+	},
+}
+-- panicky/panicky.go --
+// Package panicky defines an analyzer that panics.
+package panicky
+
+import "go/analysis"
+
+var Analyzer = &analysis.Analyzer{
+	Name: "panicky",
+	Doc:  "panic",
+	Run:  func(pass *analysis.Pass) (any, error) { panic("boom") },
+}
+-- lib/lib.go --
+package lib
+
+func F() {}
+-- a/a.go --
+package a
+
+import "example.com/m/lib"
+
+func G() { lib.F() }
+-- a/a_test.go --
+package a
+
+import "testing"
+
+func Test(t *testing.T) {}
+-- a/go.vet --
+enable . example.com/m/dependent.Analyzer
+-- b/b.go --
+package b
+-- b/b_test.go --
+package b
+-- b/go.vet --
+enable . example.com/m/panicky.Analyzer
+enable . example.com/m/dependent.Analyzer
diff --git a/src/cmd/go/testdata/script/test_vetfiles_internal.txt b/src/cmd/go/testdata/script/test_vetfiles_internal.txt
new file mode 100644
index 0000000000..f510db2cbc
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_vetfiles_internal.txt
@@ -0,0 +1,119 @@
+# Tests of the rule for internal packages in go.vet files
+# (GOEXPERIMENT=vetfiles). Every reference must be visible from the
+# directory of its go.vet file. An "importers" declaration
+# applies to every importer, even one from which its analyzer is not
+# visible; such an importer can disable it by name.
+#
+#   prov's go.vet enables, for its importers, an internal
+#     analyzer (prov/internal/chk) and a public one (pub).
+#   prov/inside and prov/quiet, beneath prov, can see chk;
+#     prov/quiet disables it by reference.
+#   client, outside prov, cannot see chk, but gets it;
+#     clientquiet disables it by name.
+#   bad refers to chk, and to another module's internal package.
+
+[short] skip 'builds and runs an analysis tool'
+
+env GOEXPERIMENT=vetfiles
+
+# Importers that can see the internal analyzer get it.
+! go test ./prov/inside
+stderr 'inside.go:1:1: chk$'
+stderr 'inside.go:1:1: pub$'
+
+# ...and can disable it.
+! go test ./prov/quiet
+stderr 'quiet.go:1:1: pub$'
+! stderr ': chk$'
+
+# Importers that cannot see the internal analyzer get it too...
+! go test ./client
+stderr 'client.go:1:1: chk$'
+stderr 'client.go:1:1: pub$'
+! stderr 'not allowed'
+
+# ...and can disable it by name.
+! go test ./clientquiet
+stderr 'clientquiet.go:1:1: pub$'
+! stderr ': chk$'
+
+# A reference to a package that is not visible from the directory of
+# the go.vet file is an error, whether enable or disable.
+! go test ./bad
+stderr '^go: bad[/\\]go.vet:1: enable example.com/m/prov/internal/chk.Analyzer: use of internal package example.com/m/prov/internal/chk not allowed$'
+stderr '^go: bad[/\\]go.vet:2: disable example.com/m/prov/internal/chk.Analyzer: use of internal package example.com/m/prov/internal/chk not allowed$'
+stderr '^go: bad[/\\]go.vet:3: enable example.com/nonesuch/internal/x.Analyzer: use of internal package example.com/nonesuch/internal/x not allowed$'
+
+-- go.mod --
+module example.com/m
+
+go 1.26
+-- pub/pub.go --
+// Package pub defines a public analyzer.
+package pub
+
+import "go/analysis"
+
+var Analyzer = &analysis.Analyzer{
+	Name: "pub",
+	Doc:  "report the analyzer name",
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s", pass.Analyzer.Name)
+		return nil, nil
+	},
+}
+-- prov/internal/chk/chk.go --
+// Package chk defines an internal analyzer of prov.
+package chk
+
+import "go/analysis"
+
+var Analyzer = &analysis.Analyzer{
+	Name: "chk",
+	Doc:  "report the analyzer name",
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s", pass.Analyzer.Name)
+		return nil, nil
+	},
+}
+-- prov/prov.go --
+package prov
+
+func F() {}
+-- prov/go.vet --
+enable importers example.com/m/prov/internal/chk.Analyzer
+enable importers example.com/m/pub.Analyzer
+-- prov/inside/inside.go --
+package inside
+
+import "example.com/m/prov"
+
+func G() { prov.F() }
+-- prov/quiet/quiet.go --
+package quiet
+
+import "example.com/m/prov"
+
+func G() { prov.F() }
+-- prov/quiet/go.vet --
+disable . example.com/m/prov/internal/chk.Analyzer
+-- client/client.go --
+package client
+
+import "example.com/m/prov"
+
+func G() { prov.F() }
+-- clientquiet/clientquiet.go --
+package clientquiet
+
+import "example.com/m/prov"
+
+func G() { prov.F() }
+-- clientquiet/go.vet --
+disable . "chk"
+-- bad/bad.go --
+package bad
+-- bad/go.vet --
+enable . example.com/m/prov/internal/chk.Analyzer
+disable . example.com/m/prov/internal/chk.Analyzer
+enable . example.com/nonesuch/internal/x.Analyzer
diff --git a/src/cmd/go/testdata/script/test_vetfiles_off.txt b/src/cmd/go/testdata/script/test_vetfiles_off.txt
new file mode 100644
index 0000000000..86943093c6
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_vetfiles_off.txt
@@ -0,0 +1,38 @@
+# Without GOEXPERIMENT=vetfiles, go test runs cmd/vet, as it always has:
+# the analysis driver, the go.vet files of the standard library and of
+# the user have no effect.
+
+[short] skip 'runs go test'
+
+go test -n ./p
+stderr '[/\\]vet(\.exe)?"? .*vet\.cfg'
+! stderr analysistool
+
+# A go.vet file, even an invalid one, is ignored.
+go test ./q
+
+# With the setting, the analysis driver runs instead of cmd/vet, and
+# the go.vet files are read.
+env GOEXPERIMENT=vetfiles
+go test -n ./p
+stderr 'analysistool(\.exe)?"? "?-describe='
+! stderr '[/\\]vet(\.exe)?"? .*vet\.cfg'
+! go test ./q
+stderr 'q[/\\]go.vet:1: unknown directive: nonsense'
+
+-- go.mod --
+module example.com/m
+
+go 1.26
+-- p/p.go --
+package p
+-- p/p_test.go --
+package p
+
+import "testing"
+
+func TestP(t *testing.T) {}
+-- q/q.go --
+package q
+-- q/go.vet --
+nonsense . example.com/m/p.Analyzer
diff --git a/src/cmd/go/testdata/script/test_vetfiles_std.txt b/src/cmd/go/testdata/script/test_vetfiles_std.txt
index a75453b99f..aa6ec38085 100644
--- a/src/cmd/go/testdata/script/test_vetfiles_std.txt
+++ b/src/cmd/go/testdata/script/test_vetfiles_std.txt
@@ -1,5 +1,5 @@
-# Tests of go.vet files in go test for the standard library
-# (GOEXPERIMENT=vetfiles).
+# Tests of go.vet files in go test for the standard library,
+# whose go.vet files are always read.
 # An overlay adds a go.vet file to GOROOT/src/fmt, and two
 # analyzers: zzcheck, in a top-level internal package of std
 # (internal/zzcheck), visible throughout std but not to user code,
@@ -33,10 +33,11 @@ stderr 'd.go:1:1: zzcheck$'
 stderr 'd.go:1:1: zzpublic$'
 stderr 'd.go:1:1: zzcheck$'

-# The go.vet files of user packages are not read: dquiet's attempt to
-# disable "zzcheck" has no effect.
+# The go.vet files of user packages are read too: a user package can
+# disable the internal analyzer by name.
 ! go test -overlay=overlay.json ./dquiet
-stderr 'dquiet.go:1:1: zzcheck$'
+stderr 'dquiet.go:1:1: zzpublic$'
+! stderr ': zzcheck$'

 # The internal analyzer does apply to std importers of fmt.
 ! go test -overlay=overlay.json -run=^$ log
@@ -56,6 +57,12 @@ stderr 'e.go:1:1: zzcheck$'
 cd $WORK/gopath/src
 env GO111MODULE=

+# Std packages, including those that use cgo, are analyzed as
+# dependencies of user packages: helper's facts are computed for
+# os/user and net and their dependencies.
+! go test ./c
+stderr 'c.go:1:1: beta: 2 imports analyzed$'
+
 -- go.mod --
 module example.com/m

@@ -119,3 +126,66 @@ import "fmt"
 func F() { fmt.Println() }
 -- d/d_test.go --
 package d
+-- c/c.go --
+package c
+
+import (
+	"net"
+	"os/user"
+)
+
+var _ = net.Dial
+var _ = user.Current
+-- c/c_test.go --
+package c
+-- c/go.vet --
+enable . example.com/m/beta.Analyzer
+-- helper/helper.go --
+// Package helper defines an analyzer that uses facts.
+// Its result is the number of direct imports that have its fact.
+package helper
+
+import (
+	"go/analysis"
+	"reflect"
+)
+
+type seen struct{ Path string }
+
+func (*seen) AFact() {}
+
+var Analyzer = &analysis.Analyzer{
+	Name:       "helper",
+	Doc:        "count the imports analyzed by helper",
+	FactTypes:  []analysis.Fact{new(seen)},
+	ResultType: reflect.TypeFor[int](),
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.ExportPackageFact(&seen{pass.Pkg.Path()})
+		n := 0
+		for _, imp := range pass.Pkg.Imports() {
+			if pass.ImportPackageFact(imp, new(seen)) {
+				n++
+			}
+		}
+		return n, nil
+	},
+}
+-- beta/beta.go --
+// Package beta defines an analyzer that requires helper.
+package beta
+
+import (
+	"go/analysis"
+
+	"example.com/m/helper"
+)
+
+var Analyzer = &analysis.Analyzer{
+	Name:     "beta",
+	Doc:      "report the analyzer name and the result of helper",
+	Requires: []*analysis.Analyzer{helper.Analyzer},
+	Run: func(pass *analysis.Pass) (any, error) {
+		pass.Reportf(pass.Files[0].Package, "%s: %d imports analyzed", pass.Analyzer.Name, pass.ResultOf[helper.Analyzer].(int))
+		return nil, nil
+	},
+}
diff --git a/src/cmd/go/testdata/script/test_vetfiles_suites.txt b/src/cmd/go/testdata/script/test_vetfiles_suites.txt
new file mode 100644
index 0000000000..a43fcf9d49
--- /dev/null
+++ b/src/cmd/go/testdata/script/test_vetfiles_suites.txt
@@ -0,0 +1,170 @@
+# Tests of suites, selectors, and negation in annotation-driven
+# analysis in go test (GOEXPERIMENT=vetfiles).
+# Each test analyzer reports its name on the package declaration
+# of the first file.
+
+[short] skip 'builds and runs an analysis tool'
+
+env GOEXPERIMENT=vetfiles
+
+# Suite[*] enables all members; repeated elements are one member.
+! go test ./all
+stderr -count=1 'all.go:1:1: alpha$'
+stderr -count=1 'all.go:1:1: beta$'
+stderr -count=1 'all.go:1:1: gamma$'
+
+# Negating a selected member.
+! go test ./negmember
+stderr 'negmember.go:1:1: alpha$'
+! stderr 'negmember.go:1:1: beta$'
+stderr 'negmember.go:1:1: gamma$'
+
+# Negating the same analyzer (pointer) through another name.
+! go test ./negpointer
+stderr 'negpointer.go:1:1: alpha$'
+stderr 'negpointer.go:1:1: beta$'
+! stderr 'negpointer.go:1:1: gamma$'
+
+# Selecting members; an analyzer enabled by two references runs and
+# is reported once.
+! go test ./select
+stderr -count=1 'select.go:1:1: alpha$'
+stderr 'select.go:1:1: beta$'
+! stderr 'select.go:1:1: gamma$'
+
+# Negating a whole suite disables its members, however they are enabled.
+go test ./negsuite
+! stderr alpha
+
+# Negating an analyzer through another variable of the same value...
+! go test ./negalias
+stderr 'negalias.go:1:1: alpha$'
+! stderr 'negalias.go:1:1: gamma$'
+
+# ...or a suite through another suite that shares members. (Though the
+# negation is of a whole variable, it does not match textually.)
+! go test ./negsuitealias
+stderr 'negsuitealias.go:1:1: alpha$'
+! stderr 'negsuitealias.go:1:1: beta$'
+! stderr 'negsuitealias.go:1:1: gamma$'
+
+# A "." negation applies only to its own package; a negation in an
+# ancestor wins over a subdirectory's enable.
+! go test ./tree/...
+stderr 'tree[/\\]tree.go:1:1: alpha$'
+! stderr 'tree.go:1:1: beta$'
+stderr 'sub[/\\]sub.go:1:1: beta$'
+stderr 'sub[/\\]sub.go:1:1: gamma$'
+! stderr 'sub[/\\]sub.go:1:1: alpha$'
+stderr 'subsub[/\\]subsub.go:1:1: alpha$'
+stderr 'subsub[/\\]subsub.go:1:1: beta$'
+stderr 'sub2[/\\]sub2.go:1:1: beta$'
+! stderr 'sub2.go:1:1: gamma$'
+stderr 'inner[/\\]inner.go:1:1: beta$'
+! stderr 'inner.go:1:1: gamma$'
+
+# An "importers" declaration applies to the importers of its package,
+# including its external test package, but not to the package itself
+# (nor to its test variant).
+! go test ./xt
+stderr 'xt_test.go:1:1: alpha$'
+! stderr 'xt.go:1:1: alpha$'
+
+-- go.mod --
+module example.com/m
+
+go 1.26
+-- checks/checks.go --
+// Package checks defines a suite of analyzers.
+package checks
+
+import (
+	"go/analysis"
+)
+
+func mk(name string) *analysis.Analyzer {
+	return &analysis.Analyzer{
+		Name: name,
+		Doc:  "report the analyzer name",
+		Run: func(pass *analysis.Pass) (any, error) {
+			pass.Reportf(pass.Files[0].Package, "%s", pass.Analyzer.Name)
+			return nil, nil
+		},
+	}
+}
+
+var (
+	Alpha = mk("alpha")
+	Beta  = mk("beta")
+	Gamma = mk("gamma")
+
+	AlsoGamma = Gamma // another variable of the same analyzer
+)
+
+var Suite = []*analysis.Analyzer{Alpha, Beta, Gamma, Alpha}
+
+var Pair = []*analysis.Analyzer{Beta, Gamma} // another suite, sharing members
+-- all/all.go --
+package all
+-- all/go.vet --
+enable . example.com/m/checks.Suite[*]
+-- negmember/negmember.go --
+package negmember
+-- negmember/go.vet --
+enable   . example.com/m/checks.Suite[*]
+disable . example.com/m/checks.Suite[beta]
+-- negpointer/negpointer.go --
+package negpointer
+-- negpointer/go.vet --
+enable   . example.com/m/checks.Suite[*]
+disable . example.com/m/checks.Gamma
+-- select/select.go --
+package select_
+-- select/go.vet --
+enable . example.com/m/checks.Suite[alpha,beta]
+enable . example.com/m/checks.Alpha
+-- negsuite/negsuite.go --
+package negsuite
+-- negsuite/go.vet --
+enable   . example.com/m/checks.Alpha
+disable . example.com/m/checks.Suite[*]
+-- negalias/negalias.go --
+package negalias
+-- negalias/go.vet --
+enable  . example.com/m/checks.Alpha
+enable  . example.com/m/checks.AlsoGamma
+disable . example.com/m/checks.Gamma
+-- negsuitealias/negsuitealias.go --
+package negsuitealias
+-- negsuitealias/go.vet --
+enable  . example.com/m/checks.Suite[*]
+disable . example.com/m/checks.Pair[*]
+-- tree/go.vet --
+enable   ./... example.com/m/checks.Alpha
+enable   ./... example.com/m/checks.Suite[beta]
+disable .     example.com/m/checks.Suite[beta]
+-- tree/tree.go --
+package tree
+-- tree/sub/go.vet --
+disable . example.com/m/checks.Alpha
+enable   . example.com/m/checks.Gamma
+-- tree/sub/sub.go --
+package sub
+-- tree/sub/subsub/subsub.go --
+package subsub
+-- tree/sub2/go.vet --
+disable ./... example.com/m/checks.Gamma
+-- tree/sub2/sub2.go --
+package sub2
+-- tree/sub2/inner/go.vet --
+enable . example.com/m/checks.Gamma
+-- tree/sub2/inner/inner.go --
+package inner
+-- xt/go.vet --
+enable importers example.com/m/checks.Alpha
+-- xt/xt.go --
+package xt
+-- xt/xt_test.go --
+package xt_test
+
+import _ "example.com/m/xt"