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

     1  package golinters
     2  
     3  import (
     4  	"github.com/polyfloyd/go-errorlint/errorlint"
     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  func NewErrorLint(cfg *config.ErrorLintSettings) *goanalysis.Linter {
    12  	a := errorlint.NewAnalyzer()
    13  
    14  	cfgMap := map[string]map[string]any{}
    15  
    16  	if cfg != nil {
    17  		cfgMap[a.Name] = map[string]any{
    18  			"errorf":       cfg.Errorf,
    19  			"errorf-multi": cfg.ErrorfMulti,
    20  			"asserts":      cfg.Asserts,
    21  			"comparison":   cfg.Comparison,
    22  		}
    23  	}
    24  
    25  	return goanalysis.NewLinter(
    26  		a.Name,
    27  		"errorlint is a linter for that can be used to find code "+
    28  			"that will cause problems with the error wrapping scheme introduced in Go 1.13.",
    29  		[]*analysis.Analyzer{a},
    30  		cfgMap,
    31  	).WithLoadMode(goanalysis.LoadModeTypesInfo)
    32  }