Skip to content

Commit 8b6a5a6

Browse files
committed
Fix golint warnings
1 parent 20a2660 commit 8b6a5a6

4 files changed

Lines changed: 83 additions & 28 deletions

File tree

generator/root_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ func TestShouldGenerateCodeRaiseErrorWhenCodeFormatterIsExited(t *testing.T) {
491491
).EnableSyntaxChecking()
492492

493493
_, err := generator.Generate(0)
494-
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command="gofmt -e".+`), err.Error())
494+
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command='gofmt -e'.+`), err.Error())
495495
}
496496

497497
{
@@ -500,7 +500,7 @@ func TestShouldGenerateCodeRaiseErrorWhenCodeFormatterIsExited(t *testing.T) {
500500
).Gofmt()
501501

502502
_, err := generator.Generate(0)
503-
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command="gofmt".+`), err.Error())
503+
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command='gofmt'.+`), err.Error())
504504
}
505505

506506
{
@@ -509,11 +509,11 @@ func TestShouldGenerateCodeRaiseErrorWhenCodeFormatterIsExited(t *testing.T) {
509509
).Goimports()
510510

511511
_, err := generator.Generate(0)
512-
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command="goimports".+`), err.Error())
512+
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command='goimports'.+`), err.Error())
513513
}
514514

515515
{
516516
_, err := applyCodeFormatter("", "not-existed-cmd")
517-
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command="not-existed-cmd".+`), err.Error())
517+
assert.Regexp(t, regexp.MustCompile(`^\[GOWRTR-13\] code formatter raises error: command='not-existed-cmd'.+`), err.Error())
518518
}
519519
}

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ module github.com/moznion/gowrtr
22

33
require (
44
github.com/davecgh/go-spew v1.1.1 // indirect
5-
github.com/moznion/go-errgen v1.3.2
5+
github.com/iancoleman/strcase v0.0.0-20191112232945-16388991a334 // indirect
6+
github.com/moznion/go-errgen v1.8.1
67
github.com/pkg/errors v0.9.1
78
github.com/stretchr/testify v1.3.0
8-
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1
9-
golang.org/x/tools v0.0.0-20190121143147-24cd39ecf745 // indirect
9+
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f
10+
golang.org/x/tools v0.0.0-20200117220505-0cba7a3a9ee9 // indirect
1011
)
1112

1213
go 1.13

internal/errmsg/errmsg.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type errs struct {
1414
FuncSignatureIsNilError error `errmsg:"func signature must not be nil, bit it gets nil (caused at %s)" vars:"caller string"`
1515
AnonymousFuncSignatureIsNilError error `errmsg:"anonymous func signature must not be nil, bit it gets nil (caused at %s)" vars:"caller string"`
1616
FuncInvocationParameterIsEmptyError error `errmsg:"a parameter of function invocation must not be nil, but it gets nil (caused at %s)" vars:"caller string"`
17-
CodeFormatterError error `errmsg:"code formatter raises error: command=\"%s\", err=\"%s\", msg=\"%s\"" vars:"cmd string, msg string, fmterr error"`
17+
CodeFormatterError error `errmsg:"code formatter raises error: command='%s', err='%s', msg='%s'" vars:"cmd string, msg string, fmterr error"`
1818
CaseConditionIsEmptyError error `errmsg:"condition of case must not be empty, but it gets empty (caused at %s)" vars:"caller string"`
1919
IfConditionIsEmptyError error `errmsg:"condition of if must not be empty, but it gets empty (caused at %s)" vars:"caller string"`
2020
UnnamedReturnTypeAppearsAfterNamedReturnTypeError error `errmsg:"unnamed return type appears after named return type (caused at %s)" vars:"caller string"`

internal/errmsg/errs_errmsg_gen.go

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,164 +14,218 @@ import (
1414
func StructNameIsNilErr(caller string) error {
1515
return fmt.Errorf(`[GOWRTR-1] struct name must not be empty, but it gets empty (caused at %s)`, caller)
1616
}
17+
18+
// StructNameIsNilErrWrap wraps the error.
1719
func StructNameIsNilErrWrap(caller string, err error) error {
18-
return errors.Wrap(fmt.Errorf(`[GOWRTR-1] struct name must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
20+
return errors.Wrap(err, "[GOWRTR-1] struct name must not be empty, but it gets empty (caused at %s)")
1921
}
2022

