aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/breml/bidichk
diff options
context:
space:
mode:
authorTaras Madan <tarasmadan@google.com>2024-11-11 11:41:38 +0100
committerTaras Madan <tarasmadan@google.com>2024-11-11 11:10:48 +0000
commit27e76fae2ee2d84dc7db63af1d9ed7358ba35b7a (patch)
treeed19c0e35e272b3c4cc5a2f2c595e035b2428337 /vendor/github.com/breml/bidichk
parent621e84e063b0e15b23e17780338627c509e1b9e8 (diff)
vendor: update
Diffstat (limited to 'vendor/github.com/breml/bidichk')
-rw-r--r--vendor/github.com/breml/bidichk/pkg/bidichk/bidichk.go33
1 files changed, 17 insertions, 16 deletions
diff --git a/vendor/github.com/breml/bidichk/pkg/bidichk/bidichk.go b/vendor/github.com/breml/bidichk/pkg/bidichk/bidichk.go
index f1bf20fab..39d3cd44e 100644
--- a/vendor/github.com/breml/bidichk/pkg/bidichk/bidichk.go
+++ b/vendor/github.com/breml/bidichk/pkg/bidichk/bidichk.go
@@ -14,7 +14,7 @@ import (
)
const (
- doc = "bidichk detects dangerous unicode character sequences"
+ doc = "Checks for dangerous unicode character sequences"
disallowedDoc = `comma separated list of disallowed runes (full name or short name)
Supported runes
@@ -142,25 +142,28 @@ func NewAnalyzer() *analysis.Analyzer {
}
func (b bidichk) run(pass *analysis.Pass) (interface{}, error) {
- var err error
+ readFile := pass.ReadFile
+ if readFile == nil {
+ readFile = os.ReadFile
+ }
- pass.Fset.Iterate(func(f *token.File) bool {
- if strings.HasPrefix(f.Name(), "$GOROOT") {
- return true
+ for _, astFile := range pass.Files {
+ f := pass.Fset.File(astFile.FileStart)
+ if f == nil {
+ continue
}
- return b.check(f.Name(), f.Pos(0), pass) == nil
- })
-
- return nil, err
-}
+ body, err := readFile(f.Name())
+ if err != nil {
+ return nil, err
+ }
-func (b bidichk) check(filename string, pos token.Pos, pass *analysis.Pass) error {
- body, err := os.ReadFile(filename)
- if err != nil {
- return err
+ b.check(body, f.Pos(0), pass)
}
+ return nil, nil
+}
+func (b bidichk) check(body []byte, pos token.Pos, pass *analysis.Pass) {
for name, r := range b.disallowedRunes {
start := 0
for {
@@ -175,6 +178,4 @@ func (b bidichk) check(filename string, pos token.Pos, pass *analysis.Pass) erro
start += utf8.RuneLen(r)
}
}
-
- return nil
}