Skip to content

Commit 0dce200

Browse files
committed
chore: remove deprecated errcheck tests
1 parent a353a7a commit 0dce200

File tree

6 files changed

+63
-120
lines changed

6 files changed

+63
-120
lines changed

pkg/golinters/errcheck/errcheck.go

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -111,35 +111,6 @@ func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck
111111
return issues
112112
}
113113

114-
// parseIgnoreConfig was taken from errcheck in order to keep the API identical.
115-
// https://github.com/kisielk/errcheck/blob/1787c4bee836470bf45018cfbc783650db3c6501/main.go#L25-L60
116-
func parseIgnoreConfig(s string) (map[string]*regexp.Regexp, error) {
117-
if s == "" {
118-
return nil, nil
119-
}
120-
121-
cfg := map[string]*regexp.Regexp{}
122-
123-
for _, pair := range strings.Split(s, ",") {
124-
colonIndex := strings.Index(pair, ":")
125-
var pkg, re string
126-
if colonIndex == -1 {
127-
pkg = ""
128-
re = pair
129-
} else {
130-
pkg = pair[:colonIndex]
131-
re = pair[colonIndex+1:]
132-
}
133-
regex, err := regexp.Compile(re)
134-
if err != nil {
135-
return nil, err
136-
}
137-
cfg[pkg] = regex
138-
}
139-
140-
return cfg, nil
141-
}
142-
143114
func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
144115
ignoreConfig, err := parseIgnoreConfig(errCfg.Ignore)
145116
if err != nil {
@@ -176,29 +147,62 @@ func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
176147
return &checker, nil
177148
}
178149

179-
func getFirstPathArg() string {
180-
args := os.Args
150+
// parseIgnoreConfig was taken from errcheck in order to keep the API identical.
151+
// https://github.com/kisielk/errcheck/blob/1787c4bee836470bf45018cfbc783650db3c6501/main.go#L25-L60
152+
func parseIgnoreConfig(s string) (map[string]*regexp.Regexp, error) {
153+
if s == "" {
154+
return nil, nil
155+
}
181156

182-
// skip all args ([golangci-lint, run/linters]) before files/dirs list
183-
for len(args) != 0 {
184-
if args[0] == "run" {
185-
args = args[1:]
186-
break
187-
}
157+
cfg := map[string]*regexp.Regexp{}
188158

189-
args = args[1:]
159+
for _, pair := range strings.Split(s, ",") {
160+
colonIndex := strings.Index(pair, ":")
161+
var pkg, re string
162+
if colonIndex == -1 {
163+
pkg = ""
164+
re = pair
165+
} else {
166+
pkg = pair[:colonIndex]
167+
re = pair[colonIndex+1:]
168+
}
169+
regex, err := regexp.Compile(re)
170+
if err != nil {
171+
return nil, err
172+
}
173+
cfg[pkg] = regex
190174
}
191175

192-
// find first file/dir arg
193-
firstArg := "./..."
194-
for _, arg := range args {
195-
if !strings.HasPrefix(arg, "-") {
196-
firstArg = arg
176+
return cfg, nil
177+
}
178+
179+
func readExcludeFile(name string) ([]string, error) {
180+
var err error
181+
var fh *os.File
182+
183+
for _, path := range setupConfigFileSearch(name) {
184+
if fh, err = os.Open(path); err == nil {
197185
break
198186
}
199187
}
200188

201-
return firstArg
189+
if fh == nil {
190+
return nil, fmt.Errorf("failed reading exclude file: %s: %w", name, err)
191+
}
192+
defer func() { _ = fh.Close() }()
193+
194+
scanner := bufio.NewScanner(fh)
195+
196+
var excludes []string
197+
for scanner.Scan() {
198+
excludes = append(excludes, scanner.Text())
199+
}
200+
201+
if err := scanner.Err(); err != nil {
202+
return nil, fmt.Errorf("failed scanning file: %s: %w", name, err)
203+
}
204+
205+
return excludes, nil
202206
}
203207

204208
func setupConfigFileSearch(name string) []string {
@@ -241,31 +245,27 @@ func setupConfigFileSearch(name string) []string {
241245
return configSearchPaths
242246
}
243247

244-
func readExcludeFile(name string) ([]string, error) {
245-
var err error
246-
var fh *os.File
248+
func getFirstPathArg() string {
249+
args := os.Args
247250

248-
for _, path := range setupConfigFileSearch(name) {
249-
if fh, err = os.Open(path); err == nil {
251+
// skip all args ([golangci-lint, run/linters]) before files/dirs list
252+
for len(args) != 0 {
253+
if args[0] == "run" {
254+
args = args[1:]
250255
break
251256
}
252-
}
253-
254-
if fh == nil {
255-
return nil, fmt.Errorf("failed reading exclude file: %s: %w", name, err)
256-
}
257-
defer func() { _ = fh.Close() }()
258-
259-
scanner := bufio.NewScanner(fh)
260257

261-
var excludes []string
262-
for scanner.Scan() {
263-
excludes = append(excludes, scanner.Text())
258+
args = args[1:]
264259
}
265260

266-
if err := scanner.Err(); err != nil {
267-
return nil, fmt.Errorf("failed scanning file: %s: %w", name, err)
261+
// find first file/dir arg
262+
firstArg := "./..."
263+
for _, arg := range args {
264+
if !strings.HasPrefix(arg, "-") {
265+
firstArg = arg
266+
break
267+
}
268268
}
269269

270-
return excludes, nil
270+
return firstArg
271271
}

pkg/golinters/errcheck/testdata/errcheck_exclude.go

Lines changed: 0 additions & 17 deletions
This file was deleted.

pkg/golinters/errcheck/testdata/errcheck_exclude.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

pkg/golinters/errcheck/testdata/errcheck_exclude.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

pkg/golinters/errcheck/testdata/errcheck_ignore.go

Lines changed: 0 additions & 28 deletions
This file was deleted.

pkg/golinters/errcheck/testdata/errcheck_ignore_config.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)