@@ -207,7 +207,29 @@ func (p *hunkChangesParser) parse(h *diffpkg.Hunk) []Change {
207
207
return p .ret
208
208
}
209
209
210
- func extractIssuesFromPatch (patch string , log logutils.Log , lintCtx * linter.Context , isGoimports bool ) ([]result.Issue , error ) {
210
+ func getErrorTextForLinter (lintCtx * linter.Context , linterName string ) string {
211
+ text := "File is not formatted"
212
+ switch linterName {
213
+ case gofumptName :
214
+ text = "File is not `gofumpt`-ed"
215
+ if lintCtx .Settings ().Gofumpt .ExtraRules {
216
+ text += " with `-extra`"
217
+ }
218
+ case gofmtName :
219
+ text = "File is not `gofmt`-ed"
220
+ if lintCtx .Settings ().Gofmt .Simplify {
221
+ text += " with `-s`"
222
+ }
223
+ case goimportsName :
224
+ text = "File is not `goimports`-ed"
225
+ if lintCtx .Settings ().Goimports .LocalPrefixes != "" {
226
+ text += " with -local " + lintCtx .Settings ().Goimports .LocalPrefixes
227
+ }
228
+ }
229
+ return text
230
+ }
231
+
232
+ func extractIssuesFromPatch (patch string , log logutils.Log , lintCtx * linter.Context , linterName string ) ([]result.Issue , error ) {
211
233
diffs , err := diffpkg .ParseMultiFileDiff ([]byte (patch ))
212
234
if err != nil {
213
235
return nil , errors .Wrap (err , "can't parse patch" )
@@ -225,35 +247,19 @@ func extractIssuesFromPatch(patch string, log logutils.Log, lintCtx *linter.Cont
225
247
}
226
248
227
249
for _ , hunk := range d .Hunks {
228
- var text string
229
- if isGoimports {
230
- text = "File is not `goimports`-ed"
231
- if lintCtx .Settings ().Goimports .LocalPrefixes != "" {
232
- text += " with -local " + lintCtx .Settings ().Goimports .LocalPrefixes
233
- }
234
- } else {
235
- text = "File is not `gofmt`-ed"
236
- if lintCtx .Settings ().Gofmt .Simplify {
237
- text += " with `-s`"
238
- }
239
- }
240
250
p := hunkChangesParser {
241
251
log : log ,
242
252
}
243
253
changes := p .parse (hunk )
244
254
for _ , change := range changes {
245
255
change := change // fix scope
246
- linterName := gofmtName
247
- if isGoimports {
248
- linterName = goimportsName
249
- }
250
256
i := result.Issue {
251
257
FromLinter : linterName ,
252
258
Pos : token.Position {
253
259
Filename : d .NewName ,
254
260
Line : change .LineRange .From ,
255
261
},
256
- Text : text ,
262
+ Text : getErrorTextForLinter ( lintCtx , linterName ) ,
257
263
Replacement : & change .Replacement ,
258
264
}
259
265
if change .LineRange .From != change .LineRange .To {
0 commit comments