fix/nonascii_attributes #69
2
go.mod
2
go.mod
|
@ -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
|
||||||
|
|
|
@ -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
|
|||||||
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
张泊明518370910136
commented
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
张泊明518370910136
commented
just
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)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user
the naming is weird, we need to think what is
!noAttri
. Just sth likegitattributesExist
.