diff --git a/go.mod b/go.mod index d7eb951..a6c9650 100644 --- a/go.mod +++ b/go.mod @@ -4,10 +4,8 @@ go 1.22.0 require ( golang.org/x/exp v0.0.0-20230809094429-853ea248256d + golang.org/x/mod v0.21.0 golang.org/x/tools v0.26.0 ) -require ( - golang.org/x/mod v0.21.0 // indirect - golang.org/x/sync v0.8.0 // indirect -) +require golang.org/x/sync v0.8.0 // indirect diff --git a/timeafter/time_after.go b/timeafter/time_after.go index 9112739..2ff62f2 100644 --- a/timeafter/time_after.go +++ b/timeafter/time_after.go @@ -9,6 +9,7 @@ import ( "go/ast" "strings" + "golang.org/x/mod/semver" "golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis/passes/inspect" "golang.org/x/tools/go/ast/inspector" @@ -50,6 +51,18 @@ func run(pass *analysis.Pass) (interface{}, error) { return nil, errors.New("analyzer is not type *inspector.Inspector") } + var goVersion string + if pass.Module != nil { + goVersion = pass.Module.GoVersion + } + if semver.Compare(goVersion, "v1.23.0") >= 0 { + // Go version ≥ 1.23 no longer has the issue of not collecting unstopped Timers and + // time.After can safely be used in loops. Also see + // https://go.dev/doc/go1.23#timer-changes and + // https://cs.opensource.google/go/go/+/refs/tags/go1.23.2:src/time/sleep.go;l=196-201 + return nil, nil + } + ignoreMap := make(map[string]struct{}) for _, ign := range strings.Split(ignoreArg, ",") { ignoreMap[strings.TrimSpace(ign)] = struct{}{}