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