Skip to content

Commit 1ffd777

Browse files
committed
fix: the randomness of the results of the analysis
1 parent aec0c47 commit 1ffd777

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

pkg/lint/linter/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const (
2020
PresetUnused = "unused" // Related to the detection of unused code.
2121
)
2222

23+
// LastLinter nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives.
24+
const LastLinter = "nolintlint"
25+
2326
type Deprecation struct {
2427
Since string
2528
Message string

pkg/lint/lintersdb/enabled_set.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ func (es EnabledSet) GetOptimizedLinters() ([]*linter.Config, error) {
111111
// Make order of execution of linters (go/analysis metalinter and unused) stable.
112112
sort.Slice(resultLinters, func(i, j int) bool {
113113
a, b := resultLinters[i], resultLinters[j]
114+
115+
if b.Name() == linter.LastLinter {
116+
return true
117+
}
118+
119+
if a.Name() == linter.LastLinter {
120+
return false
121+
}
122+
114123
if a.DoesChangeTypes != b.DoesChangeTypes {
115124
return b.DoesChangeTypes // move type-changing linters to the end to optimize speed
116125
}
@@ -149,8 +158,19 @@ func (es EnabledSet) combineGoAnalysisLinters(linters map[string]*linter.Config)
149158

150159
// Make order of execution of go/analysis analyzers stable.
151160
sort.Slice(goanalysisLinters, func(i, j int) bool {
152-
return strings.Compare(goanalysisLinters[i].Name(), goanalysisLinters[j].Name()) <= 0
161+
a, b := goanalysisLinters[i], goanalysisLinters[j]
162+
163+
if b.Name() == linter.LastLinter {
164+
return true
165+
}
166+
167+
if a.Name() == linter.LastLinter {
168+
return false
169+
}
170+
171+
return strings.Compare(a.Name(), b.Name()) <= 0
153172
})
173+
154174
ml := goanalysis.NewMetaLinter(goanalysisLinters)
155175

156176
var presets []string

0 commit comments

Comments
 (0)