Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 27eaa51

Browse files
committedJul 28, 2021
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 #2134
1 parent 245257b commit 27eaa51

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎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 += formatSuggestedEdit(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 formatSuggestedEdit(suggestedEdit string) string {
130+
if suggestedEdit == "" {
131+
return ""
132+
}
133+
return fmt.Sprintf("\nsuggestion\n```\n%s\n```\n", suggestedEdit)
134+
}
135+
121136
func getIssuesCacheKey(analyzers []*analysis.Analyzer) string {
122137
return "lint/result:" + analyzersHashID(analyzers)
123138
}

0 commit comments

Comments
 (0)
Please sign in to comment.