Skip to content

Commit

Permalink
fix: data-race (#67)
Browse files Browse the repository at this point in the history
Resolves: #63
  • Loading branch information
butuzov committed Oct 18, 2023
1 parent 2a0a6d2 commit 3da90eb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion analyzer/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type validator interface {

type analyzer struct {
once sync.Once
mu sync.RWMutex
handler validator
err error

Expand Down Expand Up @@ -83,18 +84,27 @@ func (a *analyzer) run(pass *analysis.Pass) (interface{}, error) {
}
seen[key] = true

a.found = append(a.found, issue.ExportDiagnostic())
a.addDiagnostic(issue.ExportDiagnostic())
}
})

// 02. Printing reports.
a.mu.RLock()
defer a.mu.RUnlock()
for i := range a.found {
pass.Report(a.found[i])
}

return nil, nil
}

func (a *analyzer) addDiagnostic(d analysis.Diagnostic) {
a.mu.Lock()
defer a.mu.Unlock()

a.found = append(a.found, d)
}

func (a *analyzer) readConfiguration(fs *flag.FlagSet) {
cnf, err := config.New(fs)
if err != nil {
Expand Down

0 comments on commit 3da90eb

Please sign in to comment.