@@ -207,7 +207,29 @@ func (p *hunkChangesParser) parse(h *diffpkg.Hunk) []Change {
207207 return p .ret
208208}
209209
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 ) {
211233 diffs , err := diffpkg .ParseMultiFileDiff ([]byte (patch ))
212234 if err != nil {
213235 return nil , errors .Wrap (err , "can't parse patch" )
@@ -225,35 +247,19 @@ func extractIssuesFromPatch(patch string, log logutils.Log, lintCtx *linter.Cont
225247 }
226248
227249 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- }
240250 p := hunkChangesParser {
241251 log : log ,
242252 }
243253 changes := p .parse (hunk )
244254 for _ , change := range changes {
245255 change := change // fix scope
246- linterName := gofmtName
247- if isGoimports {
248- linterName = goimportsName
249- }
250256 i := result.Issue {
251257 FromLinter : linterName ,
252258 Pos : token.Position {
253259 Filename : d .NewName ,
254260 Line : change .LineRange .From ,
255261 },
256- Text : text ,
262+ Text : getErrorTextForLinter ( lintCtx , linterName ) ,
257263 Replacement : & change .Replacement ,
258264 }
259265 if change .LineRange .From != change .LineRange .To {
0 commit comments