Skip to content

Commit 91ededf

Browse files
committed
feat: improve formatter messages
1 parent e11de60 commit 91ededf

File tree

5 files changed

+7
-40
lines changed

5 files changed

+7
-40
lines changed

pkg/golinters/gci/internal/analyzer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func runAnalysis(pass *analysis.Pass) (any, error) {
108108

109109
pass.Report(analysis.Diagnostic{
110110
Pos: fix.TextEdits[0].Pos,
111-
Message: "Invalid import order",
111+
Message: "File is not properly formatted",
112112
SuggestedFixes: []analysis.SuggestedFix{*fix},
113113
})
114114
}

pkg/golinters/gofmt/gofmt.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,23 +56,11 @@ func runGofmt(lintCtx *linter.Context, pass *analysis.Pass, settings *config.GoF
5656
continue
5757
}
5858

59-
err = internal.ExtractDiagnosticFromPatch(pass, file, string(diff), lintCtx, getIssuedTextGoFmt)
59+
err = internal.ExtractDiagnosticFromPatch(pass, file, string(diff), lintCtx)
6060
if err != nil {
6161
return fmt.Errorf("can't extract issues from gofmt diff output %q: %w", string(diff), err)
6262
}
6363
}
6464

6565
return nil
6666
}
67-
68-
func getIssuedTextGoFmt(settings *config.LintersSettings) string {
69-
text := "File is not `gofmt`-ed"
70-
if settings.Gofmt.Simplify {
71-
text += " with `-s`"
72-
}
73-
for _, rule := range settings.Gofmt.RewriteRules {
74-
text += fmt.Sprintf(" `-r '%s -> %s'`", rule.Pattern, rule.Replacement)
75-
}
76-
77-
return text
78-
}

pkg/golinters/gofumpt/gofumpt.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func runGofumpt(lintCtx *linter.Context, pass *analysis.Pass, diff differ, optio
8383

8484
diff := out.String()
8585

86-
err = internal.ExtractDiagnosticFromPatch(pass, file, diff, lintCtx, getIssuedTextGoFumpt)
86+
err = internal.ExtractDiagnosticFromPatch(pass, file, diff, lintCtx)
8787
if err != nil {
8888
return fmt.Errorf("can't extract issues from gofumpt diff output %q: %w", diff, err)
8989
}
@@ -101,13 +101,3 @@ func getLangVersion(settings *config.GofumptSettings) string {
101101

102102
return "go" + strings.TrimPrefix(settings.LangVersion, "go")
103103
}
104-
105-
func getIssuedTextGoFumpt(settings *config.LintersSettings) string {
106-
text := "File is not `gofumpt`-ed"
107-
108-
if settings.Gofumpt.ExtraRules {
109-
text += " with `-extra`"
110-
}
111-
112-
return text
113-
}

pkg/golinters/goimports/goimports.go

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,11 @@ func runGoImports(lintCtx *linter.Context, pass *analysis.Pass) error {
5454
continue
5555
}
5656

57-
err = internal.ExtractDiagnosticFromPatch(pass, file, string(diff), lintCtx, getIssuedTextGoImports)
57+
err = internal.ExtractDiagnosticFromPatch(pass, file, string(diff), lintCtx)
5858
if err != nil {
5959
return fmt.Errorf("can't extract issues from gofmt diff output %q: %w", string(diff), err)
6060
}
6161
}
6262

6363
return nil
6464
}
65-
66-
func getIssuedTextGoImports(settings *config.LintersSettings) string {
67-
text := "File is not `goimports`-ed"
68-
69-
if settings.Goimports.LocalPrefixes != "" {
70-
text += " with -local " + settings.Goimports.LocalPrefixes
71-
}
72-
73-
return text
74-
}

pkg/golinters/internal/diff.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ func ExtractDiagnosticFromPatch(
219219
file *ast.File,
220220
patch string,
221221
lintCtx *linter.Context,
222-
formatter fmtTextFormatter,
223222
) error {
224223
diffs, err := diffpkg.ParseMultiFileDiff([]byte(patch))
225224
if err != nil {
@@ -246,23 +245,23 @@ func ExtractDiagnosticFromPatch(
246245
changes := p.parse(hunk)
247246

248247
for _, change := range changes {
249-
pass.Report(toDiagnostic(ft, change, formatter(lintCtx.Settings()), adjLine))
248+
pass.Report(toDiagnostic(ft, change, adjLine))
250249
}
251250
}
252251
}
253252

254253
return nil
255254
}
256255

257-
func toDiagnostic(ft *token.File, change Change, message string, adjLine int) analysis.Diagnostic {
256+
func toDiagnostic(ft *token.File, change Change, adjLine int) analysis.Diagnostic {
258257
start := ft.LineStart(change.From + adjLine)
259258

260259
end := goanalysis.EndOfLinePos(ft, change.To+adjLine)
261260

262261
return analysis.Diagnostic{
263262
Pos: start,
264263
End: end,
265-
Message: message, // TODO(ldez) change message formatter to have a better message.
264+
Message: "File is not properly formatted",
266265
SuggestedFixes: []analysis.SuggestedFix{{
267266
TextEdits: []analysis.TextEdit{{
268267
Pos: start,

0 commit comments

Comments
 (0)