Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: data-race #67

Merged
merged 1 commit into from
Oct 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading