Skip to content

Commit 8f859d4

Browse files
committed
refactor: restrict config scope
1 parent c43e5e3 commit 8f859d4

File tree

5 files changed

+19
-27
lines changed

5 files changed

+19
-27
lines changed

pkg/lint/runner.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
107107
processors.NewFixer(cfg, log, fileCache, metaFormatter),
108108

109109
// Must be after the Fixer.
110-
processors.NewUniqByLine(cfg),
110+
processors.NewUniqByLine(cfg.Issues.UniqByLine),
111111
processors.NewMaxPerFileFromLinter(cfg),
112112
processors.NewMaxSameIssues(cfg.Issues.MaxSameIssues, log.Child(logutils.DebugKeyMaxSameIssues), cfg),
113113
processors.NewMaxFromLinter(cfg.Issues.MaxIssuesPerLinter, log.Child(logutils.DebugKeyMaxFromLinter), cfg),
@@ -117,7 +117,7 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
117117
processors.NewPathShortener(),
118118
processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, &cfg.Severity),
119119
processors.NewPathPrettifier(log, cfg.Output.PathPrefix),
120-
processors.NewSortResults(cfg),
120+
processors.NewSortResults(&cfg.Output),
121121
},
122122
lintCtx: lintCtx,
123123
Log: log,

pkg/result/processors/sort_results.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type SortResults struct {
3636
cfg *config.Output
3737
}
3838

39-
func NewSortResults(cfg *config.Config) *SortResults {
39+
func NewSortResults(cfg *config.Output) *SortResults {
4040
return &SortResults{
4141
cmps: map[string][]issueComparator{
4242
// For sorting we are comparing (in next order):
@@ -47,7 +47,7 @@ func NewSortResults(cfg *config.Config) *SortResults {
4747
// For sorting we are comparing: severity
4848
orderNameSeverity: {bySeverity},
4949
},
50-
cfg: &cfg.Output,
50+
cfg: cfg,
5151
}
5252
}
5353

pkg/result/processors/sort_results_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ func TestSortResults_Process_noSorting(t *testing.T) {
213213
tests := make([]result.Issue, len(issues))
214214
copy(tests, issues)
215215

216-
sr := NewSortResults(&config.Config{})
216+
sr := NewSortResults(&config.Output{})
217217

218218
results, err := sr.Process(tests)
219219
require.NoError(t, err)
@@ -224,9 +224,9 @@ func TestSortResults_Process_Sorting(t *testing.T) {
224224
tests := make([]result.Issue, len(issues))
225225
copy(tests, issues)
226226

227-
cfg := config.Config{}
228-
cfg.Output.SortResults = true
229-
sr := NewSortResults(&cfg)
227+
cfg := &config.Output{SortResults: true}
228+
229+
sr := NewSortResults(cfg)
230230

231231
results, err := sr.Process(tests)
232232
require.NoError(t, err)

pkg/result/processors/uniq_by_line.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package processors
22

33
import (
4-
"github.com/golangci/golangci-lint/pkg/config"
54
"github.com/golangci/golangci-lint/pkg/result"
65
)
76

@@ -12,13 +11,13 @@ var _ Processor = (*UniqByLine)(nil)
1211
// UniqByLine filters reports to keep only one report by line of code.
1312
type UniqByLine struct {
1413
fileLineCounter fileLineCounter
15-
cfg *config.Config
14+
enable bool
1615
}
1716

18-
func NewUniqByLine(cfg *config.Config) *UniqByLine {
17+
func NewUniqByLine(enable bool) *UniqByLine {
1918
return &UniqByLine{
2019
fileLineCounter: fileLineCounter{},
21-
cfg: cfg,
20+
enable: enable,
2221
}
2322
}
2423

@@ -27,7 +26,7 @@ func (*UniqByLine) Name() string {
2726
}
2827

2928
func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) {
30-
if !p.cfg.Issues.UniqByLine {
29+
if !p.enable {
3130
return issues, nil
3231
}
3332

pkg/result/processors/uniq_by_line_test.go

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import (
44
"go/token"
55
"testing"
66

7-
"github.com/golangci/golangci-lint/pkg/config"
87
"github.com/golangci/golangci-lint/pkg/result"
98
)
109

11-
func newFLIssue(file string, line int) result.Issue {
10+
func newULIssue(file string, line int) result.Issue {
1211
return result.Issue{
1312
Pos: token.Position{
1413
Filename: file,
@@ -18,26 +17,20 @@ func newFLIssue(file string, line int) result.Issue {
1817
}
1918

2019
func TestUniqByLine(t *testing.T) {
21-
cfg := config.Config{}
22-
cfg.Issues.UniqByLine = true
23-
24-
p := NewUniqByLine(&cfg)
25-
i1 := newFLIssue("f1", 1)
20+
p := NewUniqByLine(true)
21+
i1 := newULIssue("f1", 1)
2622

2723
processAssertSame(t, p, i1)
2824
processAssertEmpty(t, p, i1) // check skipping
2925
processAssertEmpty(t, p, i1) // check accumulated error
3026

31-
processAssertSame(t, p, newFLIssue("f1", 2)) // another line
32-
processAssertSame(t, p, newFLIssue("f2", 1)) // another file
27+
processAssertSame(t, p, newULIssue("f1", 2)) // another line
28+
processAssertSame(t, p, newULIssue("f2", 1)) // another file
3329
}
3430

3531
func TestUniqByLineDisabled(t *testing.T) {
36-
cfg := config.Config{}
37-
cfg.Issues.UniqByLine = false
38-
39-
p := NewUniqByLine(&cfg)
40-
i1 := newFLIssue("f1", 1)
32+
p := NewUniqByLine(false)
33+
i1 := newULIssue("f1", 1)
4134

4235
processAssertSame(t, p, i1)
4336
processAssertSame(t, p, i1) // check the same issue passed twice

0 commit comments

Comments
 (0)