diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index e09280f..decbd87 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -5,6 +5,14 @@ on: push: jobs: + lint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: golangci-lint + uses: golangci/golangci-lint-action@v8 + test: runs-on: ubuntu-latest strategy: diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..7638c33 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,30 @@ +version: "2" + +run: + issues-exit-code: 1 + +formatters: + enable: + - gofmt + - gci + +linters: + enable: + - wrapcheck + settings: + wrapcheck: + ignore-package-globs: + # We already make sure your own packages wrap errors properly + - github.com/symfony-cli/* + errcheck: + exclude-functions: + - github.com/symfony-cli/terminal.Printf + - github.com/symfony-cli/terminal.Println + - github.com/symfony-cli/terminal.Printfln + - github.com/symfony-cli/terminal.Eprintf + - github.com/symfony-cli/terminal.Eprintln + - github.com/symfony-cli/terminal.Eprintfln + - github.com/symfony-cli/terminal.Eprint + - fmt.Fprintln + - fmt.Fprintf + - fmt.Fprint diff --git a/discovery.go b/discovery.go index dca8bb2..838d48c 100644 --- a/discovery.go +++ b/discovery.go @@ -59,7 +59,7 @@ func (s *PHPStore) discoverFromDir(root string, phpRegexp *regexp.Regexp, pathRe if pathRegexp != nil { maxDepth += strings.Count(pathRegexp.String(), "/") } - filepath.Walk(root, func(path string, finfo os.FileInfo, err error) error { + err := filepath.Walk(root, func(path string, finfo os.FileInfo, err error) error { if err != nil { // prevent panic by handling failure accessing a path return nil @@ -83,6 +83,9 @@ func (s *PHPStore) discoverFromDir(root string, phpRegexp *regexp.Regexp, pathRe } return nil }) + if err != nil { + s.log("error during %s discovery: %s", why, err) + } } func (s *PHPStore) addFromDir(dir string, phpRegexp *regexp.Regexp, why string) { @@ -114,7 +117,7 @@ func (s *PHPStore) findFromDir(dir string, phpRegexp *regexp.Regexp, why string) } var versions []*Version - filepath.Walk(root, func(path string, finfo os.FileInfo, err error) error { + _ = filepath.Walk(root, func(path string, finfo os.FileInfo, err error) error { if err != nil { // prevent panic by handling failure accessing a path return nil diff --git a/store.go b/store.go index 17b7961..e327167 100644 --- a/store.go +++ b/store.go @@ -50,7 +50,7 @@ func New(configDir string, reload bool, logger func(msg string, a ...interface{} discoveryLogFunc: logger, } if reload { - os.Remove(filepath.Join(configDir, "php_versions.json")) + _ = os.Remove(filepath.Join(configDir, "php_versions.json")) } s.loadVersions() return s @@ -149,7 +149,7 @@ func (s *PHPStore) bestVersion(versionPrefix, source string) (*Version, string, isPatchVersion := false pos := strings.LastIndexByte(versionPrefix, '.') if pos != strings.IndexByte(versionPrefix, '.') { - if "99" == versionPrefix[pos+1:] { + if versionPrefix[pos+1:] == "99" { versionPrefix = versionPrefix[:pos] pos = strings.LastIndexByte(versionPrefix, '.') } else {