fix/nonascii_attributes #69

Merged
张泊明518370910136 merged 11 commits from fix/nonascii_attributes into master 2024-10-21 17:04:53 +08:00
2 changed files with 28 additions and 17 deletions
Showing only changes of commit decadeaef1 - Show all commits

2
go.mod
View File

@ -5,7 +5,6 @@ go 1.23.1
require ( require (
github.com/criyle/go-judge v1.8.5 github.com/criyle/go-judge v1.8.5
github.com/denormal/go-gitignore v0.0.0-20180930084346-ae8ad1d07817 github.com/denormal/go-gitignore v0.0.0-20180930084346-ae8ad1d07817
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.12.0 github.com/go-git/go-git/v5 v5.12.0
github.com/jinzhu/copier v0.4.0 github.com/jinzhu/copier v0.4.0
github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7 github.com/koding/multiconfig v0.0.0-20171124222453-69c27309b2d7
@ -28,6 +27,7 @@ require (
github.com/fatih/camelcase v1.0.0 // indirect github.com/fatih/camelcase v1.0.0 // indirect
github.com/fatih/structs v1.1.0 // indirect github.com/fatih/structs v1.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect github.com/kevinburke/ssh_config v1.2.0 // indirect

View File

@ -16,18 +16,27 @@ import (
// It searches for non-ASCII characters in each file's content and returns a list of paths to files containing non-ASCII characters. // 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) { func getNonAscii(root string) ([]string, error) {
var nonAscii []string var nonAscii []string
fs := os.DirFS(".") noAttri := false
zzjc123 marked this conversation as resolved Outdated

the naming is weird, we need to think what is !noAttri. Just sth like gitattributesExist.

the naming is weird, we need to think what is `!noAttri`. Just sth like `gitattributesExist`.
f, err := fs.Open(".gitattributes") var matcher gitattributes.Matcher
if err != nil { _, err := os.Stat(".gitattributes")
if os.IsNotExist(err) {
noAttri = true
return nil, err return nil, err
} }
attribute, err := gitattributes.ReadAttributes(f, nil, true) if !noAttri {
if err != nil { fs := os.DirFS(".")
return nil, err f, err := fs.Open(".gitattributes")
} if err != nil {
return nil, err
}
matcher := gitattributes.NewMatcher(attribute) attribute, err := gitattributes.ReadAttributes(f, nil, true)
if err != nil {
return nil, err
}
matcher = gitattributes.NewMatcher(attribute)
}
err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error { err = filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
@ -46,14 +55,16 @@ func getNonAscii(root string) ([]string, error) {
return nil return nil
} }
relPath, err := filepath.Rel(root, path) if !noAttri {
zzjc123 marked this conversation as resolved Outdated

this line is too long now, should make it in two lines.

this line is too long now, should make it in two lines.
if err != nil { relPath, err := filepath.Rel(root, path)
return err if err != nil {
} return err
str := strings.Split(relPath, "/") }
zzjc123 marked this conversation as resolved Outdated

just

			if _, ret := matcher.Match(strings.Split(relPath, "/"), nil); ret {
				return nil
			}
just ```go if _, ret := matcher.Match(strings.Split(relPath, "/"), nil); ret { return nil } ```
_, ret := matcher.Match(str, nil) str := strings.Split(relPath, "/")
if ret { _, ret := matcher.Match(str, nil)
return nil if ret {
return nil
}
} }
file, err := os.Open(path) file, err := os.Open(path)