Skip to content

Commit

Permalink
Disable exportloopref in go 1.22 or above
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperSandro2000 committed Mar 21, 2024
1 parent d9de26b commit 29e3261
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
1 change: 0 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ linters:
- durationcheck
- errcheck
- errorlint
- exportloopref
- forbidigo
- ginkgolinter
- gocheckcompilerdirectives
Expand Down
17 changes: 11 additions & 6 deletions internal/golangcilint/golangci_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package golangcilint
import (
"fmt"
"os"
"strconv"
"strings"
"text/template"

Expand Down Expand Up @@ -157,7 +158,9 @@ linters:
- durationcheck
- errcheck
- errorlint
{{- if lt .GoMinorVersion 22 }}
- exportloopref
{{- end }}
- forbidigo
- ginkgolinter
- gocheckcompilerdirectives
Expand Down Expand Up @@ -188,27 +191,29 @@ linters:
`, "\t", " "))))

type configTmplData struct {
GoMinorVersion int
ModulePath string
ModDownloadMode string
MisspellIgnoreWords []string
ErrcheckExcludes []string
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

Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29e3261

Please sign in to comment.