github.com/chenfeining/golangci-lint@v1.0.2-0.20230730162517-14c6c67868df/pkg/golinters/wrapcheck.go (about)

     1  package golinters
     2  
     3  import (
     4  	"github.com/tomarrell/wrapcheck/v2/wrapcheck"
     5  	"golang.org/x/tools/go/analysis"
     6  
     7  	"github.com/chenfeining/golangci-lint/pkg/config"
     8  	"github.com/chenfeining/golangci-lint/pkg/golinters/goanalysis"
     9  )
    10  
    11  const wrapcheckName = "wrapcheck"
    12  
    13  func NewWrapcheck(settings *config.WrapcheckSettings) *goanalysis.Linter {
    14  	cfg := wrapcheck.NewDefaultConfig()
    15  	if settings != nil {
    16  		if len(settings.IgnoreSigs) != 0 {
    17  			cfg.IgnoreSigs = settings.IgnoreSigs
    18  		}
    19  		if len(settings.IgnoreSigRegexps) != 0 {
    20  			cfg.IgnoreSigRegexps = settings.IgnoreSigRegexps
    21  		}
    22  		if len(settings.IgnorePackageGlobs) != 0 {
    23  			cfg.IgnorePackageGlobs = settings.IgnorePackageGlobs
    24  		}
    25  		if len(settings.IgnoreInterfaceRegexps) != 0 {
    26  			cfg.IgnoreInterfaceRegexps = settings.IgnoreInterfaceRegexps
    27  		}
    28  	}
    29  
    30  	a := wrapcheck.NewAnalyzer(cfg)
    31  
    32  	return goanalysis.NewLinter(
    33  		wrapcheckName,
    34  		a.Doc,
    35  		[]*analysis.Analyzer{a},
    36  		nil,
    37  	).WithLoadMode(goanalysis.LoadModeTypesInfo)
    38  }