Skip to content

Commit

Permalink
Merge pull request #44 from pkwarren/issue-43
Browse files Browse the repository at this point in the history
Only scan files found in package
  • Loading branch information
breml authored Oct 16, 2024
2 parents 871cd0a + 12bf0ca commit 85e3fbf
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions pkg/bidichk/bidichk.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -175,6 +178,4 @@ func (b bidichk) check(filename string, pos token.Pos, pass *analysis.Pass) erro
start += utf8.RuneLen(r)
}
}

return nil
}

0 comments on commit 85e3fbf

Please sign in to comment.