
* Initial commit * Fixed goimports * Update pkg/golinters/mnd.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * Run goimports * Update pkg/golinters/mnd.go Co-Authored-By: Bot from GolangCI <42910462+golangcibot@users.noreply.github.com> * Add prefix for goimport local * Run make README.md * Incorporate review comments Add test cases * Update readme * Update the description * Removed subpath in local-prefixes * Update readme
59 lines
980 B
Go
59 lines
980 B
Go
package magic_numbers
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/tommy-muehle/go-mnd/checks"
|
|
)
|
|
|
|
var knownChecks = map[string]bool{
|
|
checks.ArgumentCheck: true,
|
|
checks.CaseCheck: true,
|
|
checks.ConditionCheck: true,
|
|
checks.OperationCheck: true,
|
|
checks.ReturnCheck: true,
|
|
checks.AssignCheck: true,
|
|
}
|
|
|
|
type Config struct {
|
|
Checks map[string]bool
|
|
}
|
|
|
|
type Option func(config *Config)
|
|
|
|
func DefaultConfig() *Config {
|
|
return &Config{
|
|
Checks: knownChecks,
|
|
}
|
|
}
|
|
|
|
func WithOptions(options ...Option) *Config {
|
|
c := DefaultConfig()
|
|
for _, option := range options {
|
|
option(c)
|
|
}
|
|
return c
|
|
}
|
|
|
|
func WithCustomChecks(checks string) Option {
|
|
return func(config *Config) {
|
|
config.Checks = knownChecks
|
|
|
|
if checks == "" {
|
|
return
|
|
}
|
|
|
|
for name, _ := range knownChecks {
|
|
config.Checks[name] = false
|
|
}
|
|
|
|
for _, name := range strings.Split(checks, ",") {
|
|
config.Checks[name] = true
|
|
}
|
|
}
|
|
}
|
|
|
|
func (c *Config) IsCheckEnabled(name string) bool {
|
|
return c.Checks[name]
|
|
}
|