gum/internal/files/files.go
Christian Muehlhaeuser 66993d8ef1
Add soft & hard linter configs & workflows (#44)
* chore: add linter configs & workflows

* fix: ignore certain linter warnings

* fix: mark errors as intentionally ignored

* fix: avoid unnecessary conversion

* fix: handle template/renderer errors

* fix: mark intentionally unused code
2022-07-30 12:32:59 -04:00

38 lines
715 B
Go

package files
import (
"os"
"path/filepath"
"strings"
)
// List returns a list of all files in the current directory.
// It ignores the .git directory.
func List() []string {
var files []string
err := filepath.Walk(".",
func(path string, info os.FileInfo, err error) error {
if shouldIgnore(path) || info.IsDir() || err != nil {
return nil //nolint:nilerr
}
files = append(files, path)
return nil
})
if err != nil {
return []string{}
}
return files
}
var defaultIgnorePatterns = []string{"node_modules", ".git", "."}
func shouldIgnore(path string) bool {
for _, prefix := range defaultIgnorePatterns {
if strings.HasPrefix(path, prefix) {
return true
}
}
return false
}