Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 60f33c9

Browse files
committed
golangci: support running errcheck with all its options
Follow golangci/golangci-lint#223, I've added the option to run the errcheck linter with all its options. Also, kept backwards compatibility in order to do the transition in the golangci-lint package gradually.
1 parent f726ab7 commit 60f33c9

File tree

1 file changed

+47
-3
lines changed

1 file changed

+47
-3
lines changed

golangci/golangci.go

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,59 @@ import (
77
"golang.org/x/tools/go/loader"
88
)
99

10+
var dotStar = regexp.MustCompile(".*")
11+
1012
type Issue errcheck.UncheckedError
1113

1214
func Run(program *loader.Program, checkBlank, checkAsserts bool) ([]Issue, error) {
15+
return RunWithConfig(program, &Config{
16+
Blank: checkBlank,
17+
Asserts: checkAsserts,
18+
})
19+
}
20+
21+
// Config is a copy of the `errcheck.Checker` with exported `Exclude` field.
22+
type Config struct {
23+
// ignore is a map of package names to regular expressions. Identifiers from a package are
24+
// checked against its regular expressions and if any of the expressions match the call
25+
// is not checked.
26+
Ignore map[string]*regexp.Regexp
27+
28+
// If blank is true then assignments to the blank identifier are also considered to be
29+
// ignored errors.
30+
Blank bool
31+
32+
// If asserts is true then ignored type assertion results are also checked
33+
Asserts bool
34+
35+
// build tags
36+
Tags []string
37+
38+
Verbose bool
39+
40+
// If true, checking of _test.go files is disabled
41+
WithoutTests bool
42+
43+
// Excluded functions.
44+
Exclude map[string]bool
45+
}
46+
47+
// RunWithConfig runs the `errchecker` linter with all its options.
48+
func RunWithConfig(program *loader.Program, c *Config) ([]Issue, error) {
1349
checker := errcheck.NewChecker()
14-
checker.Blank = checkBlank
15-
checker.Asserts = checkAsserts
50+
checker.Tags = c.Tags
51+
checker.Blank = c.Blank
52+
checker.Asserts = c.Asserts
53+
checker.Verbose = c.Verbose
54+
checker.WithoutTests = c.WithoutTests
55+
56+
checker.SetExclude(c.Exclude)
1657

1758
checker.Ignore = map[string]*regexp.Regexp{
18-
"fmt": regexp.MustCompile(".*"),
59+
"fmt": dotStar,
60+
}
61+
for pkg, re := range c.Ignore {
62+
checker.Ignore[pkg] = re
1963
}
2064

2165
if err := checker.CheckProgram(program); err != nil {

0 commit comments

Comments
 (0)