Skip to content

x/tools/go/analysis: singlechecker.Main() does not respect *analysis.Analyzer.Flags #73875

@AkihiroSuda

Description

@AkihiroSuda

Go version

go version go1.24.3 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/suda/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/suda/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/8s/9m9m_j810kb2ystr5bxv21gc0000gn/T/go-build209139724=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/suda/gopath/src/github.com/AkihiroSuda/gosocialcheck/go.mod'
GOMODCACHE='/Users/suda/gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/suda/gopath'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.24.3/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/suda/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.3/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.24.3'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

https://github.com/golang/tools/blob/64b63a6f6aeed9d09ddeb61e31b8e3ecb925f6ff/go/analysis/singlechecker/singlechecker.go#L38-L76

Called x/tools/go/analysis/singlechecker.Main() with *analysis.Analyzer.Flags.
The flag set contains Args that differs from the global os.Args, as this is a subcommand of spf13/cobra application.

https://github.com/AkihiroSuda/gosocialcheck/blob/746641d50198cc7b9f2d1d82b691041661c56907/cmd/gosocialcheck/commands/run/run.go#L44

What did you see happen?

https://github.com/golang/tools/blob/64b63a6f6aeed9d09ddeb61e31b8e3ecb925f6ff/go/analysis/singlechecker/singlechecker.go#L38-L76

singlechecker.Main() does not respect the CLI arguments passed via*analysis.Analyzer.Flags.
Instead, it just uses the global flag.Args (i.e., the global os.Args).

This issue disallows calling singlechecker.Main from a CLI subcommand like gosocialcheck run ./...

What did you expect to see?

singlechecker.Main() should respect the CLI arguments passed via*analysis.Analyzer.Flags, so that it can be used in a CLI subcommand.

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolProposalIssues describing a requested change to a Go tool or command-line program.ToolsThis label describes issues relating to any tools in the x/tools repository.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      close