Skip to content

Commit 244e949

Browse files
ldezSeigeC
authored andcommitted
errcheck: add an option to remove default exclusions (golangci#2607)
1 parent 9a6de2e commit 244e949

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

.golangci.example.yml

+5
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,11 @@ linters-settings:
204204
# see https://github.com/kisielk/errcheck#the-deprecated-method for details
205205
ignore: fmt:.*,io/ioutil:^Read.*
206206

207+
# To disable the errcheck built-in exclude list.
208+
# See `-excludeonly` option in https://github.com/kisielk/errcheck#excluding-functions for details.
209+
# Default: false
210+
disable-default-exclusions: true
211+
207212
# DEPRECATED use exclude-functions instead.
208213
#
209214
# Path to a file containing a list of functions to exclude from checking.

pkg/config/linters_settings.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -215,10 +215,11 @@ type DuplSettings struct {
215215
}
216216

217217
type ErrcheckSettings struct {
218-
CheckTypeAssertions bool `mapstructure:"check-type-assertions"`
219-
CheckAssignToBlank bool `mapstructure:"check-blank"`
220-
Ignore string `mapstructure:"ignore"`
221-
ExcludeFunctions []string `mapstructure:"exclude-functions"`
218+
DisableDefaultExclusions bool `mapstructure:"disable-default-exclusions"`
219+
CheckTypeAssertions bool `mapstructure:"check-type-assertions"`
220+
CheckAssignToBlank bool `mapstructure:"check-blank"`
221+
Ignore string `mapstructure:"ignore"`
222+
ExcludeFunctions []string `mapstructure:"exclude-functions"`
222223

223224
// Deprecated: use ExcludeFunctions instead
224225
Exclude string `mapstructure:"exclude"`

pkg/golinters/errcheck.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,13 @@ func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
140140
BlankAssignments: !errCfg.CheckAssignToBlank,
141141
TypeAssertions: !errCfg.CheckTypeAssertions,
142142
SymbolRegexpsByPackage: map[string]*regexp.Regexp{},
143-
Symbols: append([]string{}, errcheck.DefaultExcludedSymbols...),
144143
},
145144
}
146145

146+
if !errCfg.DisableDefaultExclusions {
147+
checker.Exclusions.Symbols = append(checker.Exclusions.Symbols, errcheck.DefaultExcludedSymbols...)
148+
}
149+
147150
for pkg, re := range ignoreConfig {
148151
checker.Exclusions.SymbolRegexpsByPackage[pkg] = re
149152
}

0 commit comments

Comments
 (0)