Skip to content

Commit dbcecde

Browse files
authored
chore: format code with gofumpt (#1583)
1 parent db0fc86 commit dbcecde

13 files changed

+132
-59
lines changed

‎.golangci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ formatters:
137137
enable:
138138
- gci
139139
- gofmt
140+
- gofumpt
140141
- goimports
141142
settings:
142143
gci:

‎config/config_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ func TestGetConfig(t *testing.T) {
287287
}
288288

289289
cfg, err := config.GetConfig(cfgPath)
290-
291290
if err != nil {
292291
t.Fatalf("Unexpected error %v", err)
293292
}

‎formatter/friendly.go‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,10 @@ func (f *Friendly) printFriendlyFailure(sb *strings.Builder, failure lint.Failur
5757
sb.WriteString("\n\n")
5858
}
5959

60-
var errorEmoji = color.RedString("✘")
61-
var warningEmoji = color.YellowString("⚠")
60+
var (
61+
errorEmoji = color.RedString("✘")
62+
warningEmoji = color.YellowString("⚠")
63+
)
6264

6365
func (*Friendly) printHeaderRow(sb *strings.Builder, failure lint.Failure, severity lint.Severity) {
6466
emoji := warningEmoji

‎logging/logger_test.go‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ func TestGetLogger(t *testing.T) {
1212
t.Setenv("DEBUG", "")
1313

1414
logger, err := logging.GetLogger()
15-
1615
if err != nil {
1716
t.Fatalf("expected no error, got %v", err)
1817
}
@@ -27,7 +26,6 @@ func TestGetLogger(t *testing.T) {
2726
t.Cleanup(func() { os.Remove("revive.log") })
2827

2928
logger, err := logging.GetLogger()
30-
3129
if err != nil {
3230
t.Fatalf("expected no error, got %v", err)
3331
}

‎revivelib/core_internal_test.go‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ func TestReviveCreateInstance(t *testing.T) {
3636
}
3737
}
3838

39-
type mockRule struct {
40-
}
39+
type mockRule struct{}
4140

4241
func (*mockRule) Name() string {
4342
return "mock-rule"

‎rule/add_constant_test.go‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func TestAddConstantRule_Configure(t *testing.T) {
1717
wantStrLitLimit int
1818
}{
1919
{
20-
2120
name: "no arguments",
2221
arguments: lint.Arguments{},
2322
wantErr: nil,

‎rule/string_format_test.go‎

Lines changed: 87 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,121 +18,177 @@ func TestStringFormatConfigure(t *testing.T) {
1818
{
1919
name: "Not a Slice",
2020
arguments: lint.Arguments{
21-
"this is not a slice"},
22-
wantErr: errors.New("invalid configuration for string-format: argument is not a slice [argument 0, option 0]")},
21+
"this is not a slice",
22+
},
23+
wantErr: errors.New("invalid configuration for string-format: argument is not a slice [argument 0, option 0]"),
24+
},
2325
{
2426
name: "Missing Regex",
2527
arguments: lint.Arguments{
2628
[]any{
27-
"method[0]"}},
28-
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]")},
29+
"method[0]",
30+
},
31+
},
32+
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]"),
33+
},
2934
{
3035
name: "Bad Argument Type",
3136
arguments: lint.Arguments{
3237
[]any{
33-
1}},
34-
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]")},
38+
1,
39+
},
40+
},
41+
wantErr: errors.New("invalid configuration for string-format: less than two slices found in argument, scope and regex are required [argument 0, option 0]"),
42+
},
3543
{
3644
name: "Empty Scope",
3745
arguments: lint.Arguments{
3846
[]any{
3947
"",
40-
"//"}},
41-
wantErr: errors.New("invalid configuration for string-format: empty scope provided [argument 0, option 0]")},
48+
"//",
49+
},
50+
},
51+
wantErr: errors.New("invalid configuration for string-format: empty scope provided [argument 0, option 0]"),
52+
},
4253
{
4354
name: "Small or Empty Regex",
4455
arguments: lint.Arguments{
4556
[]any{
4657
"method[1].a",
47-
"-"}},
48-
wantErr: errors.New("invalid configuration for string-format: regex is too small (regexes should begin and end with '/') [argument 0, option 1]")},
58+
"-",
59+
},
60+
},
61+
wantErr: errors.New("invalid configuration for string-format: regex is too small (regexes should begin and end with '/') [argument 0, option 1]"),
62+
},
4963
{
5064
name: "Bad Scope",
5165
arguments: lint.Arguments{
5266
[]any{
5367
"1.a",
54-
"//"}},
55-
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]")},
68+
"//",
69+
},
70+
},
71+
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]"),
72+
},
5673
{
5774
name: "Bad Regex",
5875
arguments: lint.Arguments{
5976
[]any{
6077
"method[1].a",
61-
"/(/"}},
62-
wantErr: errors.New("failed to parse configuration for string-format: unable to compile /(/ as regexp [argument 0, option 1]")},
78+
"/(/",
79+
},
80+
},
81+
wantErr: errors.New("failed to parse configuration for string-format: unable to compile /(/ as regexp [argument 0, option 1]"),
82+
},
6383
{
6484
name: "Sample Config",
6585
arguments: lint.Arguments{
6686
[]any{
67-
"core.WriteError[1].Message", "/^([^A-Z]$)/", "must not start with a capital letter"},
87+
"core.WriteError[1].Message", "/^([^A-Z]$)/", "must not start with a capital letter",
88+
},
6889
[]any{
69-
"fmt.Errorf[0]", "/^|[^\\.!?]$/", "must not end in punctuation"},
90+
"fmt.Errorf[0]", "/^|[^\\.!?]$/", "must not end in punctuation",
91+
},
7092
[]any{
71-
"panic", "/^[^\\n]*$/", "must not contain line breaks"}}},
93+
"panic", "/^[^\\n]*$/", "must not contain line breaks",
94+
},
95+
},
96+
},
7297
{
7398
name: "Underscores in Scope",
7499
arguments: lint.Arguments{
75100
[]any{
76101
"some_pkg._some_function_name[5].some_member",
77-
"//"}}},
102+
"//",
103+
},
104+
},
105+
},
78106
{
79107
name: "Underscores in Multiple Scopes",
80108
arguments: lint.Arguments{
81109
[]any{
82110
"fmt.Errorf[0],core.WriteError[1].Message",
83-
"//"}}},
111+
"//",
112+
},
113+
},
114+
},
84115
{
85116
name: "', ' Delimiter",
86117
arguments: lint.Arguments{
87118
[]any{
88119
"abc, mt.Errorf",
89-
"//"}}},
120+
"//",
121+
},
122+
},
123+
},
90124
{
91125
name: "' ,' Delimiter",
92126
arguments: lint.Arguments{
93127
[]any{
94128
"abc ,mt.Errorf",
95-
"//"}}},
129+
"//",
130+
},
131+
},
132+
},
96133
{
97134
name: "', ' Delimiter",
98135
arguments: lint.Arguments{
99136
[]any{
100137
"abc, mt.Errorf",
101-
"//"}}},
138+
"//",
139+
},
140+
},
141+
},
102142
{
103143
name: "', ' Delimiter",
104144
arguments: lint.Arguments{
105145
[]any{
106146
"abc, mt.Errorf",
107-
"//"}}},
147+
"//",
148+
},
149+
},
150+
},
108151
{
109152
name: "Empty Middle Scope",
110153
arguments: lint.Arguments{
111154
[]any{
112155
"abc, ,mt.Errorf",
113-
"//"}},
114-
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 1]")},
156+
"//",
157+
},
158+
},
159+
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 1]"),
160+
},
115161
{
116162
name: "Empty First Scope",
117163
arguments: lint.Arguments{
118164
[]any{
119165
",mt.Errorf",
120-
"//"}},
121-
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 0]")},
166+
"//",
167+
},
168+
},
169+
wantErr: errors.New("failed to parse configuration for string-format: empty scope in rule scopes: [argument 0, option 0, scope index 0]"),
170+
},
122171
{
123172
name: "Bad First Scope",
124173
arguments: lint.Arguments{
125174
[]any{
126175
"1.a,fmt.Errorf[0]",
127-
"//"}},
128-
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]")},
176+
"//",
177+
},
178+
},
179+
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 0]"),
180+
},
129181
{
130182
name: "Bad Second Scope",
131183
arguments: lint.Arguments{
132184
[]any{
133185
"fmt.Errorf[0],1.a",
134-
"//"}},
135-
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 1]")}}
186+
"//",
187+
},
188+
},
189+
wantErr: errors.New("failed to parse configuration for string-format: unable to parse rule scope [argument 0, option 0, scope index 1]"),
190+
},
191+
}
136192

