|
1 | 1 | package lintersdb |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "regexp" |
| 5 | + |
4 | 6 | "github.com/golangci/golangci-lint/pkg/config" |
5 | 7 | "github.com/golangci/golangci-lint/pkg/golinters" |
6 | 8 | "github.com/golangci/golangci-lint/pkg/lint/linter" |
@@ -227,24 +229,24 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config { |
227 | 229 | } |
228 | 230 |
|
229 | 231 | if gocriticCfg != nil { |
230 | | - gocriticCfg.Go = m.cfg.Run.Go |
| 232 | + gocriticCfg.Go = trimGoVersion(m.cfg.Run.Go) |
231 | 233 | } |
232 | 234 |
|
233 | 235 | if gofumptCfg != nil && gofumptCfg.LangVersion == "" { |
234 | 236 | gofumptCfg.LangVersion = m.cfg.Run.Go |
235 | 237 | } |
236 | 238 |
|
237 | 239 | if staticcheckCfg != nil && staticcheckCfg.GoVersion == "" { |
238 | | - staticcheckCfg.GoVersion = m.cfg.Run.Go |
| 240 | + staticcheckCfg.GoVersion = trimGoVersion(m.cfg.Run.Go) |
239 | 241 | } |
240 | 242 | if gosimpleCfg != nil && gosimpleCfg.GoVersion == "" { |
241 | | - gosimpleCfg.GoVersion = m.cfg.Run.Go |
| 243 | + gosimpleCfg.GoVersion = trimGoVersion(m.cfg.Run.Go) |
242 | 244 | } |
243 | 245 | if stylecheckCfg != nil && stylecheckCfg.GoVersion != "" { |
244 | | - stylecheckCfg.GoVersion = m.cfg.Run.Go |
| 246 | + stylecheckCfg.GoVersion = trimGoVersion(m.cfg.Run.Go) |
245 | 247 | } |
246 | 248 | if unusedCfg != nil && unusedCfg.GoVersion == "" { |
247 | | - unusedCfg.GoVersion = m.cfg.Run.Go |
| 249 | + unusedCfg.GoVersion = trimGoVersion(m.cfg.Run.Go) |
248 | 250 | } |
249 | 251 | } |
250 | 252 |
|
@@ -928,3 +930,21 @@ func (m Manager) GetAllLinterConfigsForPreset(p string) []*linter.Config { |
928 | 930 |
|
929 | 931 | return ret |
930 | 932 | } |
| 933 | + |
| 934 | +// Trims the Go version to keep only M.m. |
| 935 | +// Since Go 1.21 the version inside the go.mod can be a patched version (ex: 1.21.0). |
| 936 | +// https://go.dev/doc/toolchain#versions |
| 937 | +// This a problem with staticcheck and gocritic. |
| 938 | +func trimGoVersion(v string) string { |
| 939 | + if v == "" { |
| 940 | + return "" |
| 941 | + } |
| 942 | + |
| 943 | + exp := regexp.MustCompile(`(\d\.\d+)\.\d+`) |
| 944 | + |
| 945 | + if exp.MatchString(v) { |
| 946 | + return exp.FindStringSubmatch(v)[1] |
| 947 | + } |
| 948 | + |
| 949 | + return v |
| 950 | +} |
0 commit comments