Skip to content

Commit

Permalink
chore: remove deprecated errcheck tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Apr 22, 2024
1 parent a353a7a commit 0dce200
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 120 deletions.
126 changes: 63 additions & 63 deletions pkg/golinters/errcheck/errcheck.go
Expand Up @@ -111,35 +111,6 @@ func runErrCheck(lintCtx *linter.Context, pass *analysis.Pass, checker *errcheck
return issues
}

// parseIgnoreConfig was taken from errcheck in order to keep the API identical.
// https://github.com/kisielk/errcheck/blob/1787c4bee836470bf45018cfbc783650db3c6501/main.go#L25-L60
func parseIgnoreConfig(s string) (map[string]*regexp.Regexp, error) {
if s == "" {
return nil, nil
}

cfg := map[string]*regexp.Regexp{}

for _, pair := range strings.Split(s, ",") {
colonIndex := strings.Index(pair, ":")
var pkg, re string
if colonIndex == -1 {
pkg = ""
re = pair
} else {
pkg = pair[:colonIndex]
re = pair[colonIndex+1:]
}
regex, err := regexp.Compile(re)
if err != nil {
return nil, err
}
cfg[pkg] = regex
}

return cfg, nil
}

func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
ignoreConfig, err := parseIgnoreConfig(errCfg.Ignore)
if err != nil {
Expand Down Expand Up @@ -176,29 +147,62 @@ func getChecker(errCfg *config.ErrcheckSettings) (*errcheck.Checker, error) {
return &checker, nil
}

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

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

args = args[1:]
for _, pair := range strings.Split(s, ",") {
colonIndex := strings.Index(pair, ":")
var pkg, re string
if colonIndex == -1 {
pkg = ""
re = pair
} else {
pkg = pair[:colonIndex]
re = pair[colonIndex+1:]
}
regex, err := regexp.Compile(re)
if err != nil {
return nil, err
}
cfg[pkg] = regex
}

// find first file/dir arg
firstArg := "./..."
for _, arg := range args {
if !strings.HasPrefix(arg, "-") {
firstArg = arg
return cfg, nil
}

func readExcludeFile(name string) ([]string, error) {
var err error
var fh *os.File

for _, path := range setupConfigFileSearch(name) {
if fh, err = os.Open(path); err == nil {
break
}
}

return firstArg
if fh == nil {
return nil, fmt.Errorf("failed reading exclude file: %s: %w", name, err)
}
defer func() { _ = fh.Close() }()

scanner := bufio.NewScanner(fh)

var excludes []string
for scanner.Scan() {
excludes = append(excludes, scanner.Text())
}

if err := scanner.Err(); err != nil {
return nil, fmt.Errorf("failed scanning file: %s: %w", name, err)
}

return excludes, nil
}

func setupConfigFileSearch(name string) []string {
Expand Down Expand Up @@ -241,31 +245,27 @@ func setupConfigFileSearch(name string) []string {
return configSearchPaths
}

func readExcludeFile(name string) ([]string, error) {
var err error
var fh *os.File
func getFirstPathArg() string {
args := os.Args

for _, path := range setupConfigFileSearch(name) {
if fh, err = os.Open(path); err == nil {
// skip all args ([golangci-lint, run/linters]) before files/dirs list
for len(args) != 0 {
if args[0] == "run" {
args = args[1:]
break
}
}

if fh == nil {
return nil, fmt.Errorf("failed reading exclude file: %s: %w", name, err)
}
defer func() { _ = fh.Close() }()

scanner := bufio.NewScanner(fh)

var excludes []string
for scanner.Scan() {
excludes = append(excludes, scanner.Text())
args = args[1:]
}

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

return excludes, nil
return firstArg
}
17 changes: 0 additions & 17 deletions pkg/golinters/errcheck/testdata/errcheck_exclude.go

This file was deleted.

1 change: 0 additions & 1 deletion pkg/golinters/errcheck/testdata/errcheck_exclude.txt

This file was deleted.

4 changes: 0 additions & 4 deletions pkg/golinters/errcheck/testdata/errcheck_exclude.yml

This file was deleted.

28 changes: 0 additions & 28 deletions pkg/golinters/errcheck/testdata/errcheck_ignore.go

This file was deleted.

7 changes: 0 additions & 7 deletions pkg/golinters/errcheck/testdata/errcheck_ignore_config.yml

This file was deleted.

0 comments on commit 0dce200

Please sign in to comment.