From 348eaa247c1fe3b107302c4ce3714d5aaa8c6183 Mon Sep 17 00:00:00 2001 From: zzjc1234 <2359047351@qq.com> Date: Mon, 21 Oct 2024 15:18:43 +0800 Subject: [PATCH] feat(healthcheck/nonascii): ignore content in gitattributes --- pkg/healthcheck/nonascii.go | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pkg/healthcheck/nonascii.go b/pkg/healthcheck/nonascii.go index 07bc436..f56ae10 100644 --- a/pkg/healthcheck/nonascii.go +++ b/pkg/healthcheck/nonascii.go @@ -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 }