lintcmd: process diagnostics of current result, not all accumulated diagnostics
The old code was both inefficient, processing the same diagnostics
multiple times, and incorrect, panicking when encountering the
diagnostics of a failed package, because "compile" isn't a known
analyzer.
Closes
@@ -136,13 +136,12 @@ func (l *linter) Lint(cfg *packages.Config, patterns []string) (LintResult, erro
if err != nil {
return out, err
}
- out.Diagnostics = append(out.Diagnostics, filtered...)
-
// OPT move this code into the 'success' function.
- for i, diag := range out.Diagnostics {
+ for i, diag := range filtered {
a := l.Analyzers[diag.Category]
- out.Diagnostics[i].MergeIf = a.Doc.MergeIf
+ filtered[i].MergeIf = a.Doc.MergeIf
}
+ out.Diagnostics = append(out.Diagnostics, filtered...)
for _, obj := range resd.Unused.Used {
// FIXME(dh): pick the object whose filename does not include $GOROOT
