Skip to content

Commit

Permalink
fix: the randomness of the results of the analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 21, 2021
1 parent 8595e54 commit e9a5d50
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 3 additions & 0 deletions pkg/lint/linter/config.go
Expand Up @@ -20,6 +20,9 @@ const (
PresetUnused = "unused" // Related to the detection of unused code.
)

// LastLinter nolintlint must be last because it looks at the results of all the previous linters for unused nolint directives.
const LastLinter = "nolintlint"

type Deprecation struct {
Since string
Message string
Expand Down
22 changes: 21 additions & 1 deletion pkg/lint/lintersdb/enabled_set.go
Expand Up @@ -111,6 +111,15 @@ func (es EnabledSet) GetOptimizedLinters() ([]*linter.Config, error) {
// Make order of execution of linters (go/analysis metalinter and unused) stable.
sort.Slice(resultLinters, func(i, j int) bool {
a, b := resultLinters[i], resultLinters[j]

if b.Name() == linter.LastLinter {
return true
}

if a.Name() == linter.LastLinter {
return false
}

if a.DoesChangeTypes != b.DoesChangeTypes {
return b.DoesChangeTypes // move type-changing linters to the end to optimize speed
}
Expand Down Expand Up @@ -149,8 +158,19 @@ func (es EnabledSet) combineGoAnalysisLinters(linters map[string]*linter.Config)

// Make order of execution of go/analysis analyzers stable.
sort.Slice(goanalysisLinters, func(i, j int) bool {
return strings.Compare(goanalysisLinters[i].Name(), goanalysisLinters[j].Name()) <= 0
a, b := goanalysisLinters[i], goanalysisLinters[j]

if b.Name() == linter.LastLinter {
return true
}

if a.Name() == linter.LastLinter {
return false
}

return strings.Compare(a.Name(), b.Name()) <= 0
})

ml := goanalysis.NewMetaLinter(goanalysisLinters)

var presets []string
Expand Down

0 comments on commit e9a5d50

Please sign in to comment.