Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(staticcheck): configurable Go version.
- Loading branch information
Showing
7 changed files
with
60 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,33 @@ | ||
package golinters | ||
|
||
import ( | ||
"fmt" | ||
|
||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/logutils" | ||
) | ||
|
||
var debugf = logutils.Debug("megacheck") | ||
|
||
func analyzersMapToSlice(m map[string]*analysis.Analyzer) []*analysis.Analyzer { | ||
func setupStaticCheckAnalyzers(m map[string]*analysis.Analyzer, settings *config.StaticCheckSettings) []*analysis.Analyzer { | ||
var ret []*analysis.Analyzer | ||
for _, v := range m { | ||
setAnalyzerGoVersion(v, settings) | ||
ret = append(ret, v) | ||
} | ||
return ret | ||
} | ||
|
||
func setAnalyzersGoVersion(analyzers []*analysis.Analyzer) { | ||
const goVersion = 13 // TODO | ||
for _, a := range analyzers { | ||
if v := a.Flags.Lookup("go"); v != nil { | ||
if err := v.Value.Set(fmt.Sprintf("1.%d", goVersion)); err != nil { | ||
debugf("Failed to set go version: %s", err) | ||
} | ||
func setAnalyzerGoVersion(a *analysis.Analyzer, settings *config.StaticCheckSettings) { | ||
// TODO: uses "1.13" for backward compatibility, but in the future (v2) must be set by using build.Default.ReleaseTags like staticcheck. | ||
goVersion := "1.13" | ||
if settings != nil && settings.GoVersion != "" { | ||
goVersion = settings.GoVersion | ||
} | ||
|
||
if v := a.Flags.Lookup("go"); v != nil { | ||
if err := v.Value.Set(goVersion); err != nil { | ||
debugf("Failed to set go version: %s", err) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters