2021-11-14 20:01:54 +00:00
|
|
|
package golinters
|
|
|
|
|
|
|
|
import (
|
|
|
|
mnd "github.com/tommy-muehle/go-mnd/v2"
|
|
|
|
"golang.org/x/tools/go/analysis"
|
|
|
|
|
|
|
|
"github.com/golangci/golangci-lint/pkg/config"
|
|
|
|
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
|
|
|
|
)
|
|
|
|
|
2022-02-24 16:33:24 +00:00
|
|
|
func NewGoMND(settings *config.GoMndSettings) *goanalysis.Linter {
|
2021-11-14 20:01:54 +00:00
|
|
|
var linterCfg map[string]map[string]interface{}
|
2022-02-24 16:33:24 +00:00
|
|
|
|
|
|
|
if settings != nil {
|
|
|
|
// TODO(ldez) For compatibility only, must be drop in v2.
|
|
|
|
if len(settings.Settings) > 0 {
|
|
|
|
linterCfg = settings.Settings
|
|
|
|
} else {
|
|
|
|
cfg := make(map[string]interface{})
|
|
|
|
if len(settings.Checks) > 0 {
|
|
|
|
cfg["checks"] = settings.Checks
|
|
|
|
}
|
|
|
|
if len(settings.IgnoredNumbers) > 0 {
|
|
|
|
cfg["ignored-numbers"] = settings.IgnoredNumbers
|
|
|
|
}
|
|
|
|
if len(settings.IgnoredFiles) > 0 {
|
|
|
|
cfg["ignored-files"] = settings.IgnoredFiles
|
|
|
|
}
|
|
|
|
if len(settings.IgnoredFunctions) > 0 {
|
|
|
|
cfg["ignored-functions"] = settings.IgnoredFunctions
|
|
|
|
}
|
|
|
|
|
|
|
|
linterCfg = map[string]map[string]interface{}{
|
|
|
|
"mnd": cfg,
|
|
|
|
}
|
|
|
|
}
|
2021-11-14 20:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return goanalysis.NewLinter(
|
|
|
|
"gomnd",
|
|
|
|
"An analyzer to detect magic numbers.",
|
2022-02-24 16:33:24 +00:00
|
|
|
[]*analysis.Analyzer{mnd.Analyzer},
|
2021-11-14 20:01:54 +00:00
|
|
|
linterCfg,
|
|
|
|
).WithLoadMode(goanalysis.LoadModeSyntax)
|
|
|
|
}
|