Skip to content

Commit b527a26

Browse files
committed
fix(runner): add suggested edit text from linter in display issue text
The tool did not print suggested edits by the linter when displaying the issues. If there is suggested edits by the linter, it should be displayed along with the issue. Closes golangci#2134
1 parent 245257b commit b527a26

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

Diff for: pkg/golinters/goanalysis/runners.go

+15
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,20 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st
9090
diag := &diags[i]
9191
linterName := linterNameBuilder(diag)
9292

93+
var suggestedEdits string
94+
for _, suggestedFix := range diag.SuggestedFixes {
95+
for _, textEdit := range suggestedFix.TextEdits {
96+
suggestedEdits += string(textEdit.NewText)
97+
}
98+
}
99+
93100
var text string
94101
if diag.Analyzer.Name == linterName {
95102
text = diag.Message
96103
} else {
97104
text = fmt.Sprintf("%s: %s", diag.Analyzer.Name, diag.Message)
98105
}
106+
text += formatSuggestFix(suggestedEdits)
99107

100108
issues = append(issues, result.Issue{
101109
FromLinter: linterName,
@@ -118,6 +126,13 @@ func buildIssues(diags []Diagnostic, linterNameBuilder func(diag *Diagnostic) st
118126
return issues
119127
}
120128

129+
func formatSuggestFix(fix string) string {
130+
if fix == "" {
131+
return ""
132+
}
133+
return fmt.Sprintf("\n```\n%s\n```\n", fix)
134+
}
135+
121136
func getIssuesCacheKey(analyzers []*analysis.Analyzer) string {
122137
return "lint/result:" + analyzersHashID(analyzers)
123138
}

0 commit comments

Comments
 (0)