File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 11package config
22
33import (
4+ "fmt"
5+ "go/version"
46 "os"
57 "regexp"
8+ "runtime"
69 "strings"
710
811 hcversion "github.com/hashicorp/go-version"
@@ -108,3 +111,37 @@ func trimGoVersion(v string) string {
108111
109112 return v
110113}
114+
115+ func getRuntimeGoVersion () string {
116+ goVersion := runtime .Version ()
117+
118+ parts := strings .Fields (goVersion )
119+
120+ if len (parts ) == 0 {
121+ return goVersion
122+ }
123+
124+ // When using GOEXPERIMENT, the version returned might look something like "go1.23.0 X:boringcrypto".
125+ return parts [0 ]
126+ }
127+
128+ func checkGoVersion (goVersion string ) error {
129+ langVersion := version .Lang (getRuntimeGoVersion ())
130+
131+ runtimeVersion , err := hcversion .NewVersion (strings .TrimPrefix (langVersion , "go" ))
132+ if err != nil {
133+ return err
134+ }
135+
136+ targetedVersion , err := hcversion .NewVersion (trimGoVersion (goVersion ))
137+ if err != nil {
138+ return err
139+ }
140+
141+ if runtimeVersion .LessThan (targetedVersion ) {
142+ return fmt .Errorf ("the Go language version (%s) used to build golangci-lint is lower than the targeted Go version (%s)" ,
143+ langVersion , goVersion )
144+ }
145+
146+ return nil
147+ }
Original file line number Diff line number Diff line change @@ -74,6 +74,11 @@ func (l *Loader) Load(opts LoadOptions) error {
7474
7575 l .handleGoVersion ()
7676
77+ err = checkGoVersion (l .cfg .Run .Go )
78+ if err != nil {
79+ return err
80+ }
81+
7782 err = l .handleEnableOnlyOption ()
7883 if err != nil {
7984 return err
You can’t perform that action at this time.
0 commit comments