Skip to content

Commit b38cc86

Browse files
committed
chore(lint): updated linters, relinted code
Signed-off-by: Frédéric BIDON <[email protected]>
1 parent 9fc682f commit b38cc86

File tree

4 files changed

+37
-35
lines changed

4 files changed

+37
-35
lines changed

.golangci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ linters:
2121
- musttag
2222
- nestif
2323
- nlreturn
24+
- noinlineerr
2425
- nonamedreturns
2526
- paralleltest
2627
- testpackage
@@ -31,6 +32,7 @@ linters:
3132
- whitespace
3233
- wrapcheck
3334
- wsl
35+
- wsl_v5
3436
settings:
3537
dupl:
3638
threshold: 200

api_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,64 +207,64 @@ func TestAPIErrors(t *testing.T) {
207207
err := New(402, "this failed %s", "yada")
208208
require.Error(t, err)
209209
assert.EqualValues(t, 402, err.Code())
210-
assert.EqualValues(t, "this failed yada", err.Error())
210+
assert.Equal(t, "this failed yada", err.Error())
211211

212212
err = NotFound("this failed %d", 1)
213213
require.Error(t, err)
214214
assert.EqualValues(t, http.StatusNotFound, err.Code())
215-
assert.EqualValues(t, "this failed 1", err.Error())
215+
assert.Equal(t, "this failed 1", err.Error())
216216

217217
err = NotFound("")
218218
require.Error(t, err)
219219
assert.EqualValues(t, http.StatusNotFound, err.Code())
220-
assert.EqualValues(t, "Not found", err.Error())
220+
assert.Equal(t, "Not found", err.Error())
221221

222222
err = NotImplemented("not implemented")
223223
require.Error(t, err)
224224
assert.EqualValues(t, http.StatusNotImplemented, err.Code())
225-
assert.EqualValues(t, "not implemented", err.Error())
225+
assert.Equal(t, "not implemented", err.Error())
226226

227227
err = MethodNotAllowed("GET", []string{"POST", "PUT"})
228228
require.Error(t, err)
229229
assert.EqualValues(t, http.StatusMethodNotAllowed, err.Code())
230-
assert.EqualValues(t, "method GET is not allowed, but [POST,PUT] are", err.Error())
230+
assert.Equal(t, "method GET is not allowed, but [POST,PUT] are", err.Error())
231231

232232
err = InvalidContentType("application/saml", []string{"application/json", "application/x-yaml"})
233233
require.Error(t, err)
234234
assert.EqualValues(t, http.StatusUnsupportedMediaType, err.Code())
235-
assert.EqualValues(t, "unsupported media type \"application/saml\", only [application/json application/x-yaml] are allowed", err.Error())
235+
assert.Equal(t, "unsupported media type \"application/saml\", only [application/json application/x-yaml] are allowed", err.Error())
236236

237237
err = InvalidResponseFormat("application/saml", []string{"application/json", "application/x-yaml"})
238238
require.Error(t, err)
239239
assert.EqualValues(t, http.StatusNotAcceptable, err.Code())
240-
assert.EqualValues(t, "unsupported media type requested, only [application/json application/x-yaml] are available", err.Error())
240+
assert.Equal(t, "unsupported media type requested, only [application/json application/x-yaml] are available", err.Error())
241241
}
242242

243243
func TestValidateName(t *testing.T) {
244244
v := &Validation{Name: "myValidation", message: "myMessage"}
245245

246246
// unchanged
247247
vv := v.ValidateName("")
248-
assert.EqualValues(t, "myValidation", vv.Name)
249-
assert.EqualValues(t, "myMessage", vv.message)
248+
assert.Equal(t, "myValidation", vv.Name)
249+
assert.Equal(t, "myMessage", vv.message)
250250

251251
// forced
252252
vv = v.ValidateName("myNewName")
253-
assert.EqualValues(t, "myNewName.myValidation", vv.Name)
254-
assert.EqualValues(t, "myNewName.myMessage", vv.message)
253+
assert.Equal(t, "myNewName.myValidation", vv.Name)
254+
assert.Equal(t, "myNewName.myMessage", vv.message)
255255

256256
v.Name = ""
257257
v.message = "myMessage"
258258

259259
// unchanged
260260
vv = v.ValidateName("")
261-
assert.EqualValues(t, "", vv.Name)
262-
assert.EqualValues(t, "myMessage", vv.message)
261+
assert.Empty(t, vv.Name)
262+
assert.Equal(t, "myMessage", vv.message)
263263

264264
// forced
265265
vv = v.ValidateName("myNewName")
266-
assert.EqualValues(t, "myNewName", vv.Name)
267-
assert.EqualValues(t, "myNewNamemyMessage", vv.message)
266+
assert.Equal(t, "myNewName", vv.Name)
267+
assert.Equal(t, "myNewNamemyMessage", vv.message)
268268
}
269269

270270
func TestMarshalJSON(t *testing.T) {

middleware.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ func (v *APIVerificationFailed) Error() string {
3535
hasSpecMissing := len(v.MissingSpecification) > 0
3636

3737
if hasRegMissing {
38-
buf.WriteString(fmt.Sprintf("missing [%s] %s registrations", strings.Join(v.MissingRegistration, ", "), v.Section))
38+
fmt.Fprintf(buf, "missing [%s] %s registrations", strings.Join(v.MissingRegistration, ", "), v.Section)
3939
}
4040

4141
if hasRegMissing && hasSpecMissing {
4242
buf.WriteString("\n")
4343
}
4444

4545
if hasSpecMissing {
46-
buf.WriteString(fmt.Sprintf("missing from spec file [%s] %s", strings.Join(v.MissingSpecification, ", "), v.Section))
46+
fmt.Fprintf(buf, "missing from spec file [%s] %s", strings.Join(v.MissingSpecification, ", "), v.Section)
4747
}
4848

4949
return buf.String()

parsing.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ type ParseError struct {
3030
message string
3131
}
3232

33+
// NewParseError creates a new parse error
34+
func NewParseError(name, in, value string, reason error) *ParseError {
35+
var msg string
36+
if in == "" {
37+
msg = fmt.Sprintf(parseErrorTemplContentNoIn, name, value, reason)
38+
} else {
39+
msg = fmt.Sprintf(parseErrorTemplContent, name, in, value, reason)
40+
}
41+
return &ParseError{
42+
code: http.StatusBadRequest,
43+
Name: name,
44+
In: in,
45+
Value: value,
46+
Reason: reason,
47+
message: msg,
48+
}
49+
}
50+
3351
func (e *ParseError) Error() string {
3452
return e.message
3553
}
@@ -59,21 +77,3 @@ const (
5977
parseErrorTemplContent = `parsing %s %s from %q failed, because %s`
6078
parseErrorTemplContentNoIn = `parsing %s from %q failed, because %s`
6179
)
62-
63-
// NewParseError creates a new parse error
64-
func NewParseError(name, in, value string, reason error) *ParseError {
65-
var msg string
66-
if in == "" {
67-
msg = fmt.Sprintf(parseErrorTemplContentNoIn, name, value, reason)
68-
} else {
69-
msg = fmt.Sprintf(parseErrorTemplContent, name, in, value, reason)
70-
}
71-
return &ParseError{
72-
code: http.StatusBadRequest,
73-
Name: name,
74-
In: in,
75-
Value: value,
76-
Reason: reason,
77-
message: msg,
78-
}
79-
}

0 commit comments

Comments
 (0)