2123
// StructFieldNameIsEmptyErr returns the error.
2224
func StructFieldNameIsEmptyErr(caller string) error {
2325
return fmt.Errorf(`[GOWRTR-2] field name must not be empty, but it gets empty (caused at %s)`, caller)
2426
}
27+
28+
// StructFieldNameIsEmptyErrWrap wraps the error.
2529
func StructFieldNameIsEmptyErrWrap(caller string, err error) error {
26-
return errors.Wrap(fmt.Errorf(`[GOWRTR-2] field name must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
30+
return errors.Wrap(err, "[GOWRTR-2] field name must not be empty, but it gets empty (caused at %s)")
2731
}
2832

2933
// StructFieldTypeIsEmptyErr returns the error.
3034
func StructFieldTypeIsEmptyErr(caller string) error {
3135
return fmt.Errorf(`[GOWRTR-3] field type must not be empty, but it gets empty (caused at %s)`, caller)
3236
}
37+
38+
// StructFieldTypeIsEmptyErrWrap wraps the error.
3339
func StructFieldTypeIsEmptyErrWrap(caller string, err error) error {
34-
return errors.Wrap(fmt.Errorf(`[GOWRTR-3] field type must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
40+
return errors.Wrap(err, "[GOWRTR-3] field type must not be empty, but it gets empty (caused at %s)")
3541
}
3642

3743
// FuncParameterNameIsEmptyErr returns the error.
3844
func FuncParameterNameIsEmptyErr(caller string) error {
3945
return fmt.Errorf(`[GOWRTR-4] func parameter name must not be empty, but it gets empty (caused at %s)`, caller)
4046
}
47+
48+
// FuncParameterNameIsEmptyErrWrap wraps the error.
4149
func FuncParameterNameIsEmptyErrWrap(caller string, err error) error {
42-
return errors.Wrap(fmt.Errorf(`[GOWRTR-4] func parameter name must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
50+
return errors.Wrap(err, "[GOWRTR-4] func parameter name must not be empty, but it gets empty (caused at %s)")
4351
}
4452

4553
// LastFuncParameterTypeIsEmptyErr returns the error.
4654
func LastFuncParameterTypeIsEmptyErr(caller string) error {
4755
return fmt.Errorf(`[GOWRTR-5] the last func parameter type must not be empty, but it gets empty (caused at %s)`, caller)
4856
}
57+
58+
// LastFuncParameterTypeIsEmptyErrWrap wraps the error.
4959
func LastFuncParameterTypeIsEmptyErrWrap(caller string, err error) error {
50-
return errors.Wrap(fmt.Errorf(`[GOWRTR-5] the last func parameter type must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
60+
return errors.Wrap(err, "[GOWRTR-5] the last func parameter type must not be empty, but it gets empty (caused at %s)")
5161
}
5262

5363
// FuncNameIsEmptyError returns the error.
5464
func FuncNameIsEmptyError(caller string) error {
5565
return fmt.Errorf(`[GOWRTR-6] name of func must not be empty, but it gets empty (caused at %s)`, caller)
5666
}
67+
68+
// FuncNameIsEmptyErrorWrap wraps the error.
5769
func FuncNameIsEmptyErrorWrap(caller string, err error) error {
58-
return errors.Wrap(fmt.Errorf(`[GOWRTR-6] name of func must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
70+
return errors.Wrap(err, "[GOWRTR-6] name of func must not be empty, but it gets empty (caused at %s)")
5971
}
6072

6173
// InterfaceNameIsEmptyError returns the error.
6274
func InterfaceNameIsEmptyError(caller string) error {
6375
return fmt.Errorf(`[GOWRTR-7] name of interface must not be empty, but it gets empty (caused at %s)`, caller)
6476
}
77+
78+
// InterfaceNameIsEmptyErrorWrap wraps the error.
6579
func InterfaceNameIsEmptyErrorWrap(caller string, err error) error {
66-
return errors.Wrap(fmt.Errorf(`[GOWRTR-7] name of interface must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
80+
return errors.Wrap(err, "[GOWRTR-7] name of interface must not be empty, but it gets empty (caused at %s)")
6781
}
6882

6983
// FuncReceiverNameIsEmptyError returns the error.
7084
func FuncReceiverNameIsEmptyError(caller string) error {
7185
return fmt.Errorf(`[GOWRTR-8] name of func receiver must not be empty, but it gets empty (caused at %s)`, caller)
7286
}
87+
88+
// FuncReceiverNameIsEmptyErrorWrap wraps the error.
7389
func FuncReceiverNameIsEmptyErrorWrap(caller string, err error) error {
74-
return errors.Wrap(fmt.Errorf(`[GOWRTR-8] name of func receiver must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
90+
return errors.Wrap(err, "[GOWRTR-8] name of func receiver must not be empty, but it gets empty (caused at %s)")
7591
}
7692

7793
// FuncReceiverTypeIsEmptyError returns the error.
7894
func FuncReceiverTypeIsEmptyError(caller string) error {
7995
return fmt.Errorf(`[GOWRTR-9] type of func receiver must not be empty, but it gets empty (caused at %s)`, caller)
8096
}
97+
98+
// FuncReceiverTypeIsEmptyErrorWrap wraps the error.
8199
func FuncReceiverTypeIsEmptyErrorWrap(caller string, err error) error {
82-
return errors.Wrap(fmt.Errorf(`[GOWRTR-9] type of func receiver must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
100+
return errors.Wrap(err, "[GOWRTR-9] type of func receiver must not be empty, but it gets empty (caused at %s)")
83101
}
84102

85103
// FuncSignatureIsNilError returns the error.
86104
func FuncSignatureIsNilError(caller string) error {
87105
return fmt.Errorf(`[GOWRTR-10] func signature must not be nil, bit it gets nil (caused at %s)`, caller)
88106
}
107+
108+
// FuncSignatureIsNilErrorWrap wraps the error.
89109
func FuncSignatureIsNilErrorWrap(caller string, err error) error {
90-
return errors.Wrap(fmt.Errorf(`[GOWRTR-10] func signature must not be nil, bit it gets nil (caused at %s)`, caller), err.Error())
110+
return errors.Wrap(err, "[GOWRTR-10] func signature must not be nil, bit it gets nil (caused at %s)")
91111
}
92112

93113
// AnonymousFuncSignatureIsNilError returns the error.
94114
func AnonymousFuncSignatureIsNilError(caller string) error {
95115
return fmt.Errorf(`[GOWRTR-11] anonymous func signature must not be nil, bit it gets nil (caused at %s)`, caller)
96116
}
117+
118+
// AnonymousFuncSignatureIsNilErrorWrap wraps the error.
97119
func AnonymousFuncSignatureIsNilErrorWrap(caller string, err error) error {
98-
return errors.Wrap(fmt.Errorf(`[GOWRTR-11] anonymous func signature must not be nil, bit it gets nil (caused at %s)`, caller), err.Error())
120+
return errors.Wrap(err, "[GOWRTR-11] anonymous func signature must not be nil, bit it gets nil (caused at %s)")
99121
}
100122

101123
// FuncInvocationParameterIsEmptyError returns the error.
102124
func FuncInvocationParameterIsEmptyError(caller string) error {
103125
return fmt.Errorf(`[GOWRTR-12] a parameter of function invocation must not be nil, but it gets nil (caused at %s)`, caller)
104126
}
127+
128+
// FuncInvocationParameterIsEmptyErrorWrap wraps the error.
105129
func FuncInvocationParameterIsEmptyErrorWrap(caller string, err error) error {
106-
return errors.Wrap(fmt.Errorf(`[GOWRTR-12] a parameter of function invocation must not be nil, but it gets nil (caused at %s)`, caller), err.Error())
130+
return errors.Wrap(err, "[GOWRTR-12] a parameter of function invocation must not be nil, but it gets nil (caused at %s)")
107131
}
108132

109133
// CodeFormatterError returns the error.
110134
func CodeFormatterError(cmd string, msg string, fmterr error) error {
111-
return fmt.Errorf(`[GOWRTR-13] code formatter raises error: command="%s", err="%s", msg="%s"`, cmd, msg, fmterr)
135+
return fmt.Errorf(`[GOWRTR-13] code formatter raises error: command='%s', err='%s', msg='%s'`, cmd, msg, fmterr)
112136
}
137+
138+
// CodeFormatterErrorWrap wraps the error.
113139
func CodeFormatterErrorWrap(cmd string, msg string, fmterr error, err error) error {
114-
return errors.Wrap(fmt.Errorf(`[GOWRTR-13] code formatter raises error: command="%s", err="%s", msg="%s"`, cmd, msg, fmterr), err.Error())
140+
return errors.Wrap(err, "[GOWRTR-13] code formatter raises error: command='%s', err='%s', msg='%s'")
115141
}
116142

117143
// CaseConditionIsEmptyError returns the error.
118144
func CaseConditionIsEmptyError(caller string) error {
119145
return fmt.Errorf(`[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at %s)`, caller)
120146
}
147+
148+
// CaseConditionIsEmptyErrorWrap wraps the error.
121149
func CaseConditionIsEmptyErrorWrap(caller string, err error) error {
122-
return errors.Wrap(fmt.Errorf(`[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
150+
return errors.Wrap(err, "[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at %s)")
123151
}
124152

125153
// IfConditionIsEmptyError returns the error.
126154
func IfConditionIsEmptyError(caller string) error {
127155
return fmt.Errorf(`[GOWRTR-15] condition of if must not be empty, but it gets empty (caused at %s)`, caller)
128156
}
157+
158+
// IfConditionIsEmptyErrorWrap wraps the error.
129159
func IfConditionIsEmptyErrorWrap(caller string, err error) error {
130-
return errors.Wrap(fmt.Errorf(`[GOWRTR-15] condition of if must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
160+
return errors.Wrap(err, "[GOWRTR-15] condition of if must not be empty, but it gets empty (caused at %s)")
131161
}
132162

133163
// UnnamedReturnTypeAppearsAfterNamedReturnTypeError returns the error.
134164
func UnnamedReturnTypeAppearsAfterNamedReturnTypeError(caller string) error {
135165
return fmt.Errorf(`[GOWRTR-16] unnamed return type appears after named return type (caused at %s)`, caller)
136166
}
167+
168+
// UnnamedReturnTypeAppearsAfterNamedReturnTypeErrorWrap wraps the error.
137169
func UnnamedReturnTypeAppearsAfterNamedReturnTypeErrorWrap(caller string, err error) error {
138-
return errors.Wrap(fmt.Errorf(`[GOWRTR-16] unnamed return type appears after named return type (caused at %s)`, caller), err.Error())
170+
return errors.Wrap(err, "[GOWRTR-16] unnamed return type appears after named return type (caused at %s)")
139171
}
140172

141173
// ValueOfCompositeLiteralIsEmptyError returns the error.
142174
func ValueOfCompositeLiteralIsEmptyError(caller string) error {
143175
return fmt.Errorf(`[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)`, caller)
144176
}
177+
178+
// ValueOfCompositeLiteralIsEmptyErrorWrap wraps the error.
145179
func ValueOfCompositeLiteralIsEmptyErrorWrap(caller string, err error) error {
146-
return errors.Wrap(fmt.Errorf(`[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)`, caller), err.Error())
180+
return errors.Wrap(err, "[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)")
147181
}
148182

183+
// ErrsType represents the error type.
149184
type ErrsType int
150185

151186
const (
187+
188+
// StructNameIsNilErrType represents the error type for StructNameIsNilErr.
152189
StructNameIsNilErrType ErrsType = iota
190+
// StructFieldNameIsEmptyErrType represents the error type for StructFieldNameIsEmptyErr.
153191
StructFieldNameIsEmptyErrType
192+
// StructFieldTypeIsEmptyErrType represents the error type for StructFieldTypeIsEmptyErr.
154193
StructFieldTypeIsEmptyErrType
194+
// FuncParameterNameIsEmptyErrType represents the error type for FuncParameterNameIsEmptyErr.
155195
FuncParameterNameIsEmptyErrType
196+
// LastFuncParameterTypeIsEmptyErrType represents the error type for LastFuncParameterTypeIsEmptyErr.
156197
LastFuncParameterTypeIsEmptyErrType
198+
// FuncNameIsEmptyErrorType represents the error type for FuncNameIsEmptyError.
157199
FuncNameIsEmptyErrorType
200+
// InterfaceNameIsEmptyErrorType represents the error type for InterfaceNameIsEmptyError.
158201
InterfaceNameIsEmptyErrorType
202+
// FuncReceiverNameIsEmptyErrorType represents the error type for FuncReceiverNameIsEmptyError.
159203
FuncReceiverNameIsEmptyErrorType
204+
// FuncReceiverTypeIsEmptyErrorType represents the error type for FuncReceiverTypeIsEmptyError.
160205
FuncReceiverTypeIsEmptyErrorType
206+
// FuncSignatureIsNilErrorType represents the error type for FuncSignatureIsNilError.
161207
FuncSignatureIsNilErrorType
208+
// AnonymousFuncSignatureIsNilErrorType represents the error type for AnonymousFuncSignatureIsNilError.
162209
AnonymousFuncSignatureIsNilErrorType
210+
// FuncInvocationParameterIsEmptyErrorType represents the error type for FuncInvocationParameterIsEmptyError.
163211
FuncInvocationParameterIsEmptyErrorType
212+
// CodeFormatterErrorType represents the error type for CodeFormatterError.
164213
CodeFormatterErrorType
214+
// CaseConditionIsEmptyErrorType represents the error type for CaseConditionIsEmptyError.
165215
CaseConditionIsEmptyErrorType
216+
// IfConditionIsEmptyErrorType represents the error type for IfConditionIsEmptyError.
166217
IfConditionIsEmptyErrorType
218+
// UnnamedReturnTypeAppearsAfterNamedReturnTypeErrorType represents the error type for UnnamedReturnTypeAppearsAfterNamedReturnTypeError.
167219
UnnamedReturnTypeAppearsAfterNamedReturnTypeErrorType
220+
// ValueOfCompositeLiteralIsEmptyErrorType represents the error type for ValueOfCompositeLiteralIsEmptyError.
168221
ValueOfCompositeLiteralIsEmptyErrorType
222+
// ErrsUnknownType represents unknown type for Errs
169223
ErrsUnknownType
170224
)
171225

172-
// ErrsList returns the list of errors.
226+
// ListErrs returns the list of errors.
173227
func ListErrs() []string {
174-
return []string{"[GOWRTR-1] struct name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-2] field name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-3] field type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-4] func parameter name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-5] the last func parameter type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-6] name of func must not be empty, but it gets empty (caused at %s)", "[GOWRTR-7] name of interface must not be empty, but it gets empty (caused at %s)", "[GOWRTR-8] name of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-9] type of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-10] func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-11] anonymous func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-12] a parameter of function invocation must not be nil, but it gets nil (caused at %s)", "[GOWRTR-13] code formatter raises error: command=\"%s\", err=\"%s\", msg=\"%s\"", "[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at %s)", "[GOWRTR-15] condition of if must not be empty, but it gets empty (caused at %s)", "[GOWRTR-16] unnamed return type appears after named return type (caused at %s)", "[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)"}
228+
return []string{"[GOWRTR-1] struct name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-2] field name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-3] field type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-4] func parameter name must not be empty, but it gets empty (caused at %s)", "[GOWRTR-5] the last func parameter type must not be empty, but it gets empty (caused at %s)", "[GOWRTR-6] name of func must not be empty, but it gets empty (caused at %s)", "[GOWRTR-7] name of interface must not be empty, but it gets empty (caused at %s)", "[GOWRTR-8] name of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-9] type of func receiver must not be empty, but it gets empty (caused at %s)", "[GOWRTR-10] func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-11] anonymous func signature must not be nil, bit it gets nil (caused at %s)", "[GOWRTR-12] a parameter of function invocation must not be nil, but it gets nil (caused at %s)", "[GOWRTR-13] code formatter raises error: command='%s', err='%s', msg='%s'", "[GOWRTR-14] condition of case must not be empty, but it gets empty (caused at %s)", "[GOWRTR-15] condition of if must not be empty, but it gets empty (caused at %s)", "[GOWRTR-16] unnamed return type appears after named return type (caused at %s)", "[GOWRTR-17] a value of composite literal must not be empty, but it gets empty (caused at %s)"}
175229
}
176230

177231
// IdentifyErrs checks the identity of an error

0 commit comments

Comments
 (0)