github.com/nozzle/golangci-lint@v1.49.0-nz3/pkg/golinters/gomnd.go (about)

     1  package golinters
     2  
     3  import (
     4  	mnd "github.com/tommy-muehle/go-mnd/v2"
     5  	"golang.org/x/tools/go/analysis"
     6  
     7  	"github.com/golangci/golangci-lint/pkg/config"
     8  	"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
     9  )
    10  
    11  func NewGoMND(settings *config.GoMndSettings) *goanalysis.Linter {
    12  	var linterCfg map[string]map[string]interface{}
    13  
    14  	if settings != nil {
    15  		// TODO(ldez) For compatibility only, must be drop in v2.
    16  		if len(settings.Settings) > 0 {
    17  			linterCfg = settings.Settings
    18  		} else {
    19  			cfg := make(map[string]interface{})
    20  			if len(settings.Checks) > 0 {
    21  				cfg["checks"] = settings.Checks
    22  			}
    23  			if len(settings.IgnoredNumbers) > 0 {
    24  				cfg["ignored-numbers"] = settings.IgnoredNumbers
    25  			}
    26  			if len(settings.IgnoredFiles) > 0 {
    27  				cfg["ignored-files"] = settings.IgnoredFiles
    28  			}
    29  			if len(settings.IgnoredFunctions) > 0 {
    30  				cfg["ignored-functions"] = settings.IgnoredFunctions
    31  			}
    32  
    33  			linterCfg = map[string]map[string]interface{}{
    34  				"mnd": cfg,
    35  			}
    36  		}
    37  	}
    38  
    39  	return goanalysis.NewLinter(
    40  		"gomnd",
    41  		"An analyzer to detect magic numbers.",
    42  		[]*analysis.Analyzer{mnd.Analyzer},
    43  		linterCfg,
    44  	).WithLoadMode(goanalysis.LoadModeSyntax)
    45  }