Skip to content

Commit

Permalink
fix: add missing ifshort configuration. (#1672)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Feb 1, 2021
1 parent 5694c50 commit 60455b5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions pkg/config/config.go
Expand Up @@ -485,6 +485,10 @@ var defaultLintersSettings = LintersSettings{
ErrorLint: ErrorLintSettings{
Errorf: true,
},
Ifshort: IfshortSettings{
MaxDeclLines: 1,
MaxDeclChars: 30,
},
Predeclared: PredeclaredSettings{
Ignore: "",
Qualified: false,
Expand Down
15 changes: 13 additions & 2 deletions pkg/golinters/ifshort.go
Expand Up @@ -4,14 +4,25 @@ import (
"github.com/esimonov/ifshort/pkg/analyzer"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"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(
"ifshort",
"Checks that your code uses short syntax for if-statements whenever possible",
[]*analysis.Analyzer{analyzer.Analyzer},
nil,
cfg,
).WithLoadMode(goanalysis.LoadModeSyntax)
}
4 changes: 3 additions & 1 deletion pkg/lint/lintersdb/manager.go
Expand Up @@ -95,13 +95,15 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
var errorlintCfg *config.ErrorLintSettings
var thelperCfg *config.ThelperSettings
var predeclaredCfg *config.PredeclaredSettings
var ifshortCfg *config.IfshortSettings
if m.cfg != nil {
govetCfg = &m.cfg.LintersSettings.Govet
testpackageCfg = &m.cfg.LintersSettings.Testpackage
exhaustiveCfg = &m.cfg.LintersSettings.Exhaustive
errorlintCfg = &m.cfg.LintersSettings.ErrorLint
thelperCfg = &m.cfg.LintersSettings.Thelper
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
ifshortCfg = &m.cfg.LintersSettings.Ifshort
}
const megacheckName = "megacheck"
lcs := []*linter.Config{
Expand Down Expand Up @@ -344,7 +346,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
linter.NewConfig(golinters.NewForbidigo()).
WithPresets(linter.PresetStyle).
WithURL("https://github.com/ashanbrown/forbidigo"),
linter.NewConfig(golinters.NewIfshort()).
linter.NewConfig(golinters.NewIfshort(ifshortCfg)).
WithPresets(linter.PresetStyle).
WithURL("https://github.com/esimonov/ifshort"),
linter.NewConfig(golinters.NewPredeclared(predeclaredCfg)).
Expand Down

0 comments on commit 60455b5

Please sign in to comment.