feat(healthcheck/nonascii): ignore content in gitattributes
This commit is contained in:
parent
55e2b38583
commit
348eaa247c
|
@ -9,7 +9,6 @@ import (
|
|||
"strings"
|
||||
"unicode"
|
||||
|
||||
"github.com/go-git/go-billy/v5/memfs"
|
||||
"github.com/go-git/go-git/v5/plumbing/format/gitattributes"
|
||||
)
|
||||
|
||||
|
@ -17,11 +16,13 @@ import (
|
|||
// It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters.
|
||||
func getNonAscii(root string) ([]string, error) {
|
||||
var nonAscii []string
|
||||
fs := memfs.New()
|
||||
rootPath := []string{"./"}
|
||||
var emptyStr []string
|
||||
fs := os.DirFS(".")
|
||||
f, err := fs.Open(".gitattributes")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
attribute, err := gitattributes.ReadPatterns(fs, rootPath)
|
||||
attribute, err := gitattributes.ReadAttributes(f, nil, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -45,7 +46,13 @@ func getNonAscii(root string) ([]string, error) {
|
|||
return nil
|
||||
}
|
||||
|
||||
if _, ret := matcher.Match(rootPath, append(emptyStr, info.Name())); ret {
|
||||
relPath, err := filepath.Rel(root, path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
str := strings.Split(relPath, "/")
|
||||
_, ret := matcher.Match(str, nil)
|
||||
if ret {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user