137193
for _, tt := range tests {
138194
t.Run(tt.name, func(t *testing.T) {

‎rule/struct_tag.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ func checkTOMLTag(checkCtx *checkContext, tag *structtag.Tag, _ *ast.Field) (mes
631631
}
632632

633633
func checkURLTag(checkCtx *checkContext, tag *structtag.Tag, _ *ast.Field) (message string, succeeded bool) {
634-
var delimiter = ""
634+
var delimiter string
635635
for _, opt := range tag.Options {
636636
switch opt {
637637
case "int", "omitempty", "numbered", "brackets",

‎rule/unsecure_url_scheme.go‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ type lintUnsecureURLSchemeRule struct {
4242
onFailure func(lint.Failure)
4343
}
4444

45-
const schemeSeparator = "://"
46-
const schemeHTTP = "http"
47-
const schemeWS = "ws"
48-
const urlPrefixHTTP = schemeHTTP + schemeSeparator
49-
const urlPrefixWS = schemeWS + schemeSeparator
50-
const lenURLPrefixHTTP = len(urlPrefixHTTP)
51-
const lenURLPrefixWS = len(urlPrefixWS)
45+
const (
46+
schemeSeparator = "://"
47+
schemeHTTP = "http"
48+
schemeWS = "ws"
49+
urlPrefixHTTP = schemeHTTP + schemeSeparator
50+
urlPrefixWS = schemeWS + schemeSeparator
51+
lenURLPrefixHTTP = len(urlPrefixHTTP)
52+
lenURLPrefixWS = len(urlPrefixWS)
53+
)
5254

5355
func (w lintUnsecureURLSchemeRule) Visit(node ast.Node) ast.Visitor {
5456
n, ok := node.(*ast.BasicLit)

‎test/comment_spacings_test.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
func TestCommentSpacings(t *testing.T) {
1111
testRule(t, "comment_spacings", &rule.CommentSpacingsRule{}, &lint.RuleConfig{
12-
Arguments: []any{"myOwnDirective:", "+optional"}},
12+
Arguments: []any{"myOwnDirective:", "+optional"},
13+
},
1314
)
1415
}

0 commit comments

Comments
 (0)