Skip to content

Commit 9972d82

Browse files
committed
fix: store severity from linters in the cache
1 parent c0f89fb commit 9972d82

File tree

3 files changed

+37
-34
lines changed

3 files changed

+37
-34
lines changed

pkg/golinters/goanalysis/issue.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func NewIssue(issue *result.Issue, pass *analysis.Pass) Issue {
2323
type EncodingIssue struct {
2424
FromLinter string
2525
Text string
26+
Severity string
2627
Pos token.Position
2728
LineRange *result.Range
2829
Replacement *result.Replacement

pkg/golinters/goanalysis/runners.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func saveIssuesToCache(allPkgs []*packages.Package, pkgsFromCache map[*packages.
151151
encodedIssues = append(encodedIssues, EncodingIssue{
152152
FromLinter: i.FromLinter,
153153
Text: i.Text,
154+
Severity: i.Severity,
154155
Pos: i.Pos,
155156
LineRange: i.LineRange,
156157
Replacement: i.Replacement,
@@ -222,6 +223,7 @@ func loadIssuesFromCache(pkgs []*packages.Package, lintCtx *linter.Context,
222223
issues = append(issues, result.Issue{
223224
FromLinter: i.FromLinter,
224225
Text: i.Text,
226+
Severity: i.Severity,
225227
Pos: i.Pos,
226228
LineRange: i.LineRange,
227229
Replacement: i.Replacement,

pkg/lint/runner.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ import (
2222
"github.com/golangci/golangci-lint/pkg/timeutils"
2323
)
2424

25+
type processorStat struct {
26+
inCount int
27+
outCount int
28+
}
29+
2530
type Runner struct {
2631
Processors []processors.Processor
2732
Log logutils.Log
@@ -111,6 +116,33 @@ func NewRunner(log logutils.Log, cfg *config.Config, goenv *goutil.Env,
111116
}, nil
112117
}
113118

119+
func (r *Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *linter.Context) ([]result.Issue, error) {
120+
sw := timeutils.NewStopwatch("linters", r.Log)
121+
defer sw.Print()
122+
123+
var (
124+
lintErrors error
125+
issues []result.Issue
126+
)
127+
128+
for _, lc := range linters {
129+
lc := lc
130+
sw.TrackStage(lc.Name(), func() {
131+
linterIssues, err := r.runLinterSafe(ctx, lintCtx, lc)
132+
if err != nil {
133+
lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err)
134+
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)
135+
136+
return
137+
}
138+
139+
issues = append(issues, linterIssues...)
140+
})
141+
}
142+
143+
return r.processLintResults(issues), lintErrors
144+
}
145+
114146
func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
115147
lc *linter.Config) (ret []result.Issue, err error) {
116148
defer func() {
@@ -151,12 +183,7 @@ func (r *Runner) runLinterSafe(ctx context.Context, lintCtx *linter.Context,
151183
return issues, nil
152184
}
153185

154-
type processorStat struct {
155-
inCount int
156-
outCount int
157-
}
158-
159-
func (r Runner) processLintResults(inIssues []result.Issue) []result.Issue {
186+
func (r *Runner) processLintResults(inIssues []result.Issue) []result.Issue {
160187
sw := timeutils.NewStopwatch("processing", r.Log)
161188

162189
var issuesBefore, issuesAfter int
@@ -187,7 +214,7 @@ func (r Runner) processLintResults(inIssues []result.Issue) []result.Issue {
187214
return outIssues
188215
}
189216

190-
func (r Runner) printPerProcessorStat(stat map[string]processorStat) {
217+
func (r *Runner) printPerProcessorStat(stat map[string]processorStat) {
191218
parts := make([]string, 0, len(stat))
192219
for name, ps := range stat {
193220
if ps.inCount != 0 {
@@ -199,33 +226,6 @@ func (r Runner) printPerProcessorStat(stat map[string]processorStat) {
199226
}
200227
}
201228

202-
func (r Runner) Run(ctx context.Context, linters []*linter.Config, lintCtx *linter.Context) ([]result.Issue, error) {
203-
sw := timeutils.NewStopwatch("linters", r.Log)
204-
defer sw.Print()
205-
206-
var (
207-
lintErrors error
208-
issues []result.Issue
209-
)
210-
211-
for _, lc := range linters {
212-
lc := lc
213-
sw.TrackStage(lc.Name(), func() {
214-
linterIssues, err := r.runLinterSafe(ctx, lintCtx, lc)
215-
if err != nil {
216-
lintErrors = errors.Join(lintErrors, fmt.Errorf("can't run linter %s", lc.Linter.Name()), err)
217-
r.Log.Warnf("Can't run linter %s: %v", lc.Linter.Name(), err)
218-
219-
return
220-
}
221-
222-
issues = append(issues, linterIssues...)
223-
})
224-
}
225-
226-
return r.processLintResults(issues), lintErrors
227-
}
228-
229229
func (r *Runner) processIssues(issues []result.Issue, sw *timeutils.Stopwatch, statPerProcessor map[string]processorStat) []result.Issue {
230230
for _, p := range r.Processors {
231231
var newIssues []result.Issue

0 commit comments

Comments
 (0)