Skip to content

Commit

Permalink
fix: store severity from linters in the cache
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 8, 2024
1 parent c0f89fb commit 9972d82
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 34 deletions.
1 change: 1 addition & 0 deletions pkg/golinters/goanalysis/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func NewIssue(issue *result.Issue, pass *analysis.Pass) Issue {
type EncodingIssue struct {
FromLinter string
Text string
Severity string
Pos token.Position
LineRange *result.Range
Replacement *result.Replacement
Expand Down
2 changes: 2 additions & 0 deletions pkg/golinters/goanalysis/runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages.
encodedIssues = append(encodedIssues, EncodingIssue{
FromLinter: i.FromLinter,
Text: i.Text,
Severity: i.Severity,
Pos: i.Pos,
LineRange: i.LineRange,
Replacement: i.Replacement,
Expand Down Expand Up @@ -222,6 +223,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
issues = append(issues, result.Issue{
FromLinter: i.FromLinter,
Text: i.Text,
Severity: i.Severity,
Pos: i.Pos,
LineRange: i.LineRange,
Replacement: i.Replacement,
Expand Down
68 changes: 34 additions & 34 deletions pkg/lint/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
"github.com/golangci/golangci-lint/pkg/timeutils"
)

type processorStat struct {
inCount int
outCount int
}

type Runner struct {
Processors []processors.Processor
Log logutils.Log
Expand Down Expand Up @@ -111,6 +116,33 @@ func NewRunner(log logutils.Log, cfg *config.Config, goenv *goutil.Env,
}, nil
}

func (r *Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *linter.Context) ([]result.Issue, error) {
sw := timeutils.NewStopwatch("linters", r.Log)
defer sw.Print()

var (
lintErrors error
issues []result.Issue
)

for _, lc := range linters {
lc := lc
sw.TrackStage(lc.Name(), func() {
linterIssues, err := r.runLinterSafe(ctx, lintCtx, lc)
if err != nil {
lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err)
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)

return
}

issues = append(issues, linterIssues...)
})
}

return r.processLintResults(issues), lintErrors
}

func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
lc *linter.Config) (ret []result.Issue, err error) {
defer func() {
Expand Down Expand Up @@ -151,12 +183,7 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
return issues, nil
}

type processorStat struct {
inCount int
outCount int
}

func (r Runner) processLintResults(inIssues []result.Issue) []result.Issue {
func (r *Runner) processLintResults(inIssues []result.Issue) []result.Issue {
sw := timeutils.NewStopwatch("processing", r.Log)

var issuesBefore, issuesAfter int
Expand Down Expand Up @@ -187,7 +214,7 @@ func (r Runner) processLintResults(inIssues []result.Issue) []result.Issue {
return outIssues
}

func (r Runner) printPerProcessorStat(stat map[string]processorStat) {
func (r *Runner) printPerProcessorStat(stat map[string]processorStat) {
parts := make([]string, 0, len(stat))
for name, ps := range stat {
if ps.inCount != 0 {
Expand All @@ -199,33 +226,6 @@ func (r Runner) printPerProcessorStat(stat map[string]processorStat) {
}
}

func (r Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *linter.Context) ([]result.Issue, error) {
sw := timeutils.NewStopwatch("linters", r.Log)
defer sw.Print()

var (
lintErrors error
issues []result.Issue
)

for _, lc := range linters {
lc := lc
sw.TrackStage(lc.Name(), func() {
linterIssues, err := r.runLinterSafe(ctx, lintCtx, lc)
if err != nil {
lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err)
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)

return
}

issues = append(issues, linterIssues...)
})
}

return r.processLintResults(issues), lintErrors
}

func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue {
for _, p := range r.Processors {
var newIssues []result.Issue
Expand Down

0 comments on commit 9972d82

Please sign in to comment.