From 29e3261325d025b613cb2baea4b1a04cd9ce3fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sandro=20J=C3=A4ckel?= Date: Thu, 21 Mar 2024 15:14:32 +0100 Subject: [PATCH] Disable exportloopref in go 1.22 or above --- .golangci.yaml | 1 - internal/golangcilint/golangci_lint.go | 17 +++++++++++------ main.go | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index 8eae191..c62651f 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -115,7 +115,6 @@ linters: - durationcheck - errcheck - errorlint - - exportloopref - forbidigo - ginkgolinter - gocheckcompilerdirectives diff --git a/internal/golangcilint/golangci_lint.go b/internal/golangcilint/golangci_lint.go index fc2ab26..2ad776b 100644 --- a/internal/golangcilint/golangci_lint.go +++ b/internal/golangcilint/golangci_lint.go @@ -17,6 +17,7 @@ package golangcilint import ( "fmt" "os" + "strconv" "strings" "text/template" @@ -157,7 +158,9 @@ linters: - durationcheck - errcheck - errorlint + {{- if lt .GoMinorVersion 22 }} - exportloopref + {{- end }} - forbidigo - ginkgolinter - gocheckcompilerdirectives @@ -188,6 +191,7 @@ linters: `, "\t", " ")))) type configTmplData struct { + GoMinorVersion int ModulePath string ModDownloadMode string MisspellIgnoreWords []string @@ -195,20 +199,21 @@ type configTmplData struct { SkipDirs []string } -func RenderConfig(cfg core.GolangciLintConfiguration, vendoring bool, modulePath string, misspellIgnoreWords []string) { +func RenderConfig(cfg core.Configuration, sr core.ScanResult) { mode := "readonly" - if vendoring { + if cfg.Golang.EnableVendoring { mode = "vendor" } f := must.Return(os.Create(".golangci.yaml")) fmt.Fprintln(f, core.AutogeneratedHeader+"\n") must.Succeed(configTmpl.Execute(f, configTmplData{ - ModulePath: modulePath, + GoMinorVersion: must.Return(strconv.Atoi(strings.Split(sr.GoVersion, ".")[1])), + ModulePath: sr.MustModulePath(), ModDownloadMode: mode, - MisspellIgnoreWords: misspellIgnoreWords, - ErrcheckExcludes: cfg.ErrcheckExcludes, - SkipDirs: cfg.SkipDirs, + MisspellIgnoreWords: cfg.SpellCheck.IgnoreWords, + ErrcheckExcludes: cfg.GolangciLint.ErrcheckExcludes, + SkipDirs: cfg.GolangciLint.SkipDirs, })) fmt.Fprintln(f) // empty line at end diff --git a/main.go b/main.go index b40e9cc..896efe4 100644 --- a/main.go +++ b/main.go @@ -73,7 +73,7 @@ func main() { // Render golangci-lint config file if cfg.GolangciLint.CreateConfig { - golangcilint.RenderConfig(cfg.GolangciLint, cfg.Golang.EnableVendoring, sr.MustModulePath(), cfg.SpellCheck.IgnoreWords) + golangcilint.RenderConfig(cfg, sr) } // Render Goreleaser config file