Skip to content

Commit

Permalink
Update errcheck after kisielk/errcheck#185 is merged
Browse files Browse the repository at this point in the history
  • Loading branch information
leventov authored and ldez committed Dec 27, 2020
1 parent 4c88f08 commit 8f88386
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 20 deletions.
3 changes: 1 addition & 2 deletions go.mod
Expand Up @@ -34,6 +34,7 @@ require (
github.com/kunwardeep/paralleltest v1.0.2
github.com/kyoh86/exportloopref v0.1.8
github.com/kisielk/errcheck v1.4.1-0.20200802052755-ea6ea2fa7078
github.com/kisielk/errcheck v1.5.0-alpha.0.20201210184435-7e1276f76cf6
github.com/kyoh86/exportloopref v0.1.7
github.com/maratori/testpackage v1.0.1
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb // v1.0
Expand Down Expand Up @@ -78,5 +79,3 @@ require (
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b // indirect
mvdan.cc/unparam v0.0.0-20200501210554-b37ab49443f7
)

replace github.com/kisielk/errcheck => /Users/sergey.vilgelm@ibm.com/icloud/projects/errcheck
12 changes: 12 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 11 additions & 13 deletions pkg/golinters/errcheck.go
Expand Up @@ -42,7 +42,6 @@ func NewErrcheck() *goanalysis.Linter {
if err != nil {
panic(err.Error())
}
checker.Verbose = lintCtx.Cfg.Run.IsVerbose
checker.Tags = lintCtx.Cfg.Run.BuildTags

analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
Expand All @@ -54,12 +53,12 @@ func NewErrcheck() *goanalysis.Linter {
}

errcheckIssues := checker.CheckPackage(pkg)
if len(errcheckIssues) == 0 {
if len(errcheckIssues.UncheckedErrors) == 0 {
return nil, nil
}

issues := make([]goanalysis.Issue, 0, len(errcheckIssues))
for _, i := range errcheckIssues {
issues := make([]goanalysis.Issue, 0, len(errcheckIssues.UncheckedErrors))
for _, i := range errcheckIssues.UncheckedErrors {
var text string
if i.FuncName != "" {
text = fmt.Sprintf("Error return value of %s is not checked", formatCode(i.FuncName, lintCtx.Cfg))
Expand Down Expand Up @@ -112,31 +111,30 @@ func parseIgnoreConfig(s string) (map[string]*regexp.Regexp, error) {
}

func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
checker := errcheck.NewChecker()
checker.Blank = errCfg.CheckAssignToBlank
checker.Asserts = errCfg.CheckTypeAssertions
var checker errcheck.Checker
checker.Exclusions.BlankAssignments = !errCfg.CheckAssignToBlank
checker.Exclusions.TypeAssertions = !errCfg.CheckTypeAssertions

ignoreConfig, err := parseIgnoreConfig(errCfg.Ignore)
if err != nil {
return nil, errors.Wrap(err, "failed to parse 'ignore' directive")
}

checker.Ignore = map[string]*regexp.Regexp{}
checker.Exclusions.SymbolRegexpsByPackage = map[string]*regexp.Regexp{}
for pkg, re := range ignoreConfig {
checker.Ignore[pkg] = re
checker.Exclusions.SymbolRegexpsByPackage[pkg] = re
}
checker.UpdateNonVendoredIgnore()

checker.AddExcludes(errcheck.DefaultExcludes)
checker.Exclusions.Symbols = append([]string{}, errcheck.DefaultExcludedSymbols...)
if errCfg.Exclude != "" {
exclude, err := readExcludeFile(errCfg.Exclude)
if err != nil {
return nil, err
}
checker.AddExcludes(exclude)
checker.Exclusions.Symbols = append(checker.Exclusions.Symbols, exclude...)
}

return checker, nil
return &checker, nil
}

func getFirstPathArg() string {
Expand Down
2 changes: 1 addition & 1 deletion test/testdata/errcheck_exclude.go
Expand Up @@ -13,6 +13,6 @@ func TestErrcheckExclude() []byte {
}

func TestErrcheckNoExclude() []byte {
ret, _ := ioutil.ReadAll(nil) // ERROR "Error return value is not checked"
ret, _ := ioutil.ReadAll(nil) // ERROR "Error return value of `io/ioutil.ReadAll` is not checked"
return ret
}
6 changes: 3 additions & 3 deletions test/testdata/errcheck_ignore.go
Expand Up @@ -12,8 +12,8 @@ func TestErrcheckIgnoreOs() {
_, _ = os.Open("f.txt")
}

func TestErrcheckNoIgnoreFmt(s string) int {
n, _ := fmt.Println(s) // ERROR "Error return value is not checked"
func TestErrcheckIgnoreFmt(s string) int {
n, _ := fmt.Println(s)
return n
}

Expand All @@ -23,6 +23,6 @@ func TestErrcheckIgnoreIoutil() []byte {
}

func TestErrcheckNoIgnoreIoutil() []byte {
ret, _ := ioutil.ReadAll(nil) // ERROR "Error return value is not checked"
ret, _ := ioutil.ReadAll(nil) // ERROR "Error return value of `io/ioutil.ReadAll` is not checked"
return ret
}
2 changes: 1 addition & 1 deletion test/testdata/errcheck_ignore_default.go
Expand Up @@ -20,5 +20,5 @@ func TestErrcheckIgnoreFmtByDefault(s string) int {
}

func TestErrcheckNoIgnoreOs() {
_, _ = os.Open("f.txt") // ERROR "Error return value is not checked"
_, _ = os.Open("f.txt") // ERROR "Error return value of `os.Open` is not checked"
}

0 comments on commit 8f88386

Please sign in to comment.