diff --git a/.golangci.example.yml b/.golangci.example.yml index 99b4e37453c3..725055451c3e 100644 --- a/.golangci.example.yml +++ b/.golangci.example.yml @@ -204,6 +204,11 @@ linters-settings: # see https://github.com/kisielk/errcheck#the-deprecated-method for details ignore: fmt:.*,io/ioutil:^Read.* + # To disable the errcheck built-in exclude list. + # See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details. + # Default: false + disable-default-exclusions: true + # DEPRECATED use exclude-functions instead. # # Path to a file containing a list of functions to exclude from checking. diff --git a/pkg/config/linters_settings.go b/pkg/config/linters_settings.go index 36a9af34c752..770183fbc967 100644 --- a/pkg/config/linters_settings.go +++ b/pkg/config/linters_settings.go @@ -215,10 +215,11 @@ type DuplSettings struct { } type ErrcheckSettings struct { - CheckTypeAssertions bool `mapstructure:"check-type-assertions"` - CheckAssignToBlank bool `mapstructure:"check-blank"` - Ignore string `mapstructure:"ignore"` - ExcludeFunctions []string `mapstructure:"exclude-functions"` + DisableDefaultExclusions bool `mapstructure:"disable-default-exclusions"` + CheckTypeAssertions bool `mapstructure:"check-type-assertions"` + CheckAssignToBlank bool `mapstructure:"check-blank"` + Ignore string `mapstructure:"ignore"` + ExcludeFunctions []string `mapstructure:"exclude-functions"` // Deprecated: use ExcludeFunctions instead Exclude string `mapstructure:"exclude"` diff --git a/pkg/golinters/errcheck.go b/pkg/golinters/errcheck.go index 0499c54ad337..faea6bcc246a 100644 --- a/pkg/golinters/errcheck.go +++ b/pkg/golinters/errcheck.go @@ -140,10 +140,13 @@ func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) { BlankAssignments: !errCfg.CheckAssignToBlank, TypeAssertions: !errCfg.CheckTypeAssertions, SymbolRegexpsByPackage: map[string]*regexp.Regexp{}, - Symbols: append([]string{}, errcheck.DefaultExcludedSymbols...), }, } + if !errCfg.DisableDefaultExclusions { + checker.Exclusions.Symbols = append(checker.Exclusions.Symbols, errcheck.DefaultExcludedSymbols...) + } + for pkg, re := range ignoreConfig { checker.Exclusions.SymbolRegexpsByPackage[pkg] = re }