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

     1  package golinters
     2  
     3  import (
     4  	"github.com/breml/errchkjson"
     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 NewErrChkJSONFuncName(cfg *config.ErrChkJSONSettings) *goanalysis.Linter {
    12  	a := errchkjson.NewAnalyzer()
    13  
    14  	cfgMap := map[string]map[string]interface{}{}
    15  	cfgMap[a.Name] = map[string]interface{}{
    16  		"omit-safe": true,
    17  	}
    18  	if cfg != nil {
    19  		cfgMap[a.Name] = map[string]interface{}{
    20  			"omit-safe":          !cfg.CheckErrorFreeEncoding,
    21  			"report-no-exported": cfg.ReportNoExported,
    22  		}
    23  	}
    24  
    25  	return goanalysis.NewLinter(
    26  		"errchkjson",
    27  		"Checks types passed to the json encoding functions. "+
    28  			"Reports unsupported types and optionally reports occasions, "+
    29  			"where the check for the returned error can be omitted.",
    30  		[]*analysis.Analyzer{a},
    31  		cfgMap,
    32  	).WithLoadMode(goanalysis.LoadModeTypesInfo)
    33  }