Skip to content

Commit 88d9ade

Browse files
committed
refactor: apply the Fixer before user limitations and output transformations
1 parent 89607f9 commit 88d9ade

File tree

4 files changed

+12
-24
lines changed

4 files changed

+12
-24
lines changed

pkg/lint/runner.go

+11-8
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,12 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
7979
// Must be after FilenameUnadjuster.
8080
processors.NewInvalidIssue(log.Child(logutils.DebugKeyInvalidIssue)),
8181

82-
// Must be before diff, nolint and exclude autogenerated processor at least.
82+
// Must be before Diff, SkipFiles, SkipDirs, ExcludeRules processors at least.
8383
processors.NewPathPrettifier(log),
84+
85+
// must be after path prettifier
8486
skipFilesProcessor,
85-
skipDirsProcessor, // must be after path prettifier
87+
skipDirsProcessor,
8688

8789
processors.NewAutogeneratedExclude(cfg.Issues.ExcludeGenerated),
8890

@@ -94,20 +96,21 @@ func NewRunner(log logutils.Log, cfg *config.Config, args []string, goenv *gouti
9496

9597
processors.NewNolint(log.Child(logutils.DebugKeyNolint), dbManager, enabledLinters),
9698

97-
processors.NewUniqByLine(cfg),
9899
processors.NewDiff(&cfg.Issues),
100+
101+
// The fixer still needs to see paths for the issues that are relative to the current directory.
102+
processors.NewFixer(cfg, log, fileCache, metaFormatter),
103+
104+
// Must be after the Fixer.
105+
processors.NewUniqByLine(cfg),
99106
processors.NewMaxPerFileFromLinter(cfg),
100107
processors.NewMaxSameIssues(cfg.Issues.MaxSameIssues, log.Child(logutils.DebugKeyMaxSameIssues), cfg),
101108
processors.NewMaxFromLinter(cfg.Issues.MaxIssuesPerLinter, log.Child(logutils.DebugKeyMaxFromLinter), cfg),
102109

110+
// Now we can modify the issues for output.
103111
processors.NewSourceCode(lineCache, log.Child(logutils.DebugKeySourceCode)),
104112
processors.NewPathShortener(),
105113
processors.NewSeverity(log.Child(logutils.DebugKeySeverityRules), files, &cfg.Severity),
106-
107-
// The fixer still needs to see paths for the issues that are relative to the current directory.
108-
processors.NewFixer(cfg, log, fileCache, metaFormatter),
109-
110-
// Now we can modify the issues for output.
111114
processors.NewPathPrefixer(cfg.Output.PathPrefix),
112115
processors.NewSortResults(cfg),
113116
},

pkg/result/processors/max_from_linter.go

-5
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@ func (p *MaxFromLinter) Process(issues []result.Issue) ([]result.Issue, error) {
3535
}
3636

3737
return filterIssuesUnsafe(issues, func(issue *result.Issue) bool {
38-
if issue.SuggestedFixes != nil && p.cfg.Issues.NeedFix {
39-
// we need to fix all issues at once => we need to return all of them
40-
return true
41-
}
42-
4338
p.linterCounter[issue.FromLinter]++ // always inc for stat
4439

4540
return p.linterCounter[issue.FromLinter] <= p.limit

pkg/result/processors/max_same_issues.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,8 @@ func (p *MaxSameIssues) Process(issues []result.Issue) ([]result.Issue, error) {
3737
}
3838

3939
return filterIssuesUnsafe(issues, func(issue *result.Issue) bool {
40-
if issue.SuggestedFixes != nil && p.cfg.Issues.NeedFix {
41-
// we need to fix all issues at once => we need to return all of them
42-
return true
43-
}
44-
4540
p.textCounter[issue.Text]++ // always inc for stat
41+
4642
return p.textCounter[issue.Text] <= p.limit
4743
}), nil
4844
}

pkg/result/processors/uniq_by_line.go

-6
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,6 @@ func (p *UniqByLine) Process(issues []result.Issue) ([]result.Issue, error) {
3737
func (*UniqByLine) Finish() {}
3838

3939
func (p *UniqByLine) shouldPassIssue(issue *result.Issue) bool {
40-
if issue.SuggestedFixes != nil && p.cfg.Issues.NeedFix {
41-
// if issue will be auto-fixed we shouldn't collapse issues:
42-
// e.g. one line can contain 2 misspellings, they will be in 2 issues and misspell should fix both of them.
43-
return true
44-
}
45-
4640
if p.fileLineCounter.GetCount(issue) == uniqByLineLimit {
4741
return false
4842
}

0 commit comments

Comments
 (0)