Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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