Skip to content

Commit 60455b5

Browse files
authored
fix: add missing ifshort configuration. (#1672)
1 parent 5694c50 commit 60455b5

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

pkg/config/config.go

+4
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,10 @@ var defaultLintersSettings = LintersSettings{
485485
ErrorLint: ErrorLintSettings{
486486
Errorf: true,
487487
},
488+
Ifshort: IfshortSettings{
489+
MaxDeclLines: 1,
490+
MaxDeclChars: 30,
491+
},
488492
Predeclared: PredeclaredSettings{
489493
Ignore: "",
490494
Qualified: false,

pkg/golinters/ifshort.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@ import (
44
"github.com/esimonov/ifshort/pkg/analyzer"
55
"golang.org/x/tools/go/analysis"
66

7+
"github.com/golangci/golangci-lint/pkg/config"
78
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
89
)
910

10-
func NewIfshort() *goanalysis.Linter {
11+
func NewIfshort(settings *config.IfshortSettings) *goanalysis.Linter {
12+
var cfg map[string]map[string]interface{}
13+
if settings != nil {
14+
cfg = map[string]map[string]interface{}{
15+
analyzer.Analyzer.Name: {
16+
"max-decl-lines": settings.MaxDeclLines,
17+
"max-decl-chars": settings.MaxDeclChars,
18+
},
19+
}
20+
}
21+
1122
return goanalysis.NewLinter(
1223
"ifshort",
1324
"Checks that your code uses short syntax for if-statements whenever possible",
1425
[]*analysis.Analyzer{analyzer.Analyzer},
15-
nil,
26+
cfg,
1627
).WithLoadMode(goanalysis.LoadModeSyntax)
1728
}

pkg/lint/lintersdb/manager.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
9595
var errorlintCfg *config.ErrorLintSettings
9696
var thelperCfg *config.ThelperSettings
9797
var predeclaredCfg *config.PredeclaredSettings
98+
var ifshortCfg *config.IfshortSettings
9899
if m.cfg != nil {
99100
govetCfg = &m.cfg.LintersSettings.Govet
100101
testpackageCfg = &m.cfg.LintersSettings.Testpackage
101102
exhaustiveCfg = &m.cfg.LintersSettings.Exhaustive
102103
errorlintCfg = &m.cfg.LintersSettings.ErrorLint
103104
thelperCfg = &m.cfg.LintersSettings.Thelper
104105
predeclaredCfg = &m.cfg.LintersSettings.Predeclared
106+
ifshortCfg = &m.cfg.LintersSettings.Ifshort
105107
}
106108
const megacheckName = "megacheck"
107109
lcs := []*linter.Config{
@@ -344,7 +346,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
344346
linter.NewConfig(golinters.NewForbidigo()).
345347
WithPresets(linter.PresetStyle).
346348
WithURL("https://github.com/ashanbrown/forbidigo"),
347-
linter.NewConfig(golinters.NewIfshort()).
349+
linter.NewConfig(golinters.NewIfshort(ifshortCfg)).
348350
WithPresets(linter.PresetStyle).
349351
WithURL("https://github.com/esimonov/ifshort"),
350352
linter.NewConfig(golinters.NewPredeclared(predeclaredCfg)).

0 commit comments

Comments
 (0)