fix: add missing ifshort configuration. (#1672)

This commit is contained in:
Ludovic Fernandez 2021-02-01 23:13:53 +01:00 committed by GitHub
parent 5694c50144
commit 60455b502b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 3 deletions

View File

@ -485,6 +485,10 @@ var defaultLintersSettings = LintersSettings{
ErrorLint: ErrorLintSettings{ ErrorLint: ErrorLintSettings{
Errorf: true, Errorf: true,
}, },
Ifshort: IfshortSettings{
MaxDeclLines: 1,
MaxDeclChars: 30,
},
Predeclared: PredeclaredSettings{ Predeclared: PredeclaredSettings{
Ignore: "", Ignore: "",
Qualified: false, Qualified: false,

View File

@ -4,14 +4,25 @@ import (
"github.com/esimonov/ifshort/pkg/analyzer" "github.com/esimonov/ifshort/pkg/analyzer"
"golang.org/x/tools/go/analysis" "golang.org/x/tools/go/analysis"
"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
) )
func NewIfshort() *goanalysis.Linter { func NewIfshort(settings *config.IfshortSettings) *goanalysis.Linter {
var cfg map[string]map[string]interface{}
if settings != nil {
cfg = map[string]map[string]interface{}{
analyzer.Analyzer.Name: {
"max-decl-lines": settings.MaxDeclLines,
"max-decl-chars": settings.MaxDeclChars,
},
}
}
return goanalysis.NewLinter( return goanalysis.NewLinter(
"ifshort", "ifshort",
"Checks that your code uses short syntax for if-statements whenever possible", "Checks that your code uses short syntax for if-statements whenever possible",
[]*analysis.Analyzer{analyzer.Analyzer}, []*analysis.Analyzer{analyzer.Analyzer},
nil, cfg,
).WithLoadMode(goanalysis.LoadModeSyntax) ).WithLoadMode(goanalysis.LoadModeSyntax)
} }

View File

@ -95,6 +95,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
var errorlintCfg *config.ErrorLintSettings var errorlintCfg *config.ErrorLintSettings
var thelperCfg *config.ThelperSettings var thelperCfg *config.ThelperSettings
var predeclaredCfg *config.PredeclaredSettings var predeclaredCfg *config.PredeclaredSettings
var ifshortCfg *config.IfshortSettings
if m.cfg != nil { if m.cfg != nil {
govetCfg = &m.cfg.LintersSettings.Govet govetCfg = &m.cfg.LintersSettings.Govet
testpackageCfg = &m.cfg.LintersSettings.Testpackage testpackageCfg = &m.cfg.LintersSettings.Testpackage
@ -102,6 +103,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
errorlintCfg = &m.cfg.LintersSettings.ErrorLint errorlintCfg = &m.cfg.LintersSettings.ErrorLint
thelperCfg = &m.cfg.LintersSettings.Thelper thelperCfg = &m.cfg.LintersSettings.Thelper
predeclaredCfg = &m.cfg.LintersSettings.Predeclared predeclaredCfg = &m.cfg.LintersSettings.Predeclared
ifshortCfg = &m.cfg.LintersSettings.Ifshort
} }
const megacheckName = "megacheck" const megacheckName = "megacheck"
lcs := []*linter.Config{ lcs := []*linter.Config{
@ -344,7 +346,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
linter.NewConfig(golinters.NewForbidigo()). linter.NewConfig(golinters.NewForbidigo()).
WithPresets(linter.PresetStyle). WithPresets(linter.PresetStyle).
WithURL("https://github.com/ashanbrown/forbidigo"), WithURL("https://github.com/ashanbrown/forbidigo"),
linter.NewConfig(golinters.NewIfshort()). linter.NewConfig(golinters.NewIfshort(ifshortCfg)).
WithPresets(linter.PresetStyle). WithPresets(linter.PresetStyle).
WithURL("https://github.com/esimonov/ifshort"), WithURL("https://github.com/esimonov/ifshort"),
linter.NewConfig(golinters.NewPredeclared(predeclaredCfg)). linter.NewConfig(golinters.NewPredeclared(predeclaredCfg)).