@@ -11,6 +11,7 @@ import (
1111 "golang.org/x/tools/go/analysis"
1212 "mvdan.cc/gofumpt/format"
1313
14+ "github.com/golangci/golangci-lint/pkg/config"
1415 "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
1516 "github.com/golangci/golangci-lint/pkg/lint/linter"
1617)
@@ -32,6 +33,13 @@ func NewGofumpt() *goanalysis.Linter {
3233 []* analysis.Analyzer {analyzer },
3334 nil ,
3435 ).WithContextSetter (func (lintCtx * linter.Context ) {
36+ settings := lintCtx .Settings ().Gofumpt
37+
38+ options := format.Options {
39+ LangVersion : getLangVersion (settings ),
40+ ExtraRules : settings .ExtraRules ,
41+ }
42+
3543 analyzer .Run = func (pass * analysis.Pass ) (interface {}, error ) {
3644 var fileNames []string
3745 for _ , f := range pass .Files {
@@ -46,12 +54,12 @@ func NewGofumpt() *goanalysis.Linter {
4654 if err != nil {
4755 return nil , fmt .Errorf ("unable to open file %s: %w" , f , err )
4856 }
49- output , err := format .Source (input , format.Options {
50- ExtraRules : lintCtx .Settings ().Gofumpt .ExtraRules ,
51- })
57+
58+ output , err := format .Source (input , options )
5259 if err != nil {
5360 return nil , fmt .Errorf ("error while running gofumpt: %w" , err )
5461 }
62+
5563 if ! bytes .Equal (input , output ) {
5664 out := bytes.Buffer {}
5765 _ , err = out .WriteString (fmt .Sprintf ("--- %[1]s\n +++ %[1]s\n " , f ))
@@ -90,3 +98,11 @@ func NewGofumpt() *goanalysis.Linter {
9098 return resIssues
9199 }).WithLoadMode (goanalysis .LoadModeSyntax )
92100}
101+
102+ func getLangVersion (settings config.GofumptSettings ) string {
103+ if settings .LangVersion == "" {
104+ // TODO: defaults to "1.15", in the future (v2) must be set by using build.Default.ReleaseTags like staticcheck.
105+ return "1.15"
106+ }
107+ return settings .LangVersion
108+ }
0 commit comments