Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golangci-lint 1.60.1 incorrectly reports SA3000: TestMain should call os.Exit #4905

Closed
6 of 7 tasks
skaji opened this issue Aug 14, 2024 · 7 comments · Fixed by #4907
Closed
6 of 7 tasks

golangci-lint 1.60.1 incorrectly reports SA3000: TestMain should call os.Exit #4905

skaji opened this issue Aug 14, 2024 · 7 comments · Fixed by #4907
Assignees
Labels
bug Something isn't working

Comments

@skaji
Copy link

skaji commented Aug 14, 2024

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

Description of the problem

golangci-lint 1.60.1 incorrectly reports

SA3000: TestMain should call os.Exit to set exit code (staticcheck)

on go 1.22 or 1.23.

Note that golangci-lint 1.59.1 does not report SA3000.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version 1.60.1 built with go1.23.0 from 3298c104 on 2024-08-14T01:15:05Z

Configuration

# no configuration file

Go environment

$ go version && go env
go version go1.22.6 darwin/arm64
GO111MODULE=''
GOARCH='arm64'
GOBIN='/Users/skaji/bin'
GOCACHE='/Users/skaji/Library/Caches/go-build'
GOENV='/Users/skaji/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/skaji/.gopath/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/skaji/.gopath'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/Users/skaji/env/goenv/versions/1.22.6'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/skaji/env/goenv/versions/1.22.6/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.6'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/Users/skaji/try/20240811/playground/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/_m/8hkr1h916g39vfcj0fltmlb00000gn/T/go-build3633526964=/tmp/go-build -gno-record-gcc-switches -fno-common'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO golangci-lint has version 1.60.1 built with go1.23.0 from 3298c104 on 2024-08-14T01:15:05Z
INFO [config_reader] Config search paths: [./ /Users/skaji/try/20240811/playground /Users/skaji/try/20240811 /Users/skaji/try /Users/skaji /Users /]
INFO [lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused]
INFO [loader] Go packages loading at mode 575 (types_sizes|compiled_files|deps|files|imports|exports_file|name) took 131.124041ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 79.375µs
INFO [linters_context/goanalysis] analyzers took 877.890789ms with top 10 stages: buildir: 667.14208ms, inspect: 34.550292ms, fact_deprecated: 31.254588ms, ctrlflow: 27.959335ms, fact_purity: 25.951583ms, SA5012: 25.154119ms, printf: 23.488038ms, nilness: 19.883499ms, typedness: 18.878253ms, tokenfileanalyzer: 1.785499ms
INFO [runner] Processors filtering stat (in/out): exclude-rules: 1/1, max_from_linter: 1/1, severity-rules: 1/1, sort_results: 1/1, path_shortener: 1/1, path_prefixer: 1/1, filename_unadjuster: 1/1, skip_files: 1/1, skip_dirs: 1/1, autogenerated_exclude: 1/1, diff: 1/1, path_prettifier: 1/1, max_same_issues: 1/1, source_code: 1/1, uniq_by_line: 1/1, max_per_file_from_linter: 1/1, fixer: 1/1, cgo: 1/1, invalid_issue: 1/1, identifier_marker: 1/1, exclude: 1/1, nolint: 1/1
INFO [runner] processing took 187.5µs with stages: path_prettifier: 37.584µs, identifier_marker: 32.875µs, exclude-rules: 32.249µs, nolint: 27.876µs, autogenerated_exclude: 26.792µs, source_code: 15.458µs, skip_dirs: 6.167µs, invalid_issue: 1.792µs, uniq_by_line: 1.292µs, cgo: 1.125µs, max_same_issues: 875ns, path_shortener: 749ns, filename_unadjuster: 583ns, exclude: 458ns, max_from_linter: 375ns, skip_files: 292ns, sort_results: 291ns, fixer: 250ns, max_per_file_from_linter: 167ns, diff: 84ns, severity-rules: 83ns, path_prefixer: 83ns
INFO [runner] linters took 610.295625ms with stages: goanalysis_metalinter: 610.037584ms
main_test.go:5:1: SA3000: TestMain should call os.Exit to set exit code (staticcheck)
func TestMain(m *testing.M) {
^
INFO File cache stats: 1 entries of total size 73B
INFO Memory: 9 samples, avg is 134.9MB, max is 207.4MB
INFO Execution took 781.692875ms

A minimal reproducible example or link to a public repository

go.mod:

module playground

go 1.22.0

main_test.go:

package main

import "testing"

func TestMain(m *testing.M) {
	m.Run()
}

Then:

golangci-lint version && golangci-lint cache clean && golangci-lint run; echo $?
golangci-lint has version 1.60.1 built with go1.23.0 from 3298c104 on 2024-08-14T01:15:05Z
main_test.go:5:1: SA3000: TestMain should call os.Exit to set exit code (staticcheck)
func TestMain(m *testing.M) {
^
1

Note1: golangci-lint 1.59.1 does not report anything.

golangci-lint version && golangci-lint cache clean && golangci-lint run; echo $?
golangci-lint has version 1.59.1 built with go1.22.3 from 1a55854a on 2024-06-09T18:08:33Z
0

Note2: Standalone staticcheck does not report anything.

staticcheck -version && staticcheck; echo $?
staticcheck 2024.1 (0.5.0)
0

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@skaji skaji added the bug Something isn't working label Aug 14, 2024
@ldez ldez self-assigned this Aug 14, 2024
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Aug 14, 2024
@ldez
Copy link
Member

ldez commented Aug 14, 2024

Hello,

the report of SA3000 doesn't seem wrong, in your example os.Exit is missing.

https://staticcheck.dev/docs/checks/#SA3000

@ldez ldez closed this as completed Aug 14, 2024
@skaji
Copy link
Author

skaji commented Aug 14, 2024

@ldez Thank you for looking at this issue.

Since go 1.15, we don't need to call os.Exit manually. https://go.dev/doc/go1.15

A TestMain function is no longer required to call os.Exit. If a TestMain function returns, the test binary will call os.Exit with the value returned by m.Run.

So I don't think golangci-lint should report that error on go 1.22.

@ldez ldez reopened this Aug 14, 2024
@ldez ldez added bug Something isn't working and removed question Further information is requested labels Aug 14, 2024
@ldez
Copy link
Member

ldez commented Aug 14, 2024

It's related to a change of staticcheck with the way to handle the Go version.

@glassmonkey
Copy link

related?
version specification removed
#4836

@ldez
Copy link
Member

ldez commented Aug 14, 2024

I don't understand your comment.
Can you be more clear?

@glassmonkey
Copy link

I'm not very good at English, so I apologize for my poor expression.

As you may have noticed, it seems that the Go version for staticlint is not being propagated correctly.
I have a hunch that the recent version upgrade might be the issue, which is what I meant in my previous comment.

Thank you for your prompt response.

@skaji
Copy link
Author

skaji commented Aug 14, 2024

@ldez Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants