Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

errcheck: add an option to remove default exclusions #2607

Merged
merged 1 commit into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .golangci.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
5 changes: 4 additions & 1 deletion pkg/golinters/errcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down