Skip to content

Commit

Permalink
Add a go language version override config option for golangci-lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiquelefevre committed Jun 4, 2024
1 parent b66ede6 commit 9be7c9c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lint/config.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package lint

import (
goversion "github.com/hashicorp/go-version"
)

// Arguments is type used for the arguments of a rule.
type Arguments = []interface{}

Expand Down Expand Up @@ -61,4 +65,7 @@ type Config struct {
WarningCode int `toml:"warningCode"`
Directives DirectivesConfig `toml:"directive"`
Exclude []string `toml:"exclude"`
// If set, overrides the go language version specified in go.mod of
// packages being linted, and assumes this specific language version.
GoVersion *goversion.Version
}
4 changes: 4 additions & 0 deletions lint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ func (l *Linter) Lint(packages [][]string, ruleSet []Rule, config Config) (<-cha
if len(files) == 0 {
continue
}
if config.GoVersion != nil {
perPkgVersions[n] = config.GoVersion
continue
}

dir, err := filepath.Abs(filepath.Dir(files[0]))
if err != nil {
Expand Down

0 comments on commit 9be7c9c

Please sign in to comment.