Skip to content

Commit f996a66

Browse files
authored
feat: improve formatter messages (#5243)
1 parent c16fb19 commit f996a66

File tree

18 files changed

+22
-58
lines changed

18 files changed

+22
-58
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/gci/testdata/gci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//golangcitest:config_path testdata/gci.yml
33
package testdata
44

5-
// want +1 "Invalid import order"
5+
// want +1 "File is not properly formatted"
66
import (
77
"golang.org/x/tools/go/analysis"
88
"github.com/golangci/golangci-lint/pkg/config"

pkg/golinters/gci/testdata/gci_cgo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ package testdata
1616
*/
1717
import "C"
1818

19-
// want +1 "Invalid import order"
19+
// want +1 "File is not properly formatted"
2020
import (
2121
"golang.org/x/tools/go/analysis"
2222
"github.com/golangci/golangci-lint/pkg/config"

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/gofmt/testdata/gofmt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ import "fmt"
55

66
func GofmtNotSimplified() {
77
var x []string
8-
fmt.Print(x[1:len(x)]) // want "File is not `gofmt`-ed with `-s`"
8+
fmt.Print(x[1:len(x)]) // want "File is not properly formatted"
99
}

pkg/golinters/gofmt/testdata/gofmt_cgo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ func _() {
2424

2525
func GofmtNotSimplified() {
2626
var x []string
27-
fmt.Print(x[1:len(x)]) // want "File is not `gofmt`-ed with `-s`"
27+
fmt.Print(x[1:len(x)]) // want "File is not properly formatted"
2828
}

pkg/golinters/gofmt/testdata/gofmt_no_simplify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ func GofmtNotSimplifiedOk() {
99
fmt.Print(x[1:len(x)])
1010
}
1111

12-
func GofmtBadFormat(){ // want "^File is not `gofmt`-ed"
12+
func GofmtBadFormat(){ // want "File is not properly formatted"
1313
}

pkg/golinters/gofmt/testdata/gofmt_rewrite_rules.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func GofmtRewriteRule() {
1111
vals = append(vals, 2)
1212
vals = append(vals, 3)
1313

14-
slice := vals[1:len(vals)] // want "^File is not `gofmt`-ed"
14+
slice := vals[1:len(vals)] // want "File is not properly formatted"
1515

1616
fmt.Println(slice)
1717
}

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/gofumpt/testdata/gofumpt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package testdata
44
import "fmt"
55

66
func GofumptNewLine() {
7-
fmt.Println( "foo" ) // want "File is not `gofumpt`-ed"
7+
fmt.Println( "foo" ) // want "File is not properly formatted"
88
}

0 commit comments

Comments
 (0)