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 1
1
package config
2
2
3
3
import (
4
+ "fmt"
5
+ "go/version"
4
6
"os"
5
7
"regexp"
8
+ "runtime"
6
9
"strings"
7
10
8
11
hcversion "github.com/hashicorp/go-version"
@@ -108,3 +111,37 @@ func trimGoVersion(v string) string {
108
111
109
112
return v
110
113
}
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 {
74
74
75
75
l .handleGoVersion ()
76
76
77
+ err = checkGoVersion (l .cfg .Run .Go )
78
+ if err != nil {
79
+ return err
80
+ }
81
+
77
82
err = l .handleEnableOnlyOption ()
78
83
if err != nil {
79
84
return err
You can’t perform that action at this time.
0 commit comments