151 msformat780 mscheck 2879total 353errors 666warnings 1860notes

Showing 1000 of 2879 detailed findings. The summary includes all 2879 findings.

auth_test.go1

25:10add-constantstring literal "bar" appears more than twice; define a constant

auth_test.go:25:10

24 assert.Contains(t, pairs, authPair{
25 user: "bar",
26 value: "Basic YmFyOmZvbw==",

tree_test.go1

709:5boolean-literal-comparisonomit the boolean literal from the logical expression

tree_test.go:709:5

708 value := node.getValue("/hello/abx/", nil, getSkippedNodes(), false)
709 if value.tsr != true {
710 t.Fatalf("want true, is false")

binding/default_validator.go1

47:28cognitive-complexityfunction has cognitive complexity 11; maximum is 7

binding/default_validator.go:47:28

46// ValidateStruct receives any kind of type, but only performed struct or pointer to struct type.
47func (v *defaultValidator) ValidateStruct(obj any) error {
48 if obj == nil {

binding/binding_test.go1

1054:6confusing-namingname testFormBindingIgnoreField differs from TestFormBindingIgnoreField only by capitalization

binding/binding_test.go:1054:6

1053
1054func testFormBindingIgnoreField(t *testing.T, method, path, badPath, body, badBody string) {
1055 b := Form

binding/form_mapping.go1

84:6cyclomatic-complexityfunction complexity is 17; maximum is 10

binding/form_mapping.go:84:6

83
84func mapping(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) {
85 if field.Tag.Get(tag) == "-" { // just ignoring this field

gin.go1

22:2deprecated-api-usagegolang.org/x/net/http2/h2c is deprecated: This package is deprecated.

gin.go:22:2

21 "golang.org/x/net/http2"
22 "golang.org/x/net/http2/h2c"
23)

auth_test.go1

93:12discarded-error-resulterror result returned by http.NewRequest is discarded

auth_test.go:93:12

92 w := httptest.NewRecorder()
93 req, _ := http.NewRequest(http.MethodGet, "/login", nil)
94 req.Header.Set("Authorization", authorizationHeader("admin", "password"))

auth.go1

44:1doc-comment-perioddocumentation comment should end with punctuation

auth.go:44:1

43
44// BasicAuthForRealm returns a Basic HTTP Authorization middleware. It takes as arguments a map[string]string where
45// the key is the user name and the value is the password, as well as the name of the Realm.

errors.go1

40:5error-namingpackage error variable should be named errFoo or ErrFoo

errors.go:40:5

39
40var _ error = (*Error)(nil)
41

binding/default_validator_test.go1

45:14error-stringserror string should not be capitalized or end with punctuation

binding/default_validator_test.go:45:14

44 if got := tt.err.Error(); got != tt.want {
45 t.Errorf("SliceValidationError.Error() = %v, want %v", got, tt.want)
46 }

errors_test.go1

110:6error-type-namingerror implementation type should have an Error suffix

errors_test.go:110:6

109
110type TestErr string
111

auth.go1

48:6exported-declaration-commentexported function or method should have a comment beginning with its name

auth.go:48:6

47// (see http://tools.ietf.org/html/rfc2617#section-1.2)
48func BasicAuthForRealm(accounts Accounts, realm string) HandlerFunc {
49 if realm == "" {

render/reader.go1

44:16external-call-in-loopnet/http.Get is called synchronously inside a loop; batch or move the external operation outside the loop

render/reader.go:44:16

43 for k, v := range r.Headers {
44 if header.Get(k) == "" {
45 header.Set(k, v)

binding/binding_test.go1

1:1file-length-limitfile has 1435 lines; maximum is 500

binding/binding_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

fs.go1

42:23flag-parameterboolean parameter listDirectory controls function flow

fs.go:42:23

41// otherwise it returns a filesystem that prevents http.FileServer() to list the directory files.
42func Dir(root string, listDirectory bool) http.FileSystem {
43 fs := http.Dir(root)

auth_test.go1

1:1formatfile is not formatted

auth_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt auth_test.go`

binding/form_mapping.go1

245:6function-lengthfunction has 40 statements and 77 lines; maximum is 50 statements or 75 lines

binding/form_mapping.go:245:6

244
245func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSet bool, err error) {
246 vs, ok := form[tagValue]

internal/bytesconv/bytesconv_test.go1

9:2import-alias-namingimport alias should contain lower-case letters and digits

internal/bytesconv/bytesconv_test.go:9:2

8 "bytes"
9 cRand "crypto/rand"
10 "math/rand"

context.go1

1336:24import-shadowingidentifier filepath shadows an imported package

context.go:1336:24

1335// File writes the specified file into the body stream in an efficient way.
1336func (c *Context) File(filepath string) {
1337 http.ServeFile(c.Writer, c.Request, filepath)

errors.go1

71:3inefficient-map-lookupreuse the map value obtained by the comma-ok lookup

errors.go:71:3

70 if _, ok := jsonData["error"]; !ok {
71 jsonData["error"] = msg.Error()
72 }

context_test.go1

816:49insecure-url-schemeURL uses insecure http scheme

context_test.go:816:49

815 c, _ := CreateTestContext(httptest.NewRecorder())
816 c.Request, _ = http.NewRequest(http.MethodGet, "http://example.com/?foo=bar&page=10&id=", nil)
817

response_writer.go1

23:21interface-method-limitinterface has 12 methods, exceeding the configured design limit of 10

response_writer.go:23:21

22// ResponseWriter ...
23type ResponseWriter interface {
24 http.ResponseWriter

tree.go1

433:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:433:7

432 // strings.HasPrefix(n.children[len(n.children)-1].path, ":") == n.wildChild
433 if n.wildChild {
434 index := len(*skippedNodes)

binding/binding_test.go1

57:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:57:6

56
57type FooDefaultBarStruct struct {
58 FooStruct

auth.go1

50:3modifies-parameterassignment modifies parameter realm

auth.go:50:3

49 if realm == "" {
50 realm = "Authorization Required"
51 }

render/html.go1

73:3modifies-value-receiverassignment modifies value receiver r

render/html.go:73:3

72 if r.FuncMap == nil {
73 r.FuncMap = template.FuncMap{}
74 }

benchmarks_test.go1

53:10nested-structsmove nested anonymous struct types to named declarations

benchmarks_test.go:53:10

52 router := New()
53 data := struct {
54 Status string `json:"status"`

context_test.go1

3291:44nil-contextdo not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use

context_test.go:3291:44

3290 assert.True(t, c.hasRequestContext(), "has request, has fallback")
3291 c.Request, _ = http.NewRequestWithContext(nil, "", "", nil) //nolint:staticcheck
3292 assert.False(t, c.hasRequestContext(), "has request with nil ctx, has fallback")

binding/form_mapping.go1

268:5no-else-after-returnremove else and unindent its body after the return

binding/form_mapping.go:268:5

267 return ok, err
268 } else if ok, err = trySetCustom(vs[0], value); ok {
269 return ok, err

binding/json_test.go1

78:6no-initreplace init with explicit initialization

binding/json_test.go:78:6

77
78func init() {
79 customConfig.RegisterExtension(&TimeEx{})

binding/binding_test.go1

1433:2no-naked-returnreturn values must be explicit

binding/binding_test.go:1433:2

1432 req, _ = http.NewRequest(method, path, bytes.NewBufferString(body))
1433 return
1434}

binding/binding.go1

72:5no-package-varpackage variables introduce mutable global state

binding/binding.go:72:5

71// under the hood.
72var Validator StructValidator = &defaultValidator{}
73

binding/form_mapping.go1

108:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

binding/form_mapping.go:108:5

107
108 if vKind != reflect.Struct || !field.Anonymous {
109 ok, err := tryToSetValue(value, field, setter, tag)

auth.go1

5:9package-commentspackage should have a documentation comment

auth.go:5:9

4
5package gin
6

ginS/gins.go1

5:9package-namingpackage name should be short, lower-case, and contain no separators

ginS/gins.go:5:9

4
5package ginS
6

binding/multipart_form_mapping_test.go1

65:32range-value-addresstaking the address of range value i can be misleading

binding/multipart_form_mapping_test.go:65:32

64 for i, file := range files {
65 assertMultipartFileHeader(t, &s.SliceValues[i], file)
66 assertMultipartFileHeader(t, s.SlicePtrs[i], file)

binding/binding_test.go1

648:20redundant-conversionconversion from float64 to the identical type is redundant

binding/binding_test.go:648:20

647 require.NoError(t, err)
648 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
649}

binding/binding.go1

100:2single-case-switchswitch with one case can be replaced by an if statement

binding/binding.go:100:2

99
100 switch contentType {
101 case MIMEJSON:

context_test.go1

44:1task-commentTODO comment should be resolved or linked to an owned work item

context_test.go:44:1

43
44// Unit tests TODO
45// func (c *Context) File(filepath string) {

auth_test.go1

16:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:16:6

15
16func TestBasicAuth(t *testing.T) {
17 pairs := processAccounts(Accounts{

benchmarks_test.go1

124:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

benchmarks_test.go:124:1

123
124type mockWriter struct {
125 headers http.Header

auth_test.go1

89:49unchecked-type-assertionuse the checked two-result form of the type assertion

auth_test.go:89:49

88 router.GET("/login", func(c *Context) {
89 c.String(http.StatusOK, c.MustGet(AuthUserKey).(string))
90 })

context_test.go1

3452:16unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

context_test.go:3452:16

3451
3452 res, err := http.DefaultClient.Do(req)
3453 if err != nil {

errors.go1

98:42unexported-returnexported function returns an unexported type

errors.go:98:42

97// ie ByType(gin.ErrorTypePublic) returns a slice of errors with type=ErrorTypePublic.
98func (a errorMsgs) ByType(typ ErrorType) errorMsgs {
99 if len(a) == 0 {

context_test.go1

3475:35unsafe-formatted-url-host-portformatted host and port may be invalid for IPv6; build the address with net.JoinHostPort

context_test.go:3475:35

3474 addr := strings.Split(l.Addr().String(), ":")
3475 res, err := http.Get(fmt.Sprintf("http://%s:%s/", localhostIP, addr[len(addr)-1]))
3476 if err != nil {

binding/binding_test.go1

858:64unused-parameterparameter badPath is unused

binding/binding_test.go:858:64

857
858func testFormBindingEmbeddedStruct(t *testing.T, method, path, badPath, body, badBody string) {
859 b := Form

benchmarks_test.go1

138:7unused-receiverreceiver m is unused

benchmarks_test.go:138:7

137
138func (m *mockWriter) Write(p []byte) (n int, err error) {
139 return len(p), nil

tree.go1

63:2var-namingidentifier should use MixedCaps rather than underscores

tree.go:63:2

62 i := 0
63 max_ := min(len(a), len(b))
64 for i < max_ && a[i] == b[i] {

auth_test.go1

29:10add-constantstring literal "foo" appears more than twice; define a constant

auth_test.go:29:10

28 assert.Contains(t, pairs, authPair{
29 user: "foo",
30 value: "Basic Zm9vOmJhcg==",

binding/form_mapping.go1

84:6cognitive-complexityfunction has cognitive complexity 23; maximum is 7

binding/form_mapping.go:84:6

83
84func mapping(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) {
85 if field.Tag.Get(tag) == "-" { // just ignoring this field

binding/default_validator.go1

79:28confusing-namingname validateStruct differs from ValidateStruct only by capitalization

binding/default_validator.go:79:28

78// validateStruct receives struct type
79func (v *defaultValidator) validateStruct(obj any) error {
80 v.lazyinit()

binding/form_mapping.go1

145:6cyclomatic-complexityfunction complexity is 11; maximum is 10

binding/form_mapping.go:145:6

144
145func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) {
146 var tagValue string

gin.go1

249:9deprecated-api-usagegolang.org/x/net/http2/h2c.NewHandler is deprecated: Set the [http.Server] Protocols field to use unencrypted HTTP/2 instead.

gin.go:249:9

248 h2s := &http2.Server{}
249 return h2c.NewHandler(engine, h2s)
250}

auth_test.go1

112:12discarded-error-resulterror result returned by http.NewRequest is discarded

auth_test.go:112:12

111 w := httptest.NewRecorder()
112 req, _ := http.NewRequest(http.MethodGet, "/login", nil)
113 req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))

binding/default_validator.go1

84:1doc-comment-perioddocumentation comment should end with punctuation

binding/default_validator.go:84:1

83
84// Engine returns the underlying validator engine which powers the default
85// Validator instance. This is useful if you want to register custom validations

context_test.go1

42:32error-stringserror string should not be capitalized or end with punctuation

context_test.go:42:32

41
42var errTestRender = errors.New("TestRender")
43

auth.go1

72:6exported-declaration-commentexported function or method should have a comment beginning with its name

auth.go:72:6

71// the key is the user name and the value is the password.
72func BasicAuth(accounts Accounts) HandlerFunc {
73 return BasicAuthForRealm(accounts, "")

routes_test.go1

563:47external-call-in-loopnet/http.Get is called synchronously inside a loop; batch or move the external operation outside the loop

routes_test.go:563:47

562 if w.Code != http.StatusNotFound {
563 assert.Equal(t, tr.location, w.Header().Get("Location"))
564 }

binding/form_mapping.go1

1:1file-length-limitfile has 551 lines; maximum is 500

binding/form_mapping.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

gin_test.go1

32:48flag-parameterboolean parameter tls controls function flow

gin_test.go:32:48

31
32func setupHTMLFiles(t *testing.T, mode string, tls bool, loadMethod func(*Engine)) *httptest.Server {
33 SetMode(mode)

benchmarks_test.go1

1:1formatfile is not formatted

benchmarks_test.go:1:1

1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt benchmarks_test.go`

binding/form_mapping_test.go1

1068:6function-lengthfunction has 39 statements and 79 lines; maximum is 50 statements or 75 lines

binding/form_mapping_test.go:1068:6

1067
1068func TestMappingEmptyValues(t *testing.T) {
1069 t.Run("slice with default", func(t *testing.T) {

context.go1

1341:30import-shadowingidentifier filepath shadows an imported package

context.go:1341:30

1340// FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.
1341func (c *Context) FileFromFS(filepath string, fs http.FileSystem) {
1342 defer func(old string) {

context_test.go1

1165:49insecure-url-schemeURL uses insecure http scheme

context_test.go:1165:49

1164 c, _ := CreateTestContext(w)
1165 c.Request, _ = http.NewRequest(http.MethodGet, "http://example.com/?callback=x", nil)
1166

routergroup.go1

27:14interface-method-limitinterface has 16 methods, exceeding the configured design limit of 10

routergroup.go:27:14

26// IRouter defines all router handle interface includes single and group router.
27type IRouter interface {
28 IRoutes

tree.go1

460:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:460:7

459 if path != "/" {
460 for length := len(*skippedNodes); length > 0; length-- {
461 skippedNode := (*skippedNodes)[length-1]

binding/binding_test.go1

62:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:62:6

61
62type FooStructUseNumber struct {
63 Foo any `json:"foo" binding:"required"`

auth.go1

52:2modifies-parameterassignment modifies parameter realm

auth.go:52:2

51 }
52 realm = "Basic realm=" + strconv.Quote(realm)
53 pairs := processAccounts(accounts)

render/reader.go1

26:4modifies-value-receiverassignment modifies value receiver r

render/reader.go:26:4

25 if r.Headers == nil {
26 r.Headers = map[string]string{}
27 }

binding/binding_test.go1

111:11nested-structsmove nested anonymous struct types to named declarations

binding/binding_test.go:111:11

110type InvalidNameMapType struct {
111 TestName struct {
112 MapFoo map[string]any `form:"map_foo"`

binding/form_mapping.go1

293:5no-else-after-returnremove else and unindent its body after the return

binding/form_mapping.go:293:5

292 return ok, err
293 } else if ok, err = trySetCustom(vs[0], value); ok {
294 return ok, err

codec/json/go_json.go1

18:6no-initreplace init with explicit initialization

codec/json/go_json.go:18:6

17
18func init() {
19 API = gojsonApi{}

context.go1

302:2no-naked-returnreturn values must be explicit

context.go:302:2

301 value, exists = c.Keys[key]
302 return
303}

binding/binding.go1

77:2no-package-varpackage variables introduce mutable global state

binding/binding.go:77:2

76var (
77 JSON BindingBody = jsonBinding{}
78 XML BindingBody = xmlBinding{}

binding/form_mapping.go1

124:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

binding/form_mapping.go:124:7

123 sf := tValue.Field(i)
124 if sf.PkgPath != "" && !sf.Anonymous { // unexported
125 continue

binding/binding.go1

7:9package-commentspackage should have a documentation comment

binding/binding.go:7:9

6
7package binding
8

ginS/gins_test.go1

5:9package-namingpackage name should be short, lower-case, and contain no separators

ginS/gins_test.go:5:9

4
5package ginS
6

binding/multipart_form_mapping_test.go1

67:32range-value-addresstaking the address of range value i can be misleading

binding/multipart_form_mapping_test.go:67:32

66 assertMultipartFileHeader(t, s.SlicePtrs[i], file)
67 assertMultipartFileHeader(t, &s.ArrayValues[i], file)
68 assertMultipartFileHeader(t, s.ArrayPtrs[i], file)

binding/binding_test.go1

702:20redundant-conversionconversion from float64 to the identical type is redundant

binding/binding_test.go:702:20

701 require.NoError(t, err)
702 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
703 assert.Equal(t, "thinkerou", obj.MapFoo["name"].(string))

binding/binding_nomsgpack.go1

96:2single-case-switchswitch with one case can be replaced by an if statement

binding/binding_nomsgpack.go:96:2

95
96 switch contentType {
97 case MIMEJSON:

context_test.go1

1667:1task-commentTODO comment should be resolved or linked to an owned work item

context_test.go:1667:1

1666
1667// TODO
1668func TestContextRenderRedirectWithRelativePath(t *testing.T) {

auth_test.go1

38:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:38:6

37
38func TestBasicAuthFails(t *testing.T) {
39 assert.Panics(t, func() { processAccounts(nil) })

binding/binding.go1

72:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/binding.go:72:1

71// under the hood.
72var Validator StructValidator = &defaultValidator{}
73

auth_test.go1

108:49unchecked-type-assertionuse the checked two-result form of the type assertion

auth_test.go:108:49

107 called = true
108 c.String(http.StatusOK, c.MustGet(AuthUserKey).(string))
109 })

context_test.go1

3475:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

context_test.go:3475:14

3474 addr := strings.Split(l.Addr().String(), ":")
3475 res, err := http.Get(fmt.Sprintf("http://%s:%s/", localhostIP, addr[len(addr)-1]))
3476 if err != nil {

binding/binding_test.go1

858:79unused-parameterparameter badBody is unused

binding/binding_test.go:858:79

857
858func testFormBindingEmbeddedStruct(t *testing.T, method, path, badPath, body, badBody string) {
859 b := Form

benchmarks_test.go1

142:7unused-receiverreceiver m is unused

benchmarks_test.go:142:7

141
142func (m *mockWriter) WriteString(s string) (n int, err error) {
143 return len(s), nil

tree.go1

191:11var-namingidentifier should use MixedCaps rather than underscores

tree.go:191:11

190 // Check if a child with the next path byte exists
191 for i, max_ := 0, len(n.indices); i < max_; i++ {
192 if c == n.indices[i] {

auth_test.go1

50:3add-constantstring literal "admin" appears more than twice; define a constant

auth_test.go:50:3

49 pairs := processAccounts(Accounts{
50 "admin": "password",
51 "foo": "bar",

binding/form_mapping.go1

145:6cognitive-complexityfunction has cognitive complexity 15; maximum is 7

binding/form_mapping.go:145:6

144
145func tryToSetValue(value reflect.Value, field reflect.StructField, setter setter, tag string) (bool, error) {
146 var tagValue string

context.go1

72:2confusing-namingname params differs from Params only by capitalization

context.go:72:2

71 engine *Engine
72 params *Params
73 skippedNodes *[]skippedNode

binding/form_mapping.go1

245:6cyclomatic-complexityfunction complexity is 27; maximum is 10

binding/form_mapping.go:245:6

244
245func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSet bool, err error) {
246 vs, ok := form[tagValue]

gin_test.go1

108:4deprecated-api-usagegolang.org/x/net/http2.DialTLS is deprecated: Use DialTLSContext instead, which allows the transport to cancel dials as soon as they are no longer needed. If both are set, DialTLSContext takes priority.

gin_test.go:108:4

107 AllowHTTP: true,
108 DialTLS: func(netw, addr string, cfg *tls.Config) (net.Conn, error) {
109 return net.Dial(netw, addr)

auth_test.go1

132:12discarded-error-resulterror result returned by http.NewRequest is discarded

auth_test.go:132:12

131 w := httptest.NewRecorder()
132 req, _ := http.NewRequest(http.MethodGet, "/login", nil)
133 req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))

binding/form_mapping.go1

25:2doc-comment-perioddocumentation comment should end with punctuation

binding/form_mapping.go:25:2

24
25 // ErrConvertMapStringSlice can not convert to map[string][]string
26 ErrConvertMapStringSlice = errors.New("can not convert to map slices of strings")

tree_test.go1

65:14error-stringserror string should not be capitalized or end with punctuation

tree_test.go:65:14

64 if !reflect.DeepEqual(*value.params, request.ps) {
65 t.Errorf("Params mismatch for route '%s'", request.path)
66 }

auth.go1

98:6exported-declaration-commentexported function or method should have a comment beginning with its name

auth.go:98:6

97// If the realm is empty, "Proxy Authorization Required" will be used by default.
98func BasicAuthForProxy(accounts Accounts, realm string) HandlerFunc {
99 if realm == "" {

routes_test.go1

593:47external-call-in-loopnet/http.Get is called synchronously inside a loop; batch or move the external operation outside the loop

routes_test.go:593:47

592 if w.Code != http.StatusNotFound {
593 assert.Equal(t, tr.location, w.Header().Get("Location"))
594 }

binding/form_mapping_test.go1

1:1file-length-limitfile has 1147 lines; maximum is 500

binding/form_mapping_test.go:1:1

1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style

tree.go1

418:83flag-parameterboolean parameter unescape controls function flow

tree.go:418:83

417// given path.
418func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
419 var globalParamsCount int16

binding/binding.go1

1:1formatfile is not formatted

binding/binding.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/binding.go`

context_test.go1

906:6function-lengthfunction has 72 statements and 97 lines; maximum is 50 statements or 75 lines

context_test.go:906:6

905
906func TestContextQueryAndPostForm(t *testing.T) {
907 c, _ := CreateTestContext(httptest.NewRecorder())

context.go1

1341:47import-shadowingidentifier fs shadows an imported package

context.go:1341:47

1340// FileFromFS writes the specified file from http.FileSystem into the body stream in an efficient way.
1341func (c *Context) FileFromFS(filepath string, fs http.FileSystem) {
1342 defer func(old string) {

context_test.go1

1179:49insecure-url-schemeURL uses insecure http scheme

context_test.go:1179:49

1178 c, _ := CreateTestContext(w)
1179 c.Request, _ = http.NewRequest(http.MethodGet, "http://example.com", nil)
1180

routergroup.go1

33:14interface-method-limitinterface has 15 methods, exceeding the configured design limit of 10

routergroup.go:33:14

32// IRoutes defines all router handle interface.
33type IRoutes interface {
34 Use(...HandlerFunc) IRoutes

tree.go1

463:8max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:463:8

462 *skippedNodes = (*skippedNodes)[:length-1]
463 if strings.HasSuffix(skippedNode.path, path) {
464 path = skippedNode.path

binding/binding_test.go1

66:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:66:6

65
66type FooStructDisallowUnknownFields struct {
67 Foo any `json:"foo" binding:"required"`

auth.go1

100:3modifies-parameterassignment modifies parameter realm

auth.go:100:3

99 if realm == "" {
100 realm = "Proxy Authorization Required"
101 }

render/reader.go1

28:3modifies-value-receiverassignment modifies value receiver r

render/reader.go:28:3

27 }
28 r.Headers["Content-Length"] = strconv.FormatInt(r.ContentLength, 10)
29 }

binding/binding_test.go1

121:12nested-structsmove nested anonymous struct types to named declarations

binding/binding_test.go:121:12

120type FooStructForStructType struct {
121 StructFoo struct {
122 Idx int `form:"idx"`

binding/form_mapping.go1

316:5no-else-after-returnremove else and unindent its body after the return

binding/form_mapping.go:316:5

315 return ok, err
316 } else if ok, err = trySetCustom(val, value); ok {
317 return ok, err

codec/json/json.go1

17:6no-initreplace init with explicit initialization

codec/json/json.go:17:6

16
17func init() {
18 API = jsonApi{}

context.go1

317:2no-naked-returnreturn values must be explicit

context.go:317:2

316 }
317 return
318}

binding/binding.go1

78:2no-package-varpackage variables introduce mutable global state

binding/binding.go:78:2

77 JSON BindingBody = jsonBinding{}
78 XML BindingBody = xmlBinding{}
79 Form Binding = formBinding{}

binding/form_mapping.go1

170:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

binding/form_mapping.go:170:8

169 cfTag := field.Tag.Get("collection_format")
170 if cfTag == "" || cfTag == "multi" || cfTag == "csv" {
171 setOpt.defaultValue = strings.ReplaceAll(v, ";", ",")

binding/binding_nomsgpack.go1

7:9package-commentspackage should have a documentation comment

binding/binding_nomsgpack.go:7:9

6
7package binding
8

gin.go1

424:18range-value-addresstaking the address of range value trustedProxy can be misleading

gin.go:424:18

423 if ip == nil {
424 return cidr, &net.ParseError{Type: "IP address", Text: trustedProxy}
425 }

binding/binding_test.go2

704:20redundant-conversionconversion from float64 to the identical type is redundant

binding/binding_test.go:704:20

703 assert.Equal(t, "thinkerou", obj.MapFoo["name"].(string))
704 assert.InDelta(t, float64(3.14), obj.MapFoo["pai"].(float64), 0.01)
705}
1114:2single-case-switchswitch with one case can be replaced by an if statement

binding/binding_test.go:1114:2

1113 }
1114 switch typ {
1115 case "Slice":

auth_test.go1

48:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:48:6

47
48func TestBasicAuthSearchCredential(t *testing.T) {
49 pairs := processAccounts(Accounts{

binding/binding_test.go1

1360:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/binding_test.go:1360:1

1359
1360type hook struct{}
1361

auth_test.go1

128:49unchecked-type-assertionuse the checked two-result form of the type assertion

auth_test.go:128:49

127 called = true
128 c.String(http.StatusOK, c.MustGet(AuthUserKey).(string))
129 })

gin_test.go1

76:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:76:14

75
76 res, err := http.Get(ts.URL + "/test")
77 if err != nil {

binding/binding_test.go1

1054:61unused-parameterparameter badPath is unused

binding/binding_test.go:1054:61

1053
1054func testFormBindingIgnoreField(t *testing.T, method, path, badPath, body, badBody string) {
1055 b := Form

benchmarks_test.go1

146:7unused-receiverreceiver m is unused

benchmarks_test.go:146:7

145
146func (m *mockWriter) WriteHeader(int) {}
147

tree.go1

763:9var-namingidentifier should use MixedCaps rather than underscores

tree.go:763:9

762 var off int
763 for max_ := min(npLen, 3); off < max_; off++ {
764 if i := npLen - off; utf8.RuneStart(oldPath[i]) {

auth_test.go1

50:12add-constantstring literal "password" appears more than twice; define a constant

auth_test.go:50:12

49 pairs := processAccounts(Accounts{
50 "admin": "password",
51 "foo": "bar",

binding/form_mapping.go1

245:6cognitive-complexityfunction has cognitive complexity 44; maximum is 7

binding/form_mapping.go:245:6

244
245func setByForm(value reflect.Value, field reflect.StructField, form map[string][]string, tagValue string, opt setOptions) (isSet bool, err error) {
246 vs, ok := form[tagValue]

routergroup.go1

103:27confusing-namingname Handle differs from handle only by capitalization

routergroup.go:103:27

102// communication with a proxy).
103func (group *RouterGroup) Handle(httpMethod, relativePath string, handlers ...HandlerFunc) IRoutes {
104 if matched := regEnLetter.MatchString(httpMethod); !matched {

binding/form_mapping.go1

323:6cyclomatic-complexityfunction complexity is 27; maximum is 10

binding/form_mapping.go:323:6

322
323func setWithProperType(val string, value reflect.Value, field reflect.StructField, opt setOptions) error {
324 // this if-check is required for parsing nested types like []MyId, where MyId is [12]byte

auth_test.go1

150:12discarded-error-resulterror result returned by http.NewRequest is discarded

auth_test.go:150:12

149 w := httptest.NewRecorder()
150 req, _ := http.NewRequest(http.MethodGet, "/test", nil)
151 req.Header.Set("Proxy-Authorization", authorizationHeader("admin", "password"))

binding/form_mapping.go1

28:2doc-comment-perioddocumentation comment should end with punctuation

binding/form_mapping.go:28:2

27
28 // ErrConvertToMapString can not convert to map[string]string
29 ErrConvertToMapString = errors.New("can not convert to map of strings")

tree_test.go1

770:13error-stringserror string should not be capitalized or end with punctuation

tree_test.go:770:13

769 if !found {
770 t.Errorf("Route '%s' not found!", route)
771 } else if string(out) != route {

benchmarks_test.go1

134:22exported-declaration-commentexported function or method should have a comment beginning with its name

benchmarks_test.go:134:22

133
134func (m *mockWriter) Header() (h http.Header) {
135 return m.headers

test_helpers.go1

45:26external-call-in-loopnet/http.Get is called synchronously inside a loop; batch or move the external operation outside the loop

test_helpers.go:45:26

44 for i := 0; i < maxAttempts; i++ {
45 resp, err := client.Get(url)
46 if err == nil {

context.go1

1:1file-length-limitfile has 1540 lines; maximum is 500

context.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

tree.go1

703:83flag-parameterboolean parameter fixTrailingSlash controls function flow

tree.go:703:83

702// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath
703func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {
704 npLen := len(n.path)

binding/binding_msgpack_test.go1

1:1formatfile is not formatted

binding/binding_msgpack_test.go:1:1

1// Copyright 2020 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/binding_msgpack_test.go`

context_test.go1

1004:6function-lengthfunction has 64 statements and 91 lines; maximum is 50 statements or 75 lines

context_test.go:1004:6

1003
1004func TestContextPostFormMultipart(t *testing.T) {
1005 c, _ := CreateTestContext(httptest.NewRecorder())

context.go1

1359:34import-shadowingidentifier filepath shadows an imported package

context.go:1359:34

1358// On the client side, the file will typically be downloaded with the given filename
1359func (c *Context) FileAttachment(filepath, filename string) {
1360 if isASCII(filename) {

context_test.go1

1672:50insecure-url-schemeURL uses insecure http scheme

context_test.go:1672:50

1671
1672 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", nil)
1673 assert.Panics(t, func() { c.Redirect(299, "/new_path") })

tree.go1

466:9max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:466:9

465 n = skippedNode.node
466 if value.params != nil {
467 *value.params = (*value.params)[:skippedNode.paramsCount]

binding/binding_test.go1

70:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:70:6

69
70type FooBarStructForTimeType struct {
71 TimeFoo time.Time `form:"time_foo" time_format:"2006-01-02" time_utc:"1" time_location:"Asia/Chongqing"`

auth.go1

102:2modifies-parameterassignment modifies parameter realm

auth.go:102:2

101 }
102 realm = "Basic realm=" + strconv.Quote(realm)
103 pairs := processAccounts(accounts)

binding/binding_test.go1

127:20nested-structsmove nested anonymous struct types to named declarations

binding/binding_test.go:127:20

126type FooStructForStructPointerType struct {
127 StructPointerFoo *struct {
128 Name string `form:"name"`

binding/form_mapping.go1

327:4no-else-after-returnremove else and unindent its body after the return

binding/form_mapping.go:327:4

326 return err
327 } else if ok, err = trySetCustom(val, value); ok {
328 return err

codec/json/jsoniter.go1

18:6no-initreplace init with explicit initialization

codec/json/jsoniter.go:18:6

17
18func init() {
19 API = jsoniterApi{}

context.go1

537:2no-naked-returnreturn values must be explicit

context.go:537:2

536 value, _ = c.GetQuery(key)
537 return
538}

binding/binding.go1

79:2no-package-varpackage variables introduce mutable global state

binding/binding.go:79:2

78 XML BindingBody = xmlBinding{}
79 Form Binding = formBinding{}
80 Query Binding = queryBinding{}

binding/form_mapping.go1

308:30optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

binding/form_mapping.go:308:30

307 var val string
308 if !ok || len(vs) == 0 || (len(vs) > 0 && vs[0] == "") {
309 val = opt.defaultValue

binding/bson.go1

5:9package-commentspackage should have a documentation comment

binding/bson.go:5:9

4
5package binding
6

recovery_test.go1

119:10range-value-addresstaking the address of range value errno can be misleading

recovery_test.go:119:10

118 // Oops. Client connection closed
119 e := &net.OpError{Err: &os.SyscallError{Err: errno}}
120 panic(e)

binding/binding_test.go1

967:18redundant-conversionconversion from int64 to the identical type is redundant

binding/binding_test.go:967:18

966 require.NoError(t, err)
967 assert.Equal(t, int64(1510675200), obj.TimeFoo.Unix())
968 assert.Equal(t, "Asia/Chongqing", obj.TimeFoo.Location().String())

binding/default_validator.go1

53:2single-case-switchswitch with one case can be replaced by an if statement

binding/default_validator.go:53:2

52 value := reflect.ValueOf(obj)
53 switch value.Kind() {
54 case reflect.Ptr:

auth_test.go1

80:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:80:6

79
80func TestBasicAuthAuthorizationHeader(t *testing.T) {
81 assert.Equal(t, "Basic YWRtaW46cGFzc3dvcmQ=", authorizationHeader("admin", "password"))

binding/default_validator.go1

44:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/default_validator.go:44:1

43
44var _ StructValidator = (*defaultValidator)(nil)
45

auth_test.go1

146:54unchecked-type-assertionuse the checked two-result form of the type assertion

auth_test.go:146:54

145 router.Any("/*proxyPath", func(c *Context) {
146 c.String(http.StatusOK, c.MustGet(AuthProxyUserKey).(string))
147 })

gin_test.go1

114:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:114:14

113
114 res, err := httpClient.Get(url)
115 if err != nil {

binding/binding_test.go2

1054:76unused-parameterparameter badBody is unused

binding/binding_test.go:1054:76

1053
1054func testFormBindingIgnoreField(t *testing.T, method, path, badPath, body, badBody string) {
1055 b := Form
1362:7unused-receiverreceiver h is unused

binding/binding_test.go:1362:7

1361
1362func (h hook) Read([]byte) (int, error) {
1363 return 0, errors.New("error")

tree.go1

843:9var-namingidentifier should use MixedCaps rather than underscores

tree.go:843:9

842 var off int
843 for max_ := min(npLen, 3); off < max_; off++ {
844 if i := npLen - off; utf8.RuneStart(oldPath[i]) {

auth_test.go1

106:13add-constantstring literal "/login" appears more than twice; define a constant

auth_test.go:106:13

105 router.Use(BasicAuth(accounts))
106 router.GET("/login", func(c *Context) {
107 called = true

binding/form_mapping.go1

323:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

binding/form_mapping.go:323:6

322
323func setWithProperType(val string, value reflect.Value, field reflect.StructField, opt setOptions) error {
324 // this if-check is required for parsing nested types like []MyId, where MyId is [12]byte

routes_test.go1

121:6confusing-namingname TestRouteNotOK differs from testRouteNotOK only by capitalization

routes_test.go:121:6

120
121func TestRouteNotOK(t *testing.T) {
122 testRouteNotOK(http.MethodGet, t)

binding/form_mapping.go1

434:6cyclomatic-complexityfunction complexity is 12; maximum is 10

binding/form_mapping.go:434:6

433
434func setTimeField(val string, structField reflect.StructField, value reflect.Value) error {
435 timeFormat := structField.Tag.Get("time_format")

auth_test.go1

169:12discarded-error-resulterror result returned by http.NewRequest is discarded

auth_test.go:169:12

168 w := httptest.NewRecorder()
169 req, _ := http.NewRequest(http.MethodGet, "/test", nil)
170 req.Header.Set("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))

binding/form_mapping.go1

74:1doc-comment-perioddocumentation comment should end with punctuation

binding/form_mapping.go:74:1

73
74// TrySet tries to set a value by request's form source (like map[string][]string)
75func (form formSource) TrySet(value reflect.Value, field reflect.StructField, tagValue string, opt setOptions) (isSet bool, err error) {

tree_test.go1

772:13error-stringserror string should not be capitalized or end with punctuation

tree_test.go:772:13

771 } else if string(out) != route {
772 t.Errorf("Wrong result for route '%s': %s", route, string(out))
773 }

benchmarks_test.go1

142:22exported-declaration-commentexported function or method should have a comment beginning with its name

benchmarks_test.go:142:22

141
142func (m *mockWriter) WriteString(s string) (n int, err error) {
143 return len(s), nil

context_test.go1

1:1file-length-limitfile has 3958 lines; maximum is 500

context_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

tree_test.go1

41:69flag-parameterboolean parameter unescapes controls function flow

tree_test.go:41:69

40
41func checkRequests(t *testing.T, tree *node, requests testRequests, unescapes ...bool) {
42 unescape := false

binding/binding_nomsgpack.go1

1:1formatfile is not formatted

binding/binding_nomsgpack.go:1:1

1// Copyright 2020 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/binding_nomsgpack.go`

context_test.go1

2062:6function-lengthfunction has 82 statements and 140 lines; maximum is 50 statements or 75 lines

context_test.go:2062:6

2061
2062func TestContextClientIP(t *testing.T) {
2063 c, _ := CreateTestContext(httptest.NewRecorder())

gin.go1

364:40import-shadowingidentifier path shadows an imported package

gin.go:364:40

363
364func (engine *Engine) addRoute(method, path string, handlers HandlersChain) {
365 assert1(path[0] == '/', "path must begin with '/'")

context_test.go1

1686:50insecure-url-schemeURL uses insecure http scheme

context_test.go:1686:50

1685
1686 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", nil)
1687 c.Redirect(http.StatusFound, "http://google.com")

tree.go1

500:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:500:7

499 // Preallocate capacity if necessary
500 if cap(*params) < int(globalParamsCount) {
501 newParams := make(Params, len(*params), globalParamsCount)

binding/binding_test.go1

79:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:79:6

78
79type FooStructForTimeTypeNotUnixFormat struct {
80 CreateTime time.Time `form:"createTime" time_format:"unixNano"`

binding/form_mapping.go1

57:4modifies-parameterassignment modifies parameter ptr

binding/form_mapping.go:57:4

56 if pointed != nil {
57 ptr = pointed
58 }

binding/binding_test.go1

839:8nested-structsmove nested anonymous struct types to named declarations

binding/binding_test.go:839:8

838 Name string `uri:"name"`
839 S struct {
840 Age int `uri:"age"`

codec/json/sonic.go1

18:6no-initreplace init with explicit initialization

codec/json/sonic.go:18:6

17
18func init() {
19 API = sonicApi{}

context.go1

575:2no-naked-returnreturn values must be explicit

context.go:575:2

574 values, _ = c.GetQueryArray(key)
575 return
576}

binding/binding.go1

80:2no-package-varpackage variables introduce mutable global state

binding/binding.go:80:2

79 Form Binding = formBinding{}
80 Query Binding = queryBinding{}
81 FormPost Binding = formPostBinding{}

binding/multipart_form_mapping.go1

52:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

binding/multipart_form_mapping.go:52:6

51 isSet, err = setArrayOfMultipartFormFiles(slice, field, files)
52 if err != nil || !isSet {
53 return isSet, err

binding/default_validator.go1

5:9package-commentspackage should have a documentation comment

binding/default_validator.go:5:9

4
5package binding
6

recovery_test.go1

119:28range-value-addresstaking the address of range value errno can be misleading

recovery_test.go:119:28

118 // Oops. Client connection closed
119 e := &net.OpError{Err: &os.SyscallError{Err: errno}}
120 panic(e)

binding/binding_test.go1

969:18redundant-conversionconversion from int64 to the identical type is redundant

binding/binding_test.go:969:18

968 assert.Equal(t, "Asia/Chongqing", obj.TimeFoo.Location().String())
969 assert.Equal(t, int64(-62135596800), obj.TimeBar.Unix())
970 assert.Equal(t, "UTC", obj.TimeBar.Location().String())

binding/form_mapping.go1

192:2single-case-switchswitch with one case can be replaced by an if statement

binding/form_mapping.go:192:2

191func trySetCustom(val string, value reflect.Value) (isSet bool, err error) {
192 switch v := value.Addr().Interface().(type) {
193 case BindUnmarshaler:

auth_test.go1

84:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:84:6

83
84func TestBasicAuthSucceed(t *testing.T) {
85 accounts := Accounts{"admin": "password"}

binding/form_mapping.go1

44:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/form_mapping.go:44:1

43
44var emptyField = reflect.StructField{}
45

auth_test.go1

165:54unchecked-type-assertionuse the checked two-result form of the type assertion

auth_test.go:165:54

164 called = true
165 c.String(http.StatusOK, c.MustGet(AuthProxyUserKey).(string))
166 })

gin_test.go1

134:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:134:14

133
134 res, err := http.Get(ts.URL + "/test")
135 if err != nil {

binding/binding_test.go2

1176:51unused-parameterparameter badPath is unused

binding/binding_test.go:1176:51

1175
1176func testQueryBinding(t *testing.T, method, path, badPath, body, badBody string) {
1177 b := Query
1368:7unused-receiverreceiver f is unused

binding/binding_test.go:1368:7

1367
1368func (f *failRead) Read(b []byte) (n int, err error) {
1369 return 0, errors.New("my fail")

auth_test.go1

133:17add-constantstring literal "Authorization" appears more than twice; define a constant

auth_test.go:133:17

132 req, _ := http.NewRequest(http.MethodGet, "/login", nil)
133 req.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))
134 router.ServeHTTP(w, req)

binding/form_mapping.go1

434:6cognitive-complexityfunction has cognitive complexity 12; maximum is 7

binding/form_mapping.go:434:6

433
434func setTimeField(val string, structField reflect.StructField, value reflect.Value) error {
435 timeFormat := structField.Tag.Get("time_format")

routes_test.go1

133:6confusing-namingname TestRouteNotOK2 differs from testRouteNotOK2 only by capitalization

routes_test.go:133:6

132
133func TestRouteNotOK2(t *testing.T) {
134 testRouteNotOK2(http.MethodGet, t)

binding/multipart_form_mapping.go1

35:6cyclomatic-complexityfunction complexity is 11; maximum is 10

binding/multipart_form_mapping.go:35:6

34
35func setByMultipartFormFile(value reflect.Value, field reflect.StructField, files []*multipart.FileHeader) (isSet bool, err error) {
36 switch value.Kind() {

binding/binding_test.go1

183:12discarded-error-resulterror result returned by http.NewRequest is discarded

binding/binding_test.go:183:12

182 var obj FooStruct
183 req, _ := http.NewRequest(http.MethodPost, "/", nil)
184 err := JSON.Bind(req, &obj)

binding/form_mapping_test.go1

1019:1doc-comment-perioddocumentation comment should end with punctuation

binding/form_mapping_test.go:1019:1

1018
1019// If someone does not specify parser=TextUnmarshaler even when it's defined for the type, gin should ignore the
1020// UnmarshalText logic and continue using its default binding logic. (This ensures gin does not break backwards

tree_test.go1

779:13error-stringserror string should not be capitalized or end with punctuation

tree_test.go:779:13

778 if !found {
779 t.Errorf("Route '%s' not found!", route)
780 } else if string(out) != route {

benchmarks_test.go1

146:22exported-declaration-commentexported function or method should have a comment beginning with its name

benchmarks_test.go:146:22

145
146func (m *mockWriter) WriteHeader(int) {}
147

gin.go1

1:1file-length-limitfile has 833 lines; maximum is 500

gin.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

utils.go1

85:14flag-parameterboolean parameter guard controls function flow

utils.go:85:14

84
85func assert1(guard bool, text string) {
86 if !guard {

binding/binding_test.go1

1:1formatfile is not formatted

binding/binding_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/binding_test.go`

context_test.go1

2596:6function-lengthfunction has 24 statements and 78 lines; maximum is 50 statements or 75 lines

context_test.go:2596:6

2595
2596func TestContextShouldBindBodyWith(t *testing.T) {
2597 type typeA struct {

gin.go1

397:14import-shadowingidentifier path shadows an imported package

gin.go:397:14

396
397func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
398 path += root.path

context_test.go1

1687:31insecure-url-schemeURL uses insecure http scheme

context_test.go:1687:31

1686 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", nil)
1687 c.Redirect(http.StatusFound, "http://google.com")
1688 c.Writer.WriteHeaderNow()

tree.go1

506:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:506:7

505
506 if value.params == nil {
507 value.params = params

binding/binding_test.go1

86:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:86:6

85
86type FooStructForTimeTypeNotFormat struct {
87 TimeFoo time.Time `form:"time_foo"`

binding/form_mapping.go1

333:3modifies-parameterassignment modifies parameter val

binding/form_mapping.go:333:3

332 if value.Kind() != reflect.String {
333 val = strings.TrimSpace(val)
334 }

binding/binding_test.go1

1130:4nested-structsmove nested anonymous struct types to named declarations

binding/binding_test.go:1130:4

1129 assert.Equal(t,
1130 struct {
1131 Idx int "form:\"idx\""

context_appengine.go1

9:6no-initreplace init with explicit initialization

context_appengine.go:9:6

8
9func init() {
10 defaultPlatform = PlatformGoogleAppEngine

context.go1

593:2no-naked-returnreturn values must be explicit

context.go:593:2

592 values, ok = c.queryCache[key]
593 return
594}

binding/binding.go1

81:2no-package-varpackage variables introduce mutable global state

binding/binding.go:81:2

80 Query Binding = queryBinding{}
81 FormPost Binding = formPostBinding{}
82 FormMultipart Binding = formMultipartBinding{}

binding/multipart_form_mapping.go1

69:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

binding/multipart_form_mapping.go:69:6

68 set, err := setByMultipartFormFile(value.Index(i), field, files[i:i+1])
69 if err != nil || !set {
70 return set, err

binding/form.go1

5:9package-commentspackage should have a documentation comment

binding/form.go:5:9

4
5package binding
6

binding/binding_test.go1

971:18redundant-conversionconversion from int64 to the identical type is redundant

binding/binding_test.go:971:18

970 assert.Equal(t, "UTC", obj.TimeBar.Location().String())
971 assert.Equal(t, int64(1562400033000000123), obj.CreateTime.UnixNano())
972 assert.Equal(t, int64(1562400033), obj.UnixTime.Unix())

binding/form_mapping.go1

202:2single-case-switchswitch with one case can be replaced by an if statement

binding/form_mapping.go:202:2

201func trySetUsingParser(val string, value reflect.Value, parser string) (isSet bool, err error) {
202 switch parser {
203 case "encoding.TextUnmarshaler":

auth_test.go1

101:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:101:6

100
101func TestBasicAuth401(t *testing.T) {
102 called := false

binding/form_mapping_benchmark_test.go1

51:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/form_mapping_benchmark_test.go:51:1

50
51type structName struct {
52 Name string `form:"name"`

binding/binding_test.go1

648:51unchecked-type-assertionuse the checked two-result form of the type assertion

binding/binding_test.go:648:51

647 require.NoError(t, err)
648 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
649}

gin_test.go1

154:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:154:14

153
154 res, err := http.Get(ts.URL + "/test")
155 if err != nil {

binding/binding_test.go2

1176:66unused-parameterparameter badBody is unused

binding/binding_test.go:1176:66

1175
1176func testQueryBinding(t *testing.T, method, path, badPath, body, badBody string) {
1177 b := Query
1372:7unused-receiverreceiver f is unused

binding/binding_test.go:1372:7

1371
1372func (f *failRead) Close() error {
1373 return nil

auth_test.go1

170:40add-constantstring literal "Basic " appears more than twice; define a constant

auth_test.go:170:40

169 req, _ := http.NewRequest(http.MethodGet, "/test", nil)
170 req.Header.Set("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))
171 router.ServeHTTP(w, req)

context.go2

684:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

context.go:684:6

683// It parses from data with bracket notation like "key[subkey]=value" into a map.
684func getMapFromFormData(m map[string][]string, key string) (map[string]string, bool) {
685 d := make(map[string]string)
998:19cyclomatic-complexityfunction complexity is 14; maximum is 10

context.go:998:19

997// the remote IP (coming from Request.RemoteAddr) is returned.
998func (c *Context) ClientIP() string {
999 // Check if we're running on a trusted platform, continue running backwards if error

binding/binding_test.go1

665:10discarded-error-resulterror result returned by os.Open is discarded

binding/binding_test.go:665:10

664 // file from os
665 f, _ := os.Open("form.go")
666 defer f.Close()

binding/multipart_form_mapping.go1

19:2doc-comment-perioddocumentation comment should end with punctuation

binding/multipart_form_mapping.go:19:2

18var (
19 // ErrMultiFileHeader multipart.FileHeader invalid
20 ErrMultiFileHeader = errors.New("unsupported field type for multipart.FileHeader")

tree_test.go1

781:13error-stringserror string should not be capitalized or end with punctuation

tree_test.go:781:13

780 } else if string(out) != route {
781 t.Errorf("Wrong result for route '%s': %s", route, string(out))
782 }

binding/binding.go1

13:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:13:2

12const (
13 MIMEJSON = "application/json"
14 MIMEHTML = "text/html"

gin_integration_test.go1

1:1file-length-limitfile has 608 lines; maximum is 500

gin_integration_test.go:1:1

1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

binding/default_validator.go1

1:1formatfile is not formatted

binding/default_validator.go:1:1

1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/default_validator.go`

context_test.go1

3599:6function-lengthfunction has 57 statements and 143 lines; maximum is 50 statements or 75 lines

context_test.go:3599:6

3598
3599func TestContextSetCookieData(t *testing.T) {
3600 c, _ := CreateTestContext(httptest.NewRecorder())

gin_test.go1

32:48import-shadowingidentifier tls shadows an imported package

gin_test.go:32:48

31
32func setupHTMLFiles(t *testing.T, mode string, tls bool, loadMethod func(*Engine)) *httptest.Server {
33 SetMode(mode)

context_test.go1

1691:18insecure-url-schemeURL uses insecure http scheme

context_test.go:1691:18

1690 assert.Equal(t, http.StatusFound, w.Code)
1691 assert.Equal(t, "http://google.com", w.Header().Get("Location"))
1692}

tree.go1

513:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:513:7

512 val := path[:end]
513 if unescape {
514 if v, err := url.QueryUnescape(val); err == nil {

binding/binding_test.go1

90:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:90:6

89
90type FooStructForTimeTypeFailFormat struct {
91 TimeFoo time.Time `form:"time_foo" time_format:"2017-11-15"`

binding/form_mapping.go1

392:3modifies-parameterassignment modifies parameter val

binding/form_mapping.go:392:3

391 if val == "" {
392 val = "0"
393 }

binding/binding_test.go1

1139:4nested-structsmove nested anonymous struct types to named declarations

binding/binding_test.go:1139:4

1138 assert.Equal(t,
1139 struct {
1140 Name string "form:\"name\""

ginS/gins_test.go1

17:6no-initreplace init with explicit initialization

ginS/gins_test.go:17:6

16
17func init() {
18 gin.SetMode(gin.TestMode)

context.go1

599:2no-naked-returnreturn values must be explicit

context.go:599:2

598 dicts, _ = c.GetQueryMap(key)
599 return
600}

binding/binding.go1

82:2no-package-varpackage variables introduce mutable global state

binding/binding.go:82:2

81 FormPost Binding = formPostBinding{}
82 FormMultipart Binding = formMultipartBinding{}
83 ProtoBuf BindingBody = protobufBinding{}

context.go1

1066:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

context.go:1066:5

1065func (c *Context) IsWebsocket() bool {
1066 if strings.Contains(strings.ToLower(c.requestHeader("Connection")), "upgrade") &&
1067 strings.EqualFold(c.requestHeader("Upgrade"), "websocket") {

binding/form_mapping.go1

5:9package-commentspackage should have a documentation comment

binding/form_mapping.go:5:9

4
5package binding
6

binding/binding_test.go1

972:18redundant-conversionconversion from int64 to the identical type is redundant

binding/binding_test.go:972:18

971 assert.Equal(t, int64(1562400033000000123), obj.CreateTime.UnixNano())
972 assert.Equal(t, int64(1562400033), obj.UnixTime.Unix())
973 assert.Equal(t, int64(1562400033001), obj.UnixMilliTime.UnixMilli())

binding/form_mapping.go1

220:2single-case-switchswitch with one case can be replaced by an if statement

binding/form_mapping.go:220:2

219 var sep string
220 switch cfTag {
221 case "csv":

auth_test.go1

121:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:121:6

120
121func TestBasicAuth401WithCustomRealm(t *testing.T) {
122 called := false

binding/form_mapping_test.go1

230:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/form_mapping_test.go:230:1

229
230type bindTestData struct {
231 need any

binding/binding_test.go1

702:51unchecked-type-assertionuse the checked two-result form of the type assertion

binding/binding_test.go:702:51

701 require.NoError(t, err)
702 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
703 assert.Equal(t, "thinkerou", obj.MapFoo["name"].(string))

gin_test.go1

181:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:181:14

180 client := &http.Client{Transport: tr}
181 res, err := client.Get(ts.URL + "/test")
182 if err != nil {

binding/binding_test.go1

1191:55unused-parameterparameter badPath is unused

binding/binding_test.go:1191:55

1190
1191func testQueryBindingFail(t *testing.T, method, path, badPath, body, badBody string) {
1192 b := Query

binding/form_mapping_test.go1

1039:7unused-receiverreceiver f is unused

binding/form_mapping_test.go:1039:7

1038
1039func (f *customHexUnmarshalParamAndUnmarshalText) UnmarshalParam(param string) error {
1040 return errors.New("should not be called in unit test if parser tag present")

auth_test.go1

170:90add-constantstring literal "admin:password" appears more than twice; define a constant

auth_test.go:170:90

169 req, _ := http.NewRequest(http.MethodGet, "/test", nil)
170 req.Header.Set("Proxy-Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte("admin:password")))
171 router.ServeHTTP(w, req)

context.go2

998:19cognitive-complexityfunction has cognitive complexity 16; maximum is 7

context.go:998:19

997// the remote IP (coming from Request.RemoteAddr) is returned.
998func (c *Context) ClientIP() string {
999 // Check if we're running on a trusted platform, continue running backwards if error
1450:19cyclomatic-complexityfunction complexity is 11; maximum is 10

context.go:1450:19

1449// NegotiateFormat returns an acceptable Accept format.
1450func (c *Context) NegotiateFormat(offered ...string) string {
1451 assert1(len(offered) > 0, "you must provide at least one offer")

binding/binding_test.go1

667:19discarded-error-resulterror result returned by io.ReadAll is discarded

binding/binding_test.go:667:19

666 defer f.Close()
667 fileActual, _ := io.ReadAll(f)
668

binding/multipart_form_mapping.go1

22:2doc-comment-perioddocumentation comment should end with punctuation

binding/multipart_form_mapping.go:22:2

21
22 // ErrMultiFileHeaderLenInvalid array for []*multipart.FileHeader len invalid
23 ErrMultiFileHeaderLenInvalid = errors.New("unsupported len of array for []*multipart.FileHeader")

tree_test.go1

852:13error-stringserror string should not be capitalized or end with punctuation

tree_test.go:852:13

851 if found != test.found || (found && (string(out) != test.out)) {
852 t.Errorf("Wrong result for '%s': got %s, %t; want %s, %t",
853 test.in, string(out), found, test.out, test.found)

binding/binding.go1

14:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:14:2

13 MIMEJSON = "application/json"
14 MIMEHTML = "text/html"
15 MIMEXML = "application/xml"

gin_test.go1

1:1file-length-limitfile has 1159 lines; maximum is 500

gin_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

binding/default_validator_test.go1

1:1formatfile is not formatted

binding/default_validator_test.go:1:1

1// Copyright 2020 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/default_validator_test.go`

context_test.go2

3743:6function-lengthfunction has 6 statements and 130 lines; maximum is 50 statements or 75 lines

context_test.go:3743:6

3742
3743func TestGetMapFromFormData(t *testing.T) {
3744 testCases := []struct {
1698:50insecure-url-schemeURL uses insecure http scheme

context_test.go:1698:50

1697
1698 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", nil)
1699 c.Redirect(http.StatusCreated, "/resource")

tree.go1

514:8max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:514:8

513 if unescape {
514 if v, err := url.QueryUnescape(val); err == nil {
515 val = v

binding/binding_test.go1

94:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:94:6

93
94type FooStructForTimeTypeFailLocation struct {
95 TimeFoo time.Time `form:"time_foo" time_format:"2006-01-02" time_location:"/asia/chongqing"`

binding/form_mapping.go1

403:3modifies-parameterassignment modifies parameter val

binding/form_mapping.go:403:3

402 if val == "" {
403 val = "0"
404 }

binding/default_validator_test.go1

13:13nested-structsmove nested anonymous struct types to named declarations

binding/default_validator_test.go:13:13

12func TestSliceValidationError(t *testing.T) {
13 tests := []struct {
14 name string

gin_test.go1

210:6no-initreplace init with explicit initialization

gin_test.go:210:6

209
210func init() {
211 SetMode(TestMode)

context.go1

613:2no-naked-returnreturn values must be explicit

context.go:613:2

612 value, _ = c.GetPostForm(key)
613 return
614}

binding/binding.go1

83:2no-package-varpackage variables introduce mutable global state

binding/binding.go:83:2

82 FormMultipart Binding = formMultipartBinding{}
83 ProtoBuf BindingBody = protobufBinding{}
84 MsgPack BindingBody = msgpackBinding{}

gin.go1

801:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

gin.go:801:6

800 return strings.Map(func(r rune) rune {
801 if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '/' || r == '-' {
802 return r

binding/header.go1

5:9package-commentspackage should have a documentation comment

binding/header.go:5:9

4
5package binding
6

binding/binding_test.go1

973:18redundant-conversionconversion from int64 to the identical type is redundant

binding/binding_test.go:973:18

972 assert.Equal(t, int64(1562400033), obj.UnixTime.Unix())
973 assert.Equal(t, int64(1562400033001), obj.UnixMilliTime.UnixMilli())
974 assert.Equal(t, int64(1562400033000012), obj.UnixMicroTime.UnixMicro())

binding/form_mapping.go1

251:2single-case-switchswitch with one case can be replaced by an if statement

binding/form_mapping.go:251:2

250
251 switch value.Kind() {
252 case reflect.Slice:

auth_test.go1

141:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:141:6

140
141func TestBasicAuthForProxySucceed(t *testing.T) {
142 accounts := Accounts{"admin": "password"}

binding/header.go1

31:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/header.go:31:1

30
31type headerSource map[string][]string
32

binding/binding_test.go1

703:49unchecked-type-assertionuse the checked two-result form of the type assertion

binding/binding_test.go:703:49

702 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
703 assert.Equal(t, "thinkerou", obj.MapFoo["name"].(string))
704 assert.InDelta(t, float64(3.14), obj.MapFoo["pai"].(float64), 0.01)

gin_test.go1

201:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:201:14

200
201 res, err := http.Get(ts.URL + "/raw")
202 if err != nil {

binding/binding_test.go1

1191:70unused-parameterparameter badBody is unused

binding/binding_test.go:1191:70

1190
1191func testQueryBindingFail(t *testing.T, method, path, badPath, body, badBody string) {
1192 b := Query

binding/json_test.go1

85:7unused-receiverreceiver j is unused

binding/json_test.go:85:7

84
85func (j customJsonApi) Marshal(v any) ([]byte, error) {
86 return customConfig.Marshal(v)

benchmarks_test.go1

30:13add-constantstring literal "/" appears more than twice; define a constant

benchmarks_test.go:30:13

29 router.Use(LoggerWithWriter(newMockWriter()))
30 router.GET("/", func(c *Context) {})
31 runRequest(B, router, http.MethodGet, "/")

context.go1

1450:19cognitive-complexityfunction has cognitive complexity 20; maximum is 7

context.go:1450:19

1449// NegotiateFormat returns an acceptable Accept format.
1450func (c *Context) NegotiateFormat(offered ...string) string {
1451 assert1(len(offered) > 0, "you must provide at least one offer")

gin.go1

690:23cyclomatic-complexityfunction complexity is 21; maximum is 10

gin.go:690:23

689
690func (engine *Engine) handleHTTPRequest(c *Context) {
691 httpMethod := c.Request.Method

binding/binding_test.go1

670:11discarded-error-resulterror result returned by obj.File.Open is discarded

binding/binding_test.go:670:11

669 // file from multipart
670 mf, _ := obj.File.Open()
671 defer mf.Close()

binding/multipart_form_mapping.go1

26:1doc-comment-perioddocumentation comment should end with punctuation

binding/multipart_form_mapping.go:26:1

25
26// TrySet tries to set a value by the multipart request with the binding a form file
27func (r *multipartRequest) TrySet(value reflect.Value, field reflect.StructField, key string, opt setOptions) (bool, error) {

tree_test.go1

862:14error-stringserror string should not be capitalized or end with punctuation

tree_test.go:862:14

861 if found { // test needs a trailingSlash fix. It must not be found!
862 t.Errorf("Found without fixTrailingSlash: %s; got %s", test.in, string(out))
863 }

binding/binding.go1

15:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:15:2

14 MIMEHTML = "text/html"
15 MIMEXML = "application/xml"
16 MIMEXML2 = "text/xml"

render/render_test.go1

1:1file-length-limitfile has 808 lines; maximum is 500

render/render_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

binding/form_mapping.go1

1:1formatfile is not formatted

binding/form_mapping.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/form_mapping.go`

context_test.go2

3874:6function-lengthfunction has 25 statements and 84 lines; maximum is 50 statements or 75 lines

context_test.go:3874:6

3873
3874func BenchmarkGetMapFromFormData(b *testing.B) {
3875 // Test case 1: Small dataset with bracket notation
1708:50insecure-url-schemeURL uses insecure http scheme

context_test.go:1708:50

1707 c, _ := CreateTestContext(httptest.NewRecorder())
1708 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", nil)
1709 assert.Panics(t, func() { c.Redirect(http.StatusOK, "/resource") })

tree.go1

526:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:526:7

525 if end < len(path) {
526 if len(n.children) > 0 {
527 path = path[end:]

binding/binding_test.go1

98:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:98:6

97
98type FooStructForMapType struct {
99 MapFoo map[string]any `form:"map_foo"`

binding/form_mapping.go1

414:3modifies-parameterassignment modifies parameter val

binding/form_mapping.go:414:3

413 if val == "" {
414 val = "false"
415 }

binding/default_validator_test.go1

56:13nested-structsmove nested anonymous struct types to named declarations

binding/default_validator_test.go:56:13

55 }
56 tests := []struct {
57 name string

logger_test.go1

18:6no-initreplace init with explicit initialization

logger_test.go:18:6

17
18func init() {
19 SetMode(TestMode)

context.go1

645:2no-naked-returnreturn values must be explicit

context.go:645:2

644 values, _ = c.GetPostFormArray(key)
645 return
646}

binding/binding.go1

84:2no-package-varpackage variables introduce mutable global state

binding/binding.go:84:2

83 ProtoBuf BindingBody = protobufBinding{}
84 MsgPack BindingBody = msgpackBinding{}
85 YAML BindingBody = yamlBinding{}

gin.go1

801:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

gin.go:801:6

800 return strings.Map(func(r rune) rune {
801 if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '/' || r == '-' {
802 return r

binding/json.go1

5:9package-commentspackage should have a documentation comment

binding/json.go:5:9

4
5package binding
6

binding/binding_test.go1

974:18redundant-conversionconversion from int64 to the identical type is redundant

binding/binding_test.go:974:18

973 assert.Equal(t, int64(1562400033001), obj.UnixMilliTime.UnixMilli())
974 assert.Equal(t, int64(1562400033000012), obj.UnixMicroTime.UnixMicro())
975

binding/form_mapping.go1

336:2single-case-switchswitch with one case can be replaced by an if statement

binding/form_mapping.go:336:2

335
336 switch value.Kind() {
337 case reflect.Int:

auth_test.go1

158:6test-parallelismconsider calling t.Parallel() when this test begins

auth_test.go:158:6

157
158func TestBasicAuthForProxy407(t *testing.T) {
159 called := false

binding/json_test.go1

65:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/json_test.go:65:1

64
65type customReq struct {
66 TimeEmpty time.Time `json:"time_empty"`

binding/binding_test.go1

704:52unchecked-type-assertionuse the checked two-result form of the type assertion

binding/binding_test.go:704:52

703 assert.Equal(t, "thinkerou", obj.MapFoo["name"].(string))
704 assert.InDelta(t, float64(3.14), obj.MapFoo["pai"].(float64), 0.01)
705}

gin_test.go1

232:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:232:14

231
232 res, err := http.Get(ts.URL + "/test")
233 if err != nil {

binding/binding_test.go1

1204:59unused-parameterparameter badPath is unused

binding/binding_test.go:1204:59

1203
1204func testQueryBindingBoolFail(t *testing.T, method, path, badPath, body, badBody string) {
1205 b := Query

binding/json_test.go1

89:7unused-receiverreceiver j is unused

binding/json_test.go:89:7

88
89func (j customJsonApi) Unmarshal(data []byte, v any) error {
90 return customConfig.Unmarshal(data, v)

benchmarks_test.go1

39:13add-constantstring literal "/ping" appears more than twice; define a constant

benchmarks_test.go:39:13

38 router.Use(func(c *Context) {})
39 router.GET("/ping", func(c *Context) {})
40 runRequest(B, router, http.MethodGet, "/ping")

context_test.go1

2675:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

context_test.go:2675:6

2674
2675func TestContextShouldBindBodyWithJSON(t *testing.T) {
2676 for _, tt := range []struct {

logger.go1

245:6cyclomatic-complexityfunction complexity is 14; maximum is 10

logger.go:245:6

244// LoggerWithConfig instance a Logger middleware with config.
245func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
246 formatter := conf.Formatter

binding/binding_test.go1

672:19discarded-error-resulterror result returned by io.ReadAll is discarded

binding/binding_test.go:672:19

671 defer mf.Close()
672 fileExpect, _ := io.ReadAll(mf)
673

context.go1

163:1doc-comment-perioddocumentation comment should end with punctuation

context.go:163:1

162
163// HandlerNames returns a list of all registered handlers for this context in descending order,
164// following the semantics of HandlerName()

tree_test.go1

866:14error-stringserror string should not be capitalized or end with punctuation

tree_test.go:866:14

865 if found != test.found || (found && (string(out) != test.out)) {
866 t.Errorf("Wrong result for '%s': got %s, %t; want %s, %t",
867 test.in, string(out), found, test.out, test.found)

binding/binding.go1

16:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:16:2

15 MIMEXML = "application/xml"
16 MIMEXML2 = "text/xml"
17 MIMEPlain = "text/plain"

routes_test.go1

1:1file-length-limitfile has 792 lines; maximum is 500

routes_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style

binding/form_mapping_benchmark_test.go1

1:1formatfile is not formatted

binding/form_mapping_benchmark_test.go:1:1

1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/form_mapping_benchmark_test.go`

gin_integration_test.go1

434:6function-lengthfunction has 177 statements and 145 lines; maximum is 50 statements or 75 lines

gin_integration_test.go:434:6

433
434func TestTreeRunDynamicRouting(t *testing.T) {
435 router := New()

context_test.go1

2407:50insecure-url-schemeURL uses insecure http scheme

context_test.go:2407:50

2406
2407 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", strings.NewReader("\"foo\":\"bar\", \"bar\":\"foo\"}"))
2408 c.Request.Header.Add("Content-Type", MIMEJSON)

tree.go1

553:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:553:7

552 // Preallocate capacity if necessary
553 if cap(*params) < int(globalParamsCount) {
554 newParams := make(Params, len(*params), globalParamsCount)

binding/binding_test.go1

102:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:102:6

101
102type FooStructForIgnoreFormTag struct {
103 Foo *string `form:"-"`

binding/form_mapping.go1

425:3modifies-parameterassignment modifies parameter val

binding/form_mapping.go:425:3

424 if val == "" {
425 val = "0.0"
426 }

binding/form_mapping_benchmark_test.go1

25:11nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_benchmark_test.go:25:11

24 Friends []string `form:"friends"`
25 ID *struct {
26 Number string `form:"id_number"`

mode.go1

52:6no-initreplace init with explicit initialization

mode.go:52:6

51
52func init() {
53 mode := os.Getenv(EnvGinMode)

context.go1

666:2no-naked-returnreturn values must be explicit

context.go:666:2

665 values, ok = c.formCache[key]
666 return
667}

binding/binding.go1

85:2no-package-varpackage variables introduce mutable global state

binding/binding.go:85:2

84 MsgPack BindingBody = msgpackBinding{}
85 YAML BindingBody = yamlBinding{}
86 Uri BindingUri = uriBinding{}

gin.go1

801:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

gin.go:801:6

800 return strings.Map(func(r rune) rune {
801 if (r >= 'a' && r <= 'z') || (r >= 'A' && r <= 'Z') || (r >= '0' && r <= '9') || r == '/' || r == '-' {
802 return r

binding/msgpack.go1

7:9package-commentspackage should have a documentation comment

binding/msgpack.go:7:9

6
7package binding
8

binding/binding_test.go1

1147:21redundant-conversionconversion from float64 to the identical type is redundant

binding/binding_test.go:1147:21

1146 require.NoError(t, err)
1147 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
1148 case "SliceMap":

binding/form_mapping.go1

346:3single-case-switchswitch with one case can be replaced by an if statement

binding/form_mapping.go:346:3

345 case reflect.Int64:
346 switch value.Interface().(type) {
347 case time.Duration:

binding/binding_msgpack_test.go1

19:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_msgpack_test.go:19:6

18
19func TestBindingMsgPack(t *testing.T) {
20 test := FooStruct{

binding/multipart_form_mapping.go1

16:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/multipart_form_mapping.go:16:1

15
16var _ setter = (*multipartRequest)(nil)
17

binding/binding_test.go1

1147:52unchecked-type-assertionuse the checked two-result form of the type assertion

binding/binding_test.go:1147:52

1146 require.NoError(t, err)
1147 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
1148 case "SliceMap":

gin_test.go1

252:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:252:14

251
252 res, err := http.Get(ts.URL + "/test")
253 if err != nil {

binding/binding_test.go1

1204:74unused-parameterparameter badBody is unused

binding/binding_test.go:1204:74

1203
1204func testQueryBindingBoolFail(t *testing.T, method, path, badPath, body, badBody string) {
1205 b := Query

binding/json_test.go1

93:7unused-receiverreceiver j is unused

binding/json_test.go:93:7

92
93func (j customJsonApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {
94 return customConfig.MarshalIndent(v, prefix, indent)

binding/binding_test.go1

191:8add-constantstring literal "/" appears more than twice; define a constant

binding/binding_test.go:191:8

190 JSON, "json",
191 "/", "/",
192 `{"foo": "bar"}`, `{"bar": "foo"}`)

context_test.go1

2739:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

context_test.go:2739:6

2738
2739func TestContextShouldBindBodyWithXML(t *testing.T) {
2740 for _, tt := range []struct {

path.go1

23:6cyclomatic-complexityfunction complexity is 27; maximum is 10

path.go:23:6

22// If the result of this process is an empty string, "/" is returned.
23func cleanPath(p string) string {
24 // Turn empty string into "/"

binding/binding_test.go1

718:13discarded-error-resulterror result returned by proto.Marshal is discarded

binding/binding_test.go:718:13

717 }
718 data, _ := proto.Marshal(test)
719

context.go1

181:1doc-comment-perioddocumentation comment should end with punctuation

context.go:181:1

180
181// FullPath returns a matched route full path. For not found routes
182// returns an empty string.

tree_test.go1

930:13error-stringserror string should not be capitalized or end with punctuation

tree_test.go:930:13

929 if value.params == nil {
930 t.Errorf("Expected %s params to be set, but they weren't", item.path)
931 continue

binding/binding.go1

17:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:17:2

16 MIMEXML2 = "text/xml"
17 MIMEPlain = "text/plain"
18 MIMEPOSTForm = "application/x-www-form-urlencoded"

tree.go1

1:1file-length-limitfile has 951 lines; maximum is 500

tree.go:1:1

1// Copyright 2013 Julien Schmidt. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be found

binding/form_mapping_test.go1

1:1formatfile is not formatted

binding/form_mapping_test.go:1:1

1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/form_mapping_test.go`

gin_test.go1

867:6function-lengthfunction has 45 statements and 104 lines; maximum is 50 statements or 75 lines

gin_test.go:867:6

866
867func TestPrepareTrustedCIRDsWith(t *testing.T) {
868 r := New()

context_test.go1

2581:50insecure-url-schemeURL uses insecure http scheme

context_test.go:2581:50

2580
2581 c.Request, _ = http.NewRequest(http.MethodPost, "http://example.com", strings.NewReader(`"foo":"bar", "bar":"foo"}`))
2582 c.Request.Header.Add("Content-Type", MIMEJSON)

tree.go1

559:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:559:7

558
559 if value.params == nil {
560 value.params = params

binding/binding_test.go1

106:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:106:6

105
106type InvalidNameType struct {
107 TestName string `invalid_name:"test_name"`

binding/form_mapping.go1

512:3modifies-parameterassignment modifies parameter val

binding/form_mapping.go:512:3

511 if val == "" {
512 val = "0"
513 }

binding/form_mapping_test.go1

26:23nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:26:23

25 }
26 for _, tt := range []struct {
27 name string

mode_test.go1

16:6no-initreplace init with explicit initialization

mode_test.go:16:6

15
16func init() {
17 os.Setenv(EnvGinMode, TestMode)

context.go1

672:2no-naked-returnreturn values must be explicit

context.go:672:2

671 dicts, _ = c.GetPostFormMap(key)
672 return
673}

binding/binding.go1

86:2no-package-varpackage variables introduce mutable global state

binding/binding.go:86:2

85 YAML BindingBody = yamlBinding{}
86 Uri BindingUri = uriBinding{}
87 Header Binding = headerBinding{}

gin_integration_test.go1

51:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

gin_integration_test.go:51:5

50 responseStatus := "200 OK"
51 if len(params) > 1 && params[1] != "" {
52 responseStatus = params[1]

binding/multipart_form_mapping.go1

5:9package-commentspackage should have a documentation comment

binding/multipart_form_mapping.go:5:9

4
5package binding
6

binding/binding_test.go1

1283:18redundant-conversionconversion from int64 to the identical type is redundant

binding/binding_test.go:1283:18

1282 require.NoError(t, e)
1283 assert.Equal(t, int64(123), v)
1284

binding/form_mapping.go1

453:3single-case-switchswitch with one case can be replaced by an if statement

binding/form_mapping.go:453:3

452 var t time.Time
453 switch tf {
454 case "unix":

binding/binding_msgpack_test.go1

56:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_msgpack_test.go:56:6

55
56func TestBindingDefaultMsgPack(t *testing.T) {
57 assert.Equal(t, MsgPack, Default(http.MethodPost, MIMEMSGPACK))

binding/multipart_form_mapping_test.go1

98:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/multipart_form_mapping_test.go:98:1

97
98type testFile struct {
99 Fieldname string

binding/binding_test.go1

1281:17unchecked-type-assertionuse the checked two-result form of the type assertion

binding/binding_test.go:1281:17

1280 // we hope it is int64(123)
1281 v, e := obj.Foo.(json.Number).Int64()
1282 require.NoError(t, e)

gin_test.go1

272:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:272:14

271
272 res, err := http.Get(ts.URL + "/test")
273 if err != nil {

binding/binding_test.go1

1368:25unused-parameterparameter b is unused

binding/binding_test.go:1368:25

1367
1368func (f *failRead) Read(b []byte) (n int, err error) {
1369 return 0, errors.New("my fail")

binding/json_test.go1

97:7unused-receiverreceiver j is unused

binding/json_test.go:97:7

96
97func (j customJsonApi) NewEncoder(writer io.Writer) json.Encoder {
98 return customConfig.NewEncoder(writer)

binding/binding_test.go1

202:32add-constantstring literal "json" appears more than twice; define a constant

binding/binding_test.go:202:32

201 testBodyBindingSlice(t, JSON, "json", "/", "/", `[]`, ``)
202 testBodyBindingSlice(t, JSON, "json", "/", "/", `[{"foo": "123"}]`, `[{}]`)
203 testBodyBindingSlice(t, JSON, "json", "/", "/", `[{"foo": "123"}]`, `[{"foo": ""}]`)

context_test.go1

2803:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

context_test.go:2803:6

2802
2803func TestContextShouldBindBodyWithYAML(t *testing.T) {
2804 for _, tt := range []struct {

tree.go1

135:16cyclomatic-complexityfunction complexity is 22; maximum is 10

tree.go:135:16

134// Not concurrency-safe!
135func (n *node) addRoute(path string, handlers HandlersChain) {
136 fullPath := path

binding/binding_test.go1

730:13discarded-error-resulterror result returned by proto.Marshal is discarded

binding/binding_test.go:730:13

729 }
730 data, _ := proto.Marshal(test)
731

context.go1

296:1doc-comment-perioddocumentation comment should end with punctuation

context.go:296:1

295
296// Get returns the value for the given key, ie: (value, true).
297// If the value does not exist it returns (nil, false)

tree_test.go1

935:13error-stringserror string should not be capitalized or end with punctuation

tree_test.go:935:13

934 if len(*value.params) != 1 {
935 t.Errorf("Wrong number of %s params: got %d, want %d",
936 item.path, len(*value.params), 1)

binding/binding.go1

18:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:18:2

17 MIMEPlain = "text/plain"
18 MIMEPOSTForm = "application/x-www-form-urlencoded"
19 MIMEMultipartPOSTForm = "multipart/form-data"

tree_test.go1

1:1file-length-limitfile has 1114 lines; maximum is 500

tree_test.go:1:1

1// Copyright 2013 Julien Schmidt. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be found

binding/header.go1

1:1formatfile is not formatted

binding/header.go:1:1

1// Copyright 2022 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/header.go`

path.go1

23:6function-lengthfunction has 40 statements and 102 lines; maximum is 50 statements or 75 lines

path.go:23:6

22// If the result of this process is an empty string, "/" is returned.
23func cleanPath(p string) string {
24 // Turn empty string into "/"

context_test.go1

2645:22insecure-url-schemeURL uses insecure http scheme

context_test.go:2645:22

2644 c.Request, _ = http.NewRequest(
2645 http.MethodPost, "http://example.com", strings.NewReader(tt.bodyA),
2646 )

tree.go1

566:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:566:7

565 val := path
566 if unescape {
567 if v, err := url.QueryUnescape(path); err == nil {

binding/binding_test.go1

110:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:110:6

109
110type InvalidNameMapType struct {
111 TestName struct {

context.go1

1161:3modifies-parameterassignment modifies parameter path

context.go:1161:3

1160 if path == "" {
1161 path = "/"
1162 }

binding/form_mapping_test.go1

32:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:32:17

31 }{
32 {"base type", struct{ F int }{}, "9", int(9)},
33 {"base type", struct{ F int8 }{}, "9", int8(9)},

response_writer_test.go1

55:6no-initreplace init with explicit initialization

response_writer_test.go:55:6

54
55func init() {
56 SetMode(TestMode)

context.go1

1499:3no-naked-returnreturn values must be explicit

context.go:1499:3

1498 if !c.hasRequestContext() {
1499 return
1500 }

binding/binding.go1

87:2no-package-varpackage variables introduce mutable global state

binding/binding.go:87:2

86 Uri BindingUri = uriBinding{}
87 Header Binding = headerBinding{}
88 Plain BindingBody = plainBinding{}

gin_integration_test.go1

56:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

gin_integration_test.go:56:5

55 responseBody := "it worked"
56 if len(params) > 2 && params[2] != "" {
57 responseBody = params[2]

binding/plain.go1

1:9package-commentspackage should have a documentation comment

binding/plain.go:1:9

1package binding
2

binding/binding_test.go1

1301:20redundant-conversionconversion from float64 to the identical type is redundant

binding/binding_test.go:1301:20

1300 // maybe it is not hoped
1301 assert.InDelta(t, float64(123), obj.Foo, 0.01)
1302

binding/multipart_form_mapping.go1

36:2single-case-switchswitch with one case can be replaced by an if statement

binding/multipart_form_mapping.go:36:2

35func setByMultipartFormFile(value reflect.Value, field reflect.StructField, files []*multipart.FileHeader) (isSet bool, err error) {
36 switch value.Kind() {
37 case reflect.Ptr:

binding/binding_test.go1

150:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:150:6

149
150func TestBindingDefault(t *testing.T) {
151 assert.Equal(t, Form, Default(http.MethodGet, ""))

binding/validate_test.go2

125:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

binding/validate_test.go:125:1

124
125type structNoValidationPointer struct {
126 substructNoValidation
201:27unchecked-type-assertionuse the checked two-result form of the type assertion

binding/validate_test.go:201:27

200func toZero(sl validator.StructLevel) {
201 s := sl.Top().Interface().(*structModifyValidation)
202 s.Integer = 0

gin_test.go1

299:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:299:14

298 client := &http.Client{Transport: tr}
299 res, err := client.Get(ts.URL + "/test")
300 if err != nil {

binding/form_mapping_test.go1

1039:66unused-parameterparameter param is unused

binding/form_mapping_test.go:1039:66

1038
1039func (f *customHexUnmarshalParamAndUnmarshalText) UnmarshalParam(param string) error {
1040 return errors.New("should not be called in unit test if parser tag present")

binding/json_test.go1

101:7unused-receiverreceiver j is unused

binding/json_test.go:101:7

100
101func (j customJsonApi) NewDecoder(reader io.Reader) json.Decoder {
102 return customConfig.NewDecoder(reader)

binding/binding_test.go1

204:50add-constantstring literal `[{"foo": "123"}]` appears more than twice; define a constant

binding/binding_test.go:204:50

203 testBodyBindingSlice(t, JSON, "json", "/", "/", `[{"foo": "123"}]`, `[{"foo": ""}]`)
204 testBodyBindingSlice(t, JSON, "json", "/", "/", `[{"foo": "123"}]`, `[{"foo": 123}]`)
205 testBodyBindingSlice(t, JSON, "json", "/", "/", `[{"foo": "123"}]`, `[{"bar": 123}]`)

context_test.go1

2868:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

context_test.go:2868:6

2867
2868func TestContextShouldBindBodyWithTOML(t *testing.T) {
2869 for _, tt := range []struct {

tree.go1

288:16cyclomatic-complexityfunction complexity is 14; maximum is 10

tree.go:288:16

287
288func (n *node) insertChild(path string, fullPath string, handlers HandlersChain) {
289 for {

binding/binding_test.go1

741:13discarded-error-resulterror result returned by bson.Marshal is discarded

binding/binding_test.go:741:13

740 obj.Foo = "bar"
741 data, _ := bson.Marshal(&obj)
742 testBodyBinding(t,

context.go1

490:1doc-comment-perioddocumentation comment should end with punctuation

context.go:490:1

489
490// Delete deletes the key from the Context's Key map, if it exists.
491// This operation is safe to be used by concurrent go-routines

tree_test.go1

1049:12error-stringserror string should not be capitalized or end with punctuation

tree_test.go:1049:12

1048 if found {
1049 t.Errorf("Expected no match for '/aa', but got: %s", string(out))
1050 }

binding/binding.go1

19:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:19:2

18 MIMEPOSTForm = "application/x-www-form-urlencoded"
19 MIMEMultipartPOSTForm = "multipart/form-data"
20 MIMEPROTOBUF = "application/x-protobuf"

binding/json_test.go1

1:1formatfile is not formatted

binding/json_test.go:1:1

1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/json_test.go`

routes_test.go1

145:6function-lengthfunction has 77 statements and 103 lines; maximum is 50 statements or 75 lines

routes_test.go:145:6

144
145func TestRouteRedirectTrailingSlash(t *testing.T) {
146 router := New()

context_test.go1

2663:22insecure-url-schemeURL uses insecure http scheme

context_test.go:2663:22

2662 c.Request, _ = http.NewRequest(
2663 http.MethodPost, "http://example.com", strings.NewReader(tt.bodyB),
2664 )

tree.go1

567:8max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:567:8

566 if unescape {
567 if v, err := url.QueryUnescape(path); err == nil {
568 val = v

binding/binding_test.go1

116:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:116:6

115
116type FooStructForSliceType struct {
117 SliceFoo []int `form:"slice_foo"`

context.go1

1180:3modifies-parameterassignment modifies parameter cookie

context.go:1180:3

1179 if cookie.Path == "" {
1180 cookie.Path = "/"
1181 }

binding/form_mapping_test.go1

33:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:33:17

32 {"base type", struct{ F int }{}, "9", int(9)},
33 {"base type", struct{ F int8 }{}, "9", int8(9)},
34 {"base type", struct{ F int16 }{}, "9", int16(9)},

routergroup_test.go1

16:6no-initreplace init with explicit initialization

routergroup_test.go:16:6

15
16func init() {
17 SetMode(TestMode)

gin.go1

555:2no-naked-returnreturn values must be explicit

gin.go:555:2

554 err = server.ListenAndServe()
555 return
556}

binding/binding.go1

88:2no-package-varpackage variables introduce mutable global state

binding/binding.go:88:2

87 Header Binding = headerBinding{}
88 Plain BindingBody = plainBinding{}
89 TOML BindingBody = tomlBinding{}

logger.go1

163:44optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

logger.go:163:44

162func (p *LogFormatterParams) IsOutputColor() bool {
163 return consoleColorMode == forceColor || (consoleColorMode == autoColor && p.isTerm)
164}

binding/protobuf.go1

5:9package-commentspackage should have a documentation comment

binding/protobuf.go:5:9

4
5package binding
6

binding/form_mapping_test.go1

32:41redundant-conversionconversion from int to the identical type is redundant

binding/form_mapping_test.go:32:41

31 }{
32 {"base type", struct{ F int }{}, "9", int(9)},
33 {"base type", struct{ F int8 }{}, "9", int8(9)},

binding/multipart_form_mapping.go1

38:3single-case-switchswitch with one case can be replaced by an if statement

binding/multipart_form_mapping.go:38:3

37 case reflect.Ptr:
38 switch value.Interface().(type) {
39 case *multipart.FileHeader:

binding/binding_test.go1

181:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:181:6

180
181func TestBindingJSONNilBody(t *testing.T) {
182 var obj FooStruct

codec/json/json.go1

21:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

codec/json/json.go:21:1

20
21type jsonApi struct{}
22

context_test.go1

341:26unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:341:26

340 assert.EqualValues(t, -1, c.index)
341 assert.Equal(t, c.Writer.(*responseWriter), &c.writermem)
342}

gin_test.go1

319:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:319:14

318
319 res, err := http.Get(ts.URL + "/raw")
320 if err != nil {

context_test.go1

798:22unused-parameterparameter c is unused

context_test.go:798:22

797
798func handlerNameTest(c *Context) {
799}

binding/json_test.go1

117:7unused-receiverreceiver te is unused

binding/json_test.go:117:7

116
117func (te *TimeEx) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder {
118 if typ == timeType {

binding/binding_test.go1

220:19add-constantstring literal `{"bar": "foo"}` appears more than twice; define a constant

binding/binding_test.go:220:19

219 "/", "/",
220 `{"foo": 123}`, `{"bar": "foo"}`)
221}

context_test.go1

2932:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

context_test.go:2932:6

2931
2932func TestContextShouldBindBodyWithPlain(t *testing.T) {
2933 for _, tt := range []struct {

tree.go1

418:16cyclomatic-complexityfunction complexity is 60; maximum is 10

tree.go:418:16

417// given path.
418func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
419 var globalParamsCount int16

binding/binding_test.go1

919:12discarded-error-resulterror result returned by http.NewRequest is discarded

binding/binding_test.go:919:12

918 obj := FooBarStruct{}
919 req, _ := http.NewRequest(http.MethodPost, "/", nil)
920 err := b.Bind(req, &obj)

context.go1

504:1doc-comment-perioddocumentation comment should end with punctuation

context.go:504:1

503
504// Param returns the value of the URL param.
505// It is a shortcut for c.Params.ByName(key)

tree_test.go1

1054:12error-stringserror string should not be capitalized or end with punctuation

tree_test.go:1054:12

1053 if found {
1054 t.Errorf("Expected no match for '/aa/aa/aa/aa', but got: %s", string(out))
1055 }

binding/binding.go1

20:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:20:2

19 MIMEMultipartPOSTForm = "multipart/form-data"
20 MIMEPROTOBUF = "application/x-protobuf"
21 MIMEMSGPACK = "application/x-msgpack"

binding/msgpack_test.go1

1:1formatfile is not formatted

binding/msgpack_test.go:1:1

1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/msgpack_test.go`

tree.go1

135:16function-lengthfunction has 53 statements and 115 lines; maximum is 50 statements or 75 lines

tree.go:135:16

134// Not concurrency-safe!
135func (n *node) addRoute(path string, handlers HandlersChain) {
136 fullPath := path

context_test.go1

3032:33insecure-url-schemeURL uses insecure http scheme

context_test.go:3032:33

3031 c.Request.Header.Set("Sec-WebSocket-Key", "dGhlIHNhbXBsZSBub25jZQ==")
3032 c.Request.Header.Set("Origin", "http://example.com")
3033 c.Request.Header.Set("Sec-WebSocket-Protocol", "chat, superchat")

tree.go1

597:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:597:7

596 n = skippedNode.node
597 if value.params != nil {
598 *value.params = (*value.params)[:skippedNode.paramsCount]

binding/binding_test.go1

120:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:120:6

119
120type FooStructForStructType struct {
121 StructFoo struct {

context.go1

1183:3modifies-parameterassignment modifies parameter cookie

context.go:1183:3

1182 if cookie.SameSite == http.SameSiteDefaultMode {
1183 cookie.SameSite = c.sameSite
1184 }

binding/form_mapping_test.go1

34:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:34:17

33 {"base type", struct{ F int8 }{}, "9", int8(9)},
34 {"base type", struct{ F int16 }{}, "9", int16(9)},
35 {"base type", struct{ F int32 }{}, "9", int32(9)},

utils_test.go1

19:6no-initreplace init with explicit initialization

utils_test.go:19:6

18
19func init() {
20 SetMode(TestMode)

gin.go1

575:2no-naked-returnreturn values must be explicit

gin.go:575:2

574 err = server.ListenAndServeTLS(certFile, keyFile)
575 return
576}

binding/binding.go1

89:2no-package-varpackage variables introduce mutable global state

binding/binding.go:89:2

88 Plain BindingBody = plainBinding{}
89 TOML BindingBody = tomlBinding{}
90 BSON BindingBody = bsonBinding{}

logger.go1

306:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

logger.go:306:6

305
306 if raw != "" && !conf.SkipQueryString {
307 path = path + "?" + raw

binding/query.go1

5:9package-commentspackage should have a documentation comment

binding/query.go:5:9

4
5package binding
6

binding/form_mapping_test.go1

33:42redundant-conversionconversion from int8 to the identical type is redundant

binding/form_mapping_test.go:33:42

32 {"base type", struct{ F int }{}, "9", int(9)},
33 {"base type", struct{ F int8 }{}, "9", int8(9)},
34 {"base type", struct{ F int16 }{}, "9", int16(9)},

binding/multipart_form_mapping.go1

44:3single-case-switchswitch with one case can be replaced by an if statement

binding/multipart_form_mapping.go:44:3

43 case reflect.Struct:
44 switch value.Interface().(type) {
45 case multipart.FileHeader:

binding/binding_test.go1

188:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:188:6

187
188func TestBindingJSON(t *testing.T) {
189 testBodyBinding(t,

context.go1

54:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

context.go:54:1

53
54const ContextRequestKey ContextKeyType = 0
55

context_test.go1

431:59unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:431:59

430
431 assert.Exactly(t, "this is a string", c.MustGet("string").(string))
432 assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))

gin_test.go1

341:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:341:14

340
341 res, err := http.Get(ts.URL + "/test")
342 if err != nil {

context_test.go1

801:23unused-parameterparameter c is unused

context_test.go:801:23

800
801func handlerNameTest2(c *Context) {
802}

binding/json_test.go1

124:7unused-receiverreceiver te is unused

binding/json_test.go:124:7

123
124func (te *TimeEx) CreateEncoder(typ reflect2.Type) jsoniter.ValEncoder {
125 if typ == timeType {

binding/binding_test.go1

262:14add-constantstring literal "bar2=foo" appears more than twice; define a constant

binding/binding_test.go:262:14

261 "/", "/",
262 "foo=bar", "bar2=foo")
263}

gin.go1

414:23cognitive-complexityfunction has cognitive complexity 12; maximum is 7

gin.go:414:23

413
414func (engine *Engine) prepareTrustedCIDRs() ([]*net.IPNet, error) {
415 if engine.trustedProxies == nil {

tree.go1

703:16cyclomatic-complexityfunction complexity is 61; maximum is 10

tree.go:703:16

702// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath
703func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {
704 npLen := len(n.path)

binding/binding_test.go1

940:12discarded-error-resulterror result returned by http.NewRequest is discarded

binding/binding_test.go:940:12

939 obj := FooBarStruct{}
940 req, _ := http.NewRequest(http.MethodPost, "/", nil)
941 err := b.Bind(req, &obj)

context.go1

517:1doc-comment-perioddocumentation comment should end with punctuation

context.go:517:1

516
517// AddParam adds param to context and
518// replaces path param key with given value for e2e testing purposes

tree_test.go1

1062:12error-stringserror string should not be capitalized or end with punctuation

tree_test.go:1062:12

1061 } else if string(out) != "/aa/aa" {
1062 t.Errorf("Wrong result for '/AA/AA': expected '/aa/aa', got: %s", string(out))
1063 }

binding/binding.go1

21:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:21:2

20 MIMEPROTOBUF = "application/x-protobuf"
21 MIMEMSGPACK = "application/x-msgpack"
22 MIMEMSGPACK2 = "application/msgpack"

binding/multipart_form_mapping.go1

1:1formatfile is not formatted

binding/multipart_form_mapping.go:1:1

1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/multipart_form_mapping.go`

tree.go1

288:16function-lengthfunction has 47 statements and 110 lines; maximum is 50 statements or 75 lines

tree.go:288:16

287
288func (n *node) insertChild(path string, fullPath string, handlers HandlersChain) {
289 for {

context_test.go1

3475:35insecure-url-schemeURL uses insecure http scheme

context_test.go:3475:35

3474 addr := strings.Split(l.Addr().String(), ":")
3475 res, err := http.Get(fmt.Sprintf("http://%s:%s/", localhostIP, addr[len(addr)-1]))
3476 if err != nil {

tree.go1

726:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:726:7

725 n = n.children[i]
726 if (len(n.path) == 1 && n.handlers != nil) ||
727 (n.nType == catchAll && n.children[0].handlers != nil) {

binding/binding_test.go1

126:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:126:6

125
126type FooStructForStructPointerType struct {
127 StructPointerFoo *struct {

context_test.go1

2209:2modifies-parameterassignment modifies parameter c

context_test.go:2209:2

2208 c.Request.Header.Set("Fly-Client-IP", "70.70.70.70")
2209 c.Request.RemoteAddr = " 40.40.40.40:42123 "
2210 c.engine.TrustedPlatform = ""

binding/form_mapping_test.go1

35:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:35:17

34 {"base type", struct{ F int16 }{}, "9", int16(9)},
35 {"base type", struct{ F int32 }{}, "9", int32(9)},
36 {"base type", struct{ F int64 }{}, "9", int64(9)},

gin.go1

592:3no-naked-returnreturn values must be explicit

gin.go:592:3

591 if err != nil {
592 return
593 }

binding/binding.go1

90:2no-package-varpackage variables introduce mutable global state

binding/binding.go:90:2

89 TOML BindingBody = tomlBinding{}
90 BSON BindingBody = bsonBinding{}
91)

recovery.go1

66:21optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

recovery.go:66:21

65 if ok {
66 isBrokenPipe = errors.Is(err, syscall.EPIPE) ||
67 errors.Is(err, syscall.ECONNRESET) ||

binding/toml.go1

5:9package-commentspackage should have a documentation comment

binding/toml.go:5:9

4
5package binding
6

binding/form_mapping_test.go1

34:43redundant-conversionconversion from int16 to the identical type is redundant

binding/form_mapping_test.go:34:43

33 {"base type", struct{ F int8 }{}, "9", int8(9)},
34 {"base type", struct{ F int16 }{}, "9", int16(9)},
35 {"base type", struct{ F int32 }{}, "9", int32(9)},

context.go1

841:3single-case-switchswitch with one case can be replaced by an if statement

context.go:841:3

840 // https://github.com/bytedance/sonic/issues/800
841 switch {
842 case errors.As(err, &maxBytesErr):

binding/binding_test.go1

209:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:209:6

208
209func TestBindingJSONUseNumber(t *testing.T) {
210 testBodyBindingUseNumber(t,

context_test.go2

804:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

context_test.go:804:1

803
804var handlerTest HandlerFunc = func(c *Context) {
805}
432:50unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:432:50

431 assert.Exactly(t, "this is a string", c.MustGet("string").(string))
432 assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))
433 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))

gin_test.go2

361:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:361:14

360
361 res, err := http.Get(ts.URL + "/test")
362 if err != nil {
990:19unused-parameterparameter c is unused

gin_test.go:990:19

989
990func handlerTest1(c *Context) {}
991func handlerTest2(c *Context) {}

binding/json_test.go1

133:7unused-receiverreceiver tc is unused

binding/json_test.go:133:7

132
133func (tc timeCodec) IsEmpty(ptr unsafe.Pointer) bool {
134 t := *((*time.Time)(ptr))

binding/binding_test.go1

267:16add-constantstring literal "/?bar2=foo" appears more than twice; define a constant

binding/binding_test.go:267:16

266 testFormBindingDefaultValue(t, http.MethodGet,
267 "/?foo=bar", "/?bar2=foo",
268 "", "")

gin.go1

690:23cognitive-complexityfunction has cognitive complexity 33; maximum is 7

gin.go:690:23

689
690func (engine *Engine) handleHTTPRequest(c *Context) {
691 httpMethod := c.Request.Method

tree_test.go1

714:6cyclomatic-complexityfunction complexity is 19; maximum is 10

tree_test.go:714:6

713
714func TestTreeFindCaseInsensitivePath(t *testing.T) {
715 tree := &node{}

binding/binding_test.go1

950:12discarded-error-resulterror result returned by http.NewRequest is discarded

binding/binding_test.go:950:12

949 obj := FooBarStruct{}
950 req, _ := http.NewRequest(http.MethodPost, "/", nil)
951 err := b.Bind(req, &obj)

context.go1

526:1doc-comment-perioddocumentation comment should end with punctuation

context.go:526:1

525
526// Query returns the keyed url query value if it exists,
527// otherwise it returns an empty string `("")`.

tree_test.go1

1087:12error-stringserror string should not be capitalized or end with punctuation

tree_test.go:1087:12

1086 if found {
1087 t.Errorf("Expected no match for '/prefix/a/b/c', but got: %s", string(out))
1088 }

binding/binding.go1

22:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:22:2

21 MIMEMSGPACK = "application/x-msgpack"
22 MIMEMSGPACK2 = "application/msgpack"
23 MIMEYAML = "application/x-yaml"

binding/multipart_form_mapping_test.go1

1:1formatfile is not formatted

binding/multipart_form_mapping_test.go:1:1

1// Copyright 2019 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/multipart_form_mapping_test.go`

tree.go1

418:16function-lengthfunction has 121 statements and 248 lines; maximum is 50 statements or 75 lines

tree.go:418:16

417// given path.
418func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
419 var globalParamsCount int16

gin_integration_test.go1

75:28insecure-url-schemeURL uses insecure http scheme

gin_integration_test.go:75:28

74 // Wait for server to be ready with exponential backoff
75 err := waitForServerReady("http://localhost:8080/example", 10)
76 require.NoError(t, err, "server should start successfully")

tree.go1

785:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:785:7

784 // as an index
785 if out := n.children[i].findCaseInsensitivePathRec(
786 path, ciPath, rb, fixTrailingSlash,

binding/binding_test.go1

132:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:132:6

131
132type FooStructForSliceMapType struct {
133 // Unknown type: not support map

context_test.go1

2210:2modifies-parameterassignment modifies parameter c

context_test.go:2210:2

2209 c.Request.RemoteAddr = " 40.40.40.40:42123 "
2210 c.engine.TrustedPlatform = ""
2211 c.engine.trustedCIDRs = defaultTrustedCIDRs

binding/form_mapping_test.go1

36:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:36:17

35 {"base type", struct{ F int32 }{}, "9", int32(9)},
36 {"base type", struct{ F int64 }{}, "9", int64(9)},
37 {"base type", struct{ F uint }{}, "9", uint(9)},

gin.go1

601:2no-naked-returnreturn values must be explicit

gin.go:601:2

600 err = server.Serve(listener)
601 return
602}

binding/binding_nomsgpack.go1

69:5no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:69:5

68// under the hood.
69var Validator StructValidator = &defaultValidator{}
70

render/redirect.go1

21:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

render/redirect.go:21:5

20func (r Redirect) Render(w http.ResponseWriter) error {
21 if (r.Code < http.StatusMultipleChoices || r.Code > http.StatusPermanentRedirect) && r.Code != http.StatusCreated {
22 panic(fmt.Sprintf("Cannot redirect with status code %d", r.Code))

binding/uri.go1

5:9package-commentspackage should have a documentation comment

binding/uri.go:5:9

4
5package binding
6

binding/form_mapping_test.go1

35:43redundant-conversionconversion from int32 to the identical type is redundant

binding/form_mapping_test.go:35:43

34 {"base type", struct{ F int16 }{}, "9", int16(9)},
35 {"base type", struct{ F int32 }{}, "9", int32(9)},
36 {"base type", struct{ F int64 }{}, "9", int64(9)},

context.go1

1111:2single-case-switchswitch with one case can be replaced by an if statement

context.go:1111:2

1110func bodyAllowedForStatus(status int) bool {
1111 switch {
1112 case status >= http.StatusContinue && status < http.StatusOK:

binding/binding_test.go1

216:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:216:6

215
216func TestBindingJSONUseNumber2(t *testing.T) {
217 testBodyBindingUseNumber2(t,

debug.go1

27:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

debug.go:27:1

26// DebugPrintRouteFunc indicates debug log output format.
27var DebugPrintRouteFunc func(httpMethod, absolutePath, handlerName string, nuHandlers int)
28

context_test.go1

433:61unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:433:61

432 assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))
433 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))
434 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))

gin_test.go2

381:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:381:14

380
381 res, err := http.Get(ts.URL + "/test")
382 if err != nil {
991:19unused-parameterparameter c is unused

gin_test.go:991:19

990func handlerTest1(c *Context) {}
991func handlerTest2(c *Context) {}
992

binding/json_test.go1

138:7unused-receiverreceiver tc is unused

binding/json_test.go:138:7

137
138func (tc timeCodec) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) {
139 t := *((*time.Time)(ptr))

binding/binding_test.go1

286:3add-constantstring literal "time_foo=2017-11-15" appears more than twice; define a constant

binding/binding_test.go:286:3

285 "/", "/",
286 "time_foo=2017-11-15", "bar2=foo")
287}

githubapi_test.go1

405:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

githubapi_test.go:405:6

404
405func exampleFromPath(path string) (string, Params) {
406 output := new(strings.Builder)

binding/binding_test.go1

1432:11discarded-error-resulterror result returned by http.NewRequest is discarded

binding/binding_test.go:1432:11

1431func requestWithBody(method, path, body string) (req *http.Request) {
1432 req, _ = http.NewRequest(method, path, bytes.NewBufferString(body))
1433 return

context.go1

540:1doc-comment-perioddocumentation comment should end with punctuation

context.go:540:1

539
540// DefaultQuery returns the keyed url query value if it exists,
541// otherwise it returns the specified defaultValue string.

tree_test.go1

1095:12error-stringserror string should not be capitalized or end with punctuation

tree_test.go:1095:12

1094 } else if string(out) != "/prefix/xxx" {
1095 t.Errorf("Wrong result for '/prefix/xxx': %s", string(out))
1096 }

binding/binding.go1

23:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:23:2

22 MIMEMSGPACK2 = "application/msgpack"
23 MIMEYAML = "application/x-yaml"
24 MIMEYAML2 = "application/yaml"

binding/validate_test.go1

1:1formatfile is not formatted

binding/validate_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt binding/validate_test.go`

tree.go1

703:16function-lengthfunction has 115 statements and 248 lines; maximum is 50 statements or 75 lines

tree.go:703:16

702// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath
703func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {
704 npLen := len(n.path)

gin_integration_test.go1

79:17insecure-url-schemeURL uses insecure http scheme

gin_integration_test.go:79:17

78 require.Error(t, router.Run(":8080"))
79 testRequest(t, "http://localhost:8080/example")
80}

tree.go1

803:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:803:7

802 // Uppercase matches
803 if c == idxc {
804 // Continue with child node

binding/binding_test.go1

137:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:137:6

136
137type FooStructForBoolType struct {
138 BoolFoo bool `form:"bool_foo"`

context_test.go1

2211:2modifies-parameterassignment modifies parameter c

context_test.go:2211:2

2210 c.engine.TrustedPlatform = ""
2211 c.engine.trustedCIDRs = defaultTrustedCIDRs
2212 c.engine.AppEngine = false

binding/form_mapping_test.go1

37:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:37:17

36 {"base type", struct{ F int64 }{}, "9", int64(9)},
37 {"base type", struct{ F uint }{}, "9", uint(9)},
38 {"base type", struct{ F uint8 }{}, "9", uint8(9)},

gin.go1

620:3no-naked-returnreturn values must be explicit

gin.go:620:3

619 if err != nil {
620 return
621 }

binding/binding_nomsgpack.go1

74:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:74:2

73var (
74 JSON = jsonBinding{}
75 XML = xmlBinding{}

render/render_test.go1

164:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

render/render_test.go:164:5

163 w.writeCount++
164 if (w.bufString != "" && string(buf) == w.bufString) || (w.ErrThreshold > 0 && w.writeCount >= w.ErrThreshold) {
165 return 0, errors.New(`write error`)

binding/xml.go1

5:9package-commentspackage should have a documentation comment

binding/xml.go:5:9

4
5package binding
6

binding/form_mapping_test.go1

36:43redundant-conversionconversion from int64 to the identical type is redundant

binding/form_mapping_test.go:36:43

35 {"base type", struct{ F int32 }{}, "9", int32(9)},
36 {"base type", struct{ F int64 }{}, "9", int64(9)},
37 {"base type", struct{ F uint }{}, "9", uint(9)},

context.go1

1415:2single-case-switchswitch with one case can be replaced by an if statement

context.go:1415:2

1414func (c *Context) Negotiate(code int, config Negotiate) {
1415 switch c.NegotiateFormat(config.Offered...) {
1416 case binding.MIMEJSON:

binding/binding_test.go1

223:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:223:6

222
223func TestBindingJSONDisallowUnknownFields(t *testing.T) {
224 testBodyBindingDisallowUnknownFields(t, JSON,

errors.go1

18:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

errors.go:18:1

17
18const (
19 // ErrorTypeBind is used when Context.Bind() fails.

context_test.go1

434:51unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:434:51

433 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))
434 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))
435 assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)

gin_test.go1

408:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:408:14

407 client := &http.Client{Transport: tr}
408 res, err := client.Get(ts.URL + "/test")
409 if err != nil {

render/render_msgpack_test.go1

67:28unused-parameterparameter data is unused

render/render_msgpack_test.go:67:28

66
67func (w *failWriter) Write(data []byte) (int, error) {
68 return 0, errors.New("write error")

binding/json_test.go1

147:7unused-receiverreceiver tc is unused

binding/json_test.go:147:7

146
147func (tc timeCodec) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
148 ts := iter.ReadString()

binding/binding_test.go1

303:3add-constantstring literal "/?time_foo=2017-11-15" appears more than twice; define a constant

binding/binding_test.go:303:3

302 testFormBindingForTimeFailLocation(t, http.MethodGet,
303 "/?time_foo=2017-11-15", "/?bar2=foo",
304 "", "")

logger.go1

245:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

logger.go:245:6

244// LoggerWithConfig instance a Logger middleware with config.
245func LoggerWithConfig(conf LoggerConfig) HandlerFunc {
246 formatter := conf.Formatter

binding/form_mapping.go1

469:17discarded-error-resulterror result returned by strconv.ParseBool is discarded

binding/form_mapping.go:469:17

468 l := time.Local
469 if isUTC, _ := strconv.ParseBool(structField.Tag.Get("time_utc")); isUTC {
470 l = time.UTC

context.go1

555:1doc-comment-perioddocumentation comment should end with punctuation

context.go:555:1

554
555// GetQuery is like Query(), it returns the keyed url query value
556// if it exists `(value, true)` (even when the value is an empty string),

tree_test.go1

1103:12error-stringserror string should not be capitalized or end with punctuation

tree_test.go:1103:12

1102 } else if string(out) != "/prefix/xxx" {
1103 t.Errorf("Wrong result for '/PREFIX/XXX': expected '/prefix/xxx', got: %s", string(out))
1104 }

binding/binding.go1

24:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:24:2

23 MIMEYAML = "application/x-yaml"
24 MIMEYAML2 = "application/yaml"
25 MIMETOML = "application/toml"

codec/json/go_json.go1

1:1formatfile is not formatted

codec/json/go_json.go:1:1

1// Copyright 2025 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt codec/json/go_json.go`

tree_test.go1

138:6function-lengthfunction has 6 statements and 186 lines; maximum is 50 statements or 75 lines

tree_test.go:138:6

137
138func TestTreeWildcard(t *testing.T) {
139 tree := &node{}

gin_integration_test.go1

219:28insecure-url-schemeURL uses insecure http scheme

gin_integration_test.go:219:28

218 // Wait for server to be ready with exponential backoff
219 err := waitForServerReady("http://localhost:3123/example", 10)
220 require.NoError(t, err, "server should start successfully")

tree.go1

832:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:832:7

831 if c == idxc {
832 if out := n.children[i].findCaseInsensitivePathRec(
833 path, ciPath, rb, fixTrailingSlash,

binding/binding_test.go1

141:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:141:6

140
141type FooStructForStringPtrType struct {
142 PtrFoo *string `form:"ptr_foo"`

context_test.go1

2212:2modifies-parameterassignment modifies parameter c

context_test.go:2212:2

2211 c.engine.trustedCIDRs = defaultTrustedCIDRs
2212 c.engine.AppEngine = false
2213}

binding/form_mapping_test.go1

38:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:38:17

37 {"base type", struct{ F uint }{}, "9", uint(9)},
38 {"base type", struct{ F uint8 }{}, "9", uint8(9)},
39 {"base type", struct{ F uint16 }{}, "9", uint16(9)},

gin.go1

624:2no-naked-returnreturn values must be explicit

gin.go:624:2

623 err = engine.RunListener(listener)
624 return
625}

binding/binding_nomsgpack.go1

75:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:75:2

74 JSON = jsonBinding{}
75 XML = xmlBinding{}
76 Form = formBinding{}

tree.go1

201:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:201:7

200 // Otherwise insert it
201 if c != ':' && c != '*' && n.nType != catchAll {
202 // []byte for proper unicode char conversion, see #65

binding/yaml.go1

5:9package-commentspackage should have a documentation comment

binding/yaml.go:5:9

4
5package binding
6

binding/form_mapping_test.go1

37:42redundant-conversionconversion from uint to the identical type is redundant

binding/form_mapping_test.go:37:42

36 {"base type", struct{ F int64 }{}, "9", int64(9)},
37 {"base type", struct{ F uint }{}, "9", uint(9)},
38 {"base type", struct{ F uint8 }{}, "9", uint8(9)},

context_test.go1

2228:2single-case-switchswitch with one case can be replaced by an if statement

context_test.go:2228:2

2227 var expectedCode int
2228 switch json.Package {
2229 case "github.com/goccy/go-json":

binding/binding_test.go1

229:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:229:6

228
229func TestBindingJSONStringMap(t *testing.T) {
230 testBodyBindingStringMap(t, JSON,

errors_test.go1

110:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

errors_test.go:110:1

109
110type TestErr string
111

context_test.go1

435:54unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:435:54

434 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))
435 assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)
436 assert.InDelta(t, 4.2, c.MustGet("float64").(float64), 0.01)

gin_test.go1

428:14unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

gin_test.go:428:14

427
428 res, err := http.Get(ts.URL + "/raw")
429 if err != nil {

response_writer_test.go1

44:40unused-parameterparameter code is unused

response_writer_test.go:44:40

43func (w *nonFlusherWriter) Write(b []byte) (int, error) { return len(b), nil }
44func (w *nonFlusherWriter) WriteHeader(code int) {}
45

binding/json_test.go1

173:7unused-receiverreceiver tpe is unused

binding/json_test.go:173:7

172
173func (tpe *TimePointerEx) CreateDecoder(typ reflect2.Type) jsoniter.ValDecoder {
174 if typ == timePointerType {

binding/binding_test.go1

410:3add-constantstring literal "/?foo=bar&bar=foo" appears more than twice; define a constant

binding/binding_test.go:410:3

409 testQueryBinding(t, http.MethodGet,
410 "/?foo=bar&bar=foo", "/?bar2=foo",
411 "foo=unused", "")

path.go1

23:6cognitive-complexityfunction has cognitive complexity 32; maximum is 7

path.go:23:6

22// If the result of this process is an empty string, "/" is returned.
23func cleanPath(p string) string {
24 // Turn empty string into "/"

binding/form_mapping_test.go1

700:17discarded-error-resulterror result returned by convertTo is discarded

binding/form_mapping_test.go:700:17

699
700 expected, _ := convertTo(val)
701 assert.Equal(t, expected, s.FileData)

context.go1

626:1doc-comment-perioddocumentation comment should end with punctuation

context.go:626:1

625
626// GetPostForm is like PostForm(key). It returns the specified key from a POST urlencoded
627// form or multipart form when it exists `(value, true)` (even when the value is an empty string),

tree_test.go1

1111:12error-stringserror string should not be capitalized or end with punctuation

tree_test.go:1111:12

1110 } else if string(out) != "/prefix/something" {
1111 t.Errorf("Wrong result for '/prefix/something': %s", string(out))
1112 }

binding/binding.go1

25:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:25:2

24 MIMEYAML2 = "application/yaml"
25 MIMETOML = "application/toml"
26 MIMEBSON = "application/bson"

codec/json/json.go1

1:1formatfile is not formatted

codec/json/json.go:1:1

1// Copyright 2025 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt codec/json/json.go`

tree_test.go1

570:6function-lengthfunction has 19 statements and 105 lines; maximum is 50 statements or 75 lines

tree_test.go:570:6

569
570func TestTreeTrailingSlashRedirect(t *testing.T) {
571 tree := &node{}

gin_integration_test.go1

223:17insecure-url-schemeURL uses insecure http scheme

gin_integration_test.go:223:17

222 require.Error(t, router.Run(":3123"))
223 testRequest(t, "http://localhost:3123/example")
224}

tree.go1

857:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:857:7

856 if c == idxc {
857 if out := n.children[i].findCaseInsensitivePathRec(
858 path, ciPath, rb, fixTrailingSlash,

binding/binding_test.go1

146:6max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:146:6

145
146type FooStructForMapPtrType struct {
147 PtrBar *map[string]any `form:"ptr_bar"`

debug.go1

67:3modifies-parameterassignment modifies parameter format

debug.go:67:3

66 if !strings.HasSuffix(format, "\n") {
67 format += "\n"
68 }

binding/form_mapping_test.go1

39:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:39:17

38 {"base type", struct{ F uint8 }{}, "9", uint8(9)},
39 {"base type", struct{ F uint16 }{}, "9", uint16(9)},
40 {"base type", struct{ F uint32 }{}, "9", uint32(9)},

gin.go1

640:2no-naked-returnreturn values must be explicit

gin.go:640:2

639 err = http3.ListenAndServeQUIC(addr, certFile, keyFile, engine.Handler())
640 return
641}

binding/binding_nomsgpack.go1

76:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:76:2

75 XML = xmlBinding{}
76 Form = formBinding{}
77 Query = queryBinding{}

tree.go1

216:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:216:8

215 // Check if the wildcard matches
216 if len(path) >= len(n.path) && n.path == path[:len(n.path)] &&
217 // Adding a child to a catchAll is not possible

codec/json/api.go1

5:9package-commentspackage should have a documentation comment

codec/json/api.go:5:9

4
5package json
6

binding/form_mapping_test.go1

38:43redundant-conversionconversion from uint8 to the identical type is redundant

binding/form_mapping_test.go:38:43

37 {"base type", struct{ F uint }{}, "9", uint(9)},
38 {"base type", struct{ F uint8 }{}, "9", uint8(9)},
39 {"base type", struct{ F uint16 }{}, "9", uint16(9)},

errors.go1

59:3single-case-switchswitch with one case can be replaced by an if statement

errors.go:59:3

58 value := reflect.ValueOf(msg.Meta)
59 switch value.Kind() {
60 case reflect.Struct:

binding/binding_test.go1

235:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:235:6

234
235func TestBindingForm(t *testing.T) {
236 testFormBinding(t, http.MethodPost,

fs.go1

28:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

fs.go:28:1

27// neutralizedReaddirFile wraps http.File with a specific implementation of `Readdir`.
28type neutralizedReaddirFile struct {
29 http.File

context_test.go1

436:45unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:436:45

435 assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)
436 assert.InDelta(t, 4.2, c.MustGet("float64").(float64), 0.01)
437 assert.Exactly(t, 1, c.MustGet("intInterface").(int))

response_writer_test.go2

292:15unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

response_writer_test.go:292:15

291 // should return 500
292 resp, err := http.Get(testServer.URL)
293 require.NoError(t, err)
320:41unused-parameterparameter target is unused

response_writer_test.go:320:41

319
320func (m *mockPusherResponseWriter) Push(target string, opts *http.PushOptions) error {
321 return nil

binding/json_test.go1

180:7unused-receiverreceiver tpe is unused

binding/json_test.go:180:7

179
180func (tpe *TimePointerEx) CreateEncoder(typ reflect2.Type) jsoniter.ValEncoder {
181 if typ == timePointerType {

binding/binding_test.go1

450:27add-constantstring literal "foo" appears more than twice; define a constant

binding/binding_test.go:450:27

449 assert.Len(t, obj, 2)
450 assert.Equal(t, "2", obj["foo"])
451 assert.Equal(t, "world", obj["hello"])

path.go1

155:6cognitive-complexityfunction has cognitive complexity 12; maximum is 7

path.go:155:6

154// if s == "/a//b///c////" && char == '/', it returns "/a/b/c/"
155func removeRepeatedChar(s string, char byte) string {
156 // Check if there are any consecutive chars

binding/form_mapping_test.go1

712:17discarded-error-resulterror result returned by convertTo is discarded

binding/form_mapping_test.go:712:17

711
712 expected, _ := convertTo(val)
713 assert.Equal(t, expected, s.FileData)

context.go1

866:1doc-comment-perioddocumentation comment should end with punctuation

context.go:866:1

865
866// ShouldBindJSON is a shortcut for c.ShouldBindWith(obj, binding.JSON).
867//

binding/binding.go1

26:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:26:2

25 MIMETOML = "application/toml"
26 MIMEBSON = "application/bson"
27)

codec/json/jsoniter.go1

1:1formatfile is not formatted

codec/json/jsoniter.go:1:1

1// Copyright 2025 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt codec/json/jsoniter.go`

tree_test.go1

714:6function-lengthfunction has 33 statements and 159 lines; maximum is 50 statements or 75 lines

tree_test.go:714:6

713
714func TestTreeFindCaseInsensitivePath(t *testing.T) {
715 tree := &node{}

gin_integration_test.go1

241:28insecure-url-schemeURL uses insecure http scheme

gin_integration_test.go:241:28

240 // Wait for server to be ready with exponential backoff
241 err := waitForServerReady("http://localhost:5150/example", 10)
242 require.NoError(t, err, "server should start successfully")

tree.go1

872:7max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:872:7

871 for i, c := range []byte(n.indices) {
872 if c == idxc {
873 if out := n.children[i].findCaseInsensitivePathRec(

binding/binding_test.go1

769:7max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:769:7

768func TestRequiredSucceeds(t *testing.T) {
769 type HogeStruct struct {
770 Hoge *int `json:"hoge" binding:"required"`

gin.go1

398:2modifies-parameterassignment modifies parameter path

gin.go:398:2

397func iterate(path, method string, routes RoutesInfo, root *node) RoutesInfo {
398 path += root.path
399 if len(root.handlers) > 0 {

binding/form_mapping_test.go1

40:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:40:17

39 {"base type", struct{ F uint16 }{}, "9", uint16(9)},
40 {"base type", struct{ F uint32 }{}, "9", uint32(9)},
41 {"base type", struct{ F uint64 }{}, "9", uint64(9)},

gin.go1

658:2no-naked-returnreturn values must be explicit

gin.go:658:2

657 err = server.Serve(listener)
658 return
659}

binding/binding_nomsgpack.go1

77:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:77:2

76 Form = formBinding{}
77 Query = queryBinding{}
78 FormPost = formPostBinding{}

tree.go1

216:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:216:8

215 // Check if the wildcard matches
216 if len(path) >= len(n.path) && n.path == path[:len(n.path)] &&
217 // Adding a child to a catchAll is not possible

codec/json/go_json.go1

7:9package-commentspackage should have a documentation comment

codec/json/go_json.go:7:9

6
7package json
8

binding/form_mapping_test.go1

39:44redundant-conversionconversion from uint16 to the identical type is redundant

binding/form_mapping_test.go:39:44

38 {"base type", struct{ F uint8 }{}, "9", uint8(9)},
39 {"base type", struct{ F uint16 }{}, "9", uint16(9)},
40 {"base type", struct{ F uint32 }{}, "9", uint32(9)},

errors.go1

142:2single-case-switchswitch with one case can be replaced by an if statement

errors.go:142:2

141func (a errorMsgs) JSON() any {
142 switch length := len(a); length {
143 case 0:

binding/binding_test.go1

241:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:241:6

240
241func TestBindingForm2(t *testing.T) {
242 testFormBinding(t, http.MethodGet,

gin.go1

68:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

gin.go:68:1

67// RouteInfo represents a request route's specification which contains method and path and its handler.
68type RouteInfo struct {
69 Method string

context_test.go1

437:48unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:437:48

436 assert.InDelta(t, 4.2, c.MustGet("float64").(float64), 0.01)
437 assert.Exactly(t, 1, c.MustGet("intInterface").(int))
438}

test_helpers.go1

45:16unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

test_helpers.go:45:16

44 for i := 0; i < maxAttempts; i++ {
45 resp, err := client.Get(url)
46 if err == nil {

response_writer_test.go1

320:56unused-parameterparameter opts is unused

response_writer_test.go:320:56

319
320func (m *mockPusherResponseWriter) Push(target string, opts *http.PushOptions) error {
321 return nil

binding/json_test.go1

189:7unused-receiverreceiver tpc is unused

binding/json_test.go:189:7

188
189func (tpc timePointerCodec) IsEmpty(ptr unsafe.Pointer) bool {
190 t := *((**time.Time)(ptr))

binding/binding_test.go1

451:18add-constantstring literal "world" appears more than twice; define a constant

binding/binding_test.go:451:18

450 assert.Equal(t, "2", obj["foo"])
451 assert.Equal(t, "world", obj["hello"])
452}

recovery.go1

53:6cognitive-complexityfunction has cognitive complexity 15; maximum is 7

recovery.go:53:6

52// CustomRecoveryWithWriter returns a middleware for a given writer that recovers from any panics and calls the provided handle func to handle it.
53func CustomRecoveryWithWriter(out io.Writer, handle RecoveryFunc) HandlerFunc {
54 var logger *log.Logger

binding/form_mapping_test.go1

717:12discarded-error-resulterror result returned by convertTo is discarded

binding/form_mapping_test.go:717:12

716func TestMappingCustomArrayOfArrayUri(t *testing.T) {
717 id1, _ := convertTo(`664a062ac74a8ad104e0e80e`)
718 id2, _ := convertTo(`664a062ac74a8ad104e0e80f`)

context.go1

1073:1doc-comment-perioddocumentation comment should end with punctuation

context.go:1073:1

1072
1073// Scheme returns the HTTP scheme of the request ("http" or "https").
1074// When running behind reverse proxies or load balancers `Request.URL.Scheme` is usually empty.

binding/binding.go1

32:6exported-declaration-commentexported type should have a comment beginning with its name

binding/binding.go:32:6

31// the form POST.
32type Binding interface {
33 Name() string

codec/json/sonic.go1

1:1formatfile is not formatted

codec/json/sonic.go:1:1

1// Copyright 2025 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt codec/json/sonic.go`

gin_integration_test.go1

245:17insecure-url-schemeURL uses insecure http scheme

gin_integration_test.go:245:17

244 require.Error(t, router.Run(":5150"))
245 testRequest(t, "http://localhost:5150/example")
246}

tree.go1

873:8max-control-nestingcontrol-flow nesting exceeds 5 levels

tree.go:873:8

872 if c == idxc {
873 if out := n.children[i].findCaseInsensitivePathRec(
874 path, ciPath, rb, fixTrailingSlash,

binding/binding_test.go1

780:7max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:780:7

779func TestRequiredFails(t *testing.T) {
780 type HogeStruct struct {
781 Hoge *int `json:"foo" binding:"required"`

gin.go1

401:3modifies-parameterassignment modifies parameter routes

gin.go:401:3

400 handlerFunc := root.handlers.Last()
401 routes = append(routes, RouteInfo{
402 Method: method,

binding/form_mapping_test.go1

41:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:41:17

40 {"base type", struct{ F uint32 }{}, "9", uint32(9)},
41 {"base type", struct{ F uint64 }{}, "9", uint64(9)},
42 {"base type", struct{ F bool }{}, "True", true},

path_test.go1

123:2no-naked-returnreturn values must be explicit

path_test.go:123:2

122 }
123 return
124}

binding/binding_nomsgpack.go1

78:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:78:2

77 Query = queryBinding{}
78 FormPost = formPostBinding{}
79 FormMultipart = formMultipartBinding{}

tree.go1

220:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:220:7

219 // Check for longer wildcard, e.g. :name and :names
220 (len(n.path) >= len(path) || path[len(n.path)] == '/') {
221 continue walk

codec/json/json.go1

7:9package-commentspackage should have a documentation comment

codec/json/json.go:7:9

6
7package json
8

binding/form_mapping_test.go1

40:44redundant-conversionconversion from uint32 to the identical type is redundant

binding/form_mapping_test.go:40:44

39 {"base type", struct{ F uint16 }{}, "9", uint16(9)},
40 {"base type", struct{ F uint32 }{}, "9", uint32(9)},
41 {"base type", struct{ F uint64 }{}, "9", uint64(9)},

gin.go1

427:4single-case-switchswitch with one case can be replaced by an if statement

gin.go:427:4

426
427 switch len(ip) {
428 case net.IPv4len:

binding/binding_test.go1

247:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:247:6

246
247func TestBindingFormEmbeddedStruct(t *testing.T) {
248 testFormBindingEmbeddedStruct(t, http.MethodPost,

gin_test.go1

328:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

gin_test.go:328:1

327
328var tmplFS = http.Dir("testdata/template")
329

context_test.go1

724:42unchecked-type-assertionuse the checked two-result form of the type assertion

context_test.go:724:42

723 assert.Nil(t, cp.writermem.ResponseWriter)
724 assert.Equal(t, &cp.writermem, cp.Writer.(*responseWriter))
725 assert.Equal(t, cp.Request, c.Request)

tree_test.go1

533:29unused-parameterparameter t is unused

tree_test.go:533:29

532
533func TestTreeCatchMaxParams(t *testing.T) {
534 tree := &node{}

binding/json_test.go1

194:7unused-receiverreceiver tpc is unused

binding/json_test.go:194:7

193
194func (tpc timePointerCodec) Encode(ptr unsafe.Pointer, stream *jsoniter.Stream) {
195 t := *((**time.Time)(ptr))

binding/binding_test.go1

451:31add-constantstring literal "hello" appears more than twice; define a constant

binding/binding_test.go:451:31

450 assert.Equal(t, "2", obj["foo"])
451 assert.Equal(t, "world", obj["hello"])
452}

recovery.go1

119:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

recovery.go:119:6

118// stack returns a nicely formatted stack frame, skipping skip frames.
119func stack(skip int) []byte {
120 buf := new(bytes.Buffer) // the returned data

binding/form_mapping_test.go1

718:12discarded-error-resulterror result returned by convertTo is discarded

binding/form_mapping_test.go:718:12

717 id1, _ := convertTo(`664a062ac74a8ad104e0e80e`)
718 id2, _ := convertTo(`664a062ac74a8ad104e0e80f`)
719

context.go1

1127:1doc-comment-perioddocumentation comment should end with punctuation

context.go:1127:1

1126
1127// Header is an intelligent shortcut for c.Writer.Header().Set(key, value).
1128// It writes a header in the response.

binding/binding.go1

39:6exported-declaration-commentexported type should have a comment beginning with its name

binding/binding.go:39:6

38// but it reads the body from supplied bytes instead of req.Body.
39type BindingBody interface {
40 Binding

context.go1

1:1formatfile is not formatted

context.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt context.go`

gin_test.go1

103:9insecure-url-schemeURL uses insecure http scheme

gin_test.go:103:9

102
103 url := "http://" + ln.Addr().String() + "/"
104

binding/binding_test.go1

819:7max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:819:7

818
819 type Tag struct {
820 Name string `uri:"name"`

gin.go1

409:3modifies-parameterassignment modifies parameter routes

gin.go:409:3

408 for _, child := range root.children {
409 routes = iterate(path, method, routes, child)
410 }

binding/form_mapping_test.go1

42:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:42:17

41 {"base type", struct{ F uint64 }{}, "9", uint64(9)},
42 {"base type", struct{ F bool }{}, "True", true},
43 {"base type", struct{ F float32 }{}, "9.1", float32(9.1)},

render/data.go1

25:2no-naked-returnreturn values must be explicit

render/data.go:25:2

24 _, err = w.Write(r.Data)
25 return
26}

binding/binding_nomsgpack.go1

79:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:79:2

78 FormPost = formPostBinding{}
79 FormMultipart = formMultipartBinding{}
80 ProtoBuf = protobufBinding{}

tree.go1

493:10optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:493:10

492 end := 0
493 for end < len(path) && path[end] != '/' {
494 end++

codec/json/jsoniter.go1

7:9package-commentspackage should have a documentation comment

codec/json/jsoniter.go:7:9

6
7package json
8

binding/form_mapping_test.go1

41:44redundant-conversionconversion from uint64 to the identical type is redundant

binding/form_mapping_test.go:41:44

40 {"base type", struct{ F uint32 }{}, "9", uint32(9)},
41 {"base type", struct{ F uint64 }{}, "9", uint64(9)},
42 {"base type", struct{ F bool }{}, "True", true},

gin_test.go1

689:3single-case-switchswitch with one case can be replaced by an if statement

gin_test.go:689:3

688
689 switch {
690 case count > 0:

binding/binding_test.go1

253:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:253:6

252
253func TestBindingFormEmbeddedStruct2(t *testing.T) {
254 testFormBindingEmbeddedStruct(t, http.MethodGet,

githubapi_test.go1

27:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

githubapi_test.go:27:1

26// http://developer.github.com/v3/
27var githubAPI = []route{
28 // OAuth Authorizations

fs_test.go1

33:32unchecked-type-assertionuse the checked two-result form of the type assertion

fs_test.go:33:32

32 require.NoError(t, err)
33 assert.Equal(t, testFile, file.(neutralizedReaddirFile).File)
34}

tree_test.go1

901:32unused-parameterparameter t is unused

tree_test.go:901:32

900
901func TestTreeInvalidParamsType(t *testing.T) {
902 tree := &node{}

binding/json_test.go1

203:7unused-receiverreceiver tpc is unused

binding/json_test.go:203:7

202
203func (tpc timePointerCodec) Decode(ptr unsafe.Pointer, iter *jsoniter.Iterator) {
204 ts := iter.ReadString()

binding/binding_test.go1

506:17add-constantstring literal "Content-Type" appears more than twice; define a constant

binding/binding_test.go:506:17

505 require.NoError(t, err)
506 req.Header.Set("Content-Type", MIMEPOSTForm)
507 return req

tree.go1

135:16cognitive-complexityfunction has cognitive complexity 38; maximum is 7

tree.go:135:16

134// Not concurrency-safe!
135func (n *node) addRoute(path string, handlers HandlersChain) {
136 fullPath := path

binding/form_mapping_test.go1

729:12discarded-error-resulterror result returned by convertTo is discarded

binding/form_mapping_test.go:729:12

728func TestMappingCustomArrayOfArrayForm(t *testing.T) {
729 id1, _ := convertTo(`664a062ac74a8ad104e0e80e`)
730 id2, _ := convertTo(`664a062ac74a8ad104e0e80f`)

context.go1

1151:1doc-comment-perioddocumentation comment should end with punctuation

context.go:1151:1

1150
1151// SetSameSite with cookie
1152func (c *Context) SetSameSite(samesite http.SameSite) {

binding/binding.go1

46:6exported-declaration-commentexported type should have a comment beginning with its name

binding/binding.go:46:6

45// but it reads the Params.
46type BindingUri interface {
47 Name() string

context_test.go1

1:1formatfile is not formatted

context_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt context_test.go`

recovery_test.go1

313:45insecure-url-schemeURL uses insecure http scheme

recovery_test.go:313:45

312 req: func() *http.Request {
313 r, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
314 r.Header.Set("Authorization", "Bearer secret-token")

binding/binding_test.go1

828:7max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:828:7

827
828 type NotSupportStruct struct {
829 Name map[string]any `uri:"name"`

gin.go1

505:2modifies-parameterassignment modifies parameter n

gin.go:505:2

504func updateRouteTree(n *node) {
505 n.path = strings.ReplaceAll(n.path, escapedColon, colon)
506 n.fullPath = strings.ReplaceAll(n.fullPath, escapedColon, colon)

binding/form_mapping_test.go1

43:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:43:17

42 {"base type", struct{ F bool }{}, "True", true},
43 {"base type", struct{ F float32 }{}, "9.1", float32(9.1)},
44 {"base type", struct{ F float64 }{}, "9.1", float64(9.1)},

render/reader.go1

32:2no-naked-returnreturn values must be explicit

render/reader.go:32:2

31 _, err = io.Copy(w, r.Reader)
32 return
33}

binding/binding_nomsgpack.go1

80:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:80:2

79 FormMultipart = formMultipartBinding{}
80 ProtoBuf = protobufBinding{}
81 YAML = yamlBinding{}

tree.go1

616:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:616:7

615 // additional trailing slash
616 if path == "/" && n.wildChild && n.nType != root {
617 value.tsr = true

codec/json/sonic.go1

7:9package-commentspackage should have a documentation comment

codec/json/sonic.go:7:9

6
7package json
8

binding/form_mapping_test.go1

43:47redundant-conversionconversion from float32 to the identical type is redundant

binding/form_mapping_test.go:43:47

42 {"base type", struct{ F bool }{}, "True", true},
43 {"base type", struct{ F float32 }{}, "9.1", float32(9.1)},
44 {"base type", struct{ F float64 }{}, "9.1", float64(9.1)},

logger.go1

97:2single-case-switchswitch with one case can be replaced by an if statement

logger.go:97:2

96
97 switch {
98 case code >= http.StatusContinue && code < http.StatusOK:

binding/binding_test.go1

259:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:259:6

258
259func TestBindingFormDefaultValue(t *testing.T) {
260 testFormBindingDefaultValue(t, http.MethodPost,

internal/bytesconv/bytesconv_test.go1

53:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

internal/bytesconv/bytesconv_test.go:53:1

52
53const letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
54const (

gin.go1

667:24unchecked-type-assertionuse the checked two-result form of the type assertion

gin.go:667:24

666
667 c := engine.pool.Get().(*Context)
668 c.writermem.reset(w)

codec/json/go_json.go1

24:7unused-receiverreceiver j is unused

codec/json/go_json.go:24:7

23
24func (j gojsonApi) Marshal(v any) ([]byte, error) {
25 return json.Marshal(v)

binding/binding_test.go1

538:42add-constantstring literal "bar" appears more than twice; define a constant

binding/binding_test.go:538:42

537 require.NoError(t, mw.SetBoundary(boundary))
538 require.NoError(t, mw.WriteField("foo", "bar"))
539 require.NoError(t, mw.WriteField("bar", "foo"))

tree.go1

253:6cognitive-complexityfunction has cognitive complexity 18; maximum is 7

tree.go:253:6

252// Returns -1 as index, if no wildcard was found.
253func findWildcard(path string) (wildcard string, i int, valid bool) {
254 // Find start

binding/form_mapping_test.go1

730:12discarded-error-resulterror result returned by convertTo is discarded

binding/form_mapping_test.go:730:12

729 id1, _ := convertTo(`664a062ac74a8ad104e0e80e`)
730 id2, _ := convertTo(`664a062ac74a8ad104e0e80f`)
731

context.go1

1218:1doc-comment-perioddocumentation comment should end with punctuation

context.go:1218:1

1217
1218// HTML renders the HTTP template specified by its file name.
1219// It also updates the HTTP code and sets the Content-Type as "text/html".

binding/binding.go1

55:6exported-declaration-commentexported type should have a comment beginning with its name

binding/binding.go:55:6

54// https://github.com/go-playground/validator/tree/v10.6.1.
55type StructValidator interface {
56 // ValidateStruct can receive any kind of type and it should never panic, even if the configuration is not right.

debug.go1

1:1formatfile is not formatted

debug.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt debug.go`

recovery_test.go1

323:45insecure-url-schemeURL uses insecure http scheme

recovery_test.go:323:45

322 req: func() *http.Request {
323 r, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
324 r.Header.Set("authorization", "some-secret")

binding/binding_test.go1

837:7max-public-structsfile declares more than 5 exported structs

binding/binding_test.go:837:7

836func TestUriInnerBinding(t *testing.T) {
837 type Tag struct {
838 Name string `uri:"name"`

gin.go1

506:2modifies-parameterassignment modifies parameter n

gin.go:506:2

505 n.path = strings.ReplaceAll(n.path, escapedColon, colon)
506 n.fullPath = strings.ReplaceAll(n.fullPath, escapedColon, colon)
507 n.indices = strings.ReplaceAll(n.indices, backslash, colon)

binding/form_mapping_test.go1

44:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:44:17

43 {"base type", struct{ F float32 }{}, "9.1", float32(9.1)},
44 {"base type", struct{ F float64 }{}, "9.1", float64(9.1)},
45 {"base type", struct{ F string }{}, "test", string("test")},

render/text.go1

37:3no-naked-returnreturn values must be explicit

render/text.go:37:3

36 _, err = fmt.Fprintf(w, format, data...)
37 return
38 }

binding/binding_nomsgpack.go1

81:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:81:2

80 ProtoBuf = protobufBinding{}
81 YAML = yamlBinding{}
82 Uri = uriBinding{}

tree.go1

616:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:616:7

615 // additional trailing slash
616 if path == "/" && n.wildChild && n.nType != root {
617 value.tsr = true

context.go1

5:9package-commentspackage should have a documentation comment

context.go:5:9

4
5package gin
6

binding/form_mapping_test.go1

44:47redundant-conversionconversion from float64 to the identical type is redundant

binding/form_mapping_test.go:44:47

43 {"base type", struct{ F float32 }{}, "9.1", float32(9.1)},
44 {"base type", struct{ F float64 }{}, "9.1", float64(9.1)},
45 {"base type", struct{ F string }{}, "test", string("test")},

logger.go1

114:2single-case-switchswitch with one case can be replaced by an if statement

logger.go:114:2

113 latency := p.Latency
114 switch {
115 case latency < time.Millisecond*100:

binding/binding_test.go1

265:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:265:6

264
265func TestBindingFormDefaultValue2(t *testing.T) {
266 testFormBindingDefaultValue(t, http.MethodGet,

logger.go1

19:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

logger.go:19:1

18
19const (
20 autoColor consoleColorModeValue = iota

mode.go1

99:24unchecked-type-assertionuse the checked two-result form of the type assertion

mode.go:99:24

98func Mode() string {
99 return modeName.Load().(string)
100}

codec/json/go_json.go1

28:7unused-receiverreceiver j is unused

codec/json/go_json.go:28:7

27
28func (j gojsonApi) Unmarshal(data []byte, v any) error {
29 return json.Unmarshal(data, v)

binding/binding_test.go1

549:48add-constantstring literal "/?foo=getfoo&bar=getbar" appears more than twice; define a constant

binding/binding_test.go:549:48

548
549 req, err2 := http.NewRequest(http.MethodPost, "/?foo=getfoo&bar=getbar", body)
550 require.NoError(t, err2)

tree.go1

288:16cognitive-complexityfunction has cognitive complexity 26; maximum is 7

tree.go:288:16

287
288func (n *node) insertChild(path string, fullPath string, handlers HandlersChain) {
289 for {

binding/form_mapping_test.go1

950:17discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:950:17

949
950 expected, _ := convertToOidUnmarshalText(val)
951 assert.Equal(t, expected, s.FileData)

context.go1

1357:1doc-comment-perioddocumentation comment should end with punctuation

context.go:1357:1

1356
1357// FileAttachment writes the specified file into the body stream in an efficient way
1358// On the client side, the file will typically be downloaded with the given filename

binding/binding.go1

72:5exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:72:5

71// under the hood.
72var Validator StructValidator = &defaultValidator{}
73

debug_test.go1

1:1formatfile is not formatted

debug_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt debug_test.go`

recovery_test.go1

333:45insecure-url-schemeURL uses insecure http scheme

recovery_test.go:333:45

332 req: func() *http.Request {
333 r, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
334 r.Header.Set("AuThOrIzAtIoN", "token123")

render/json.go1

46:6max-public-structsfile declares more than 5 exported structs

render/json.go:46:6

45// PureJSON contains the given interface object.
46type PureJSON struct {
47 Data any

gin.go1

507:2modifies-parameterassignment modifies parameter n

gin.go:507:2

506 n.fullPath = strings.ReplaceAll(n.fullPath, escapedColon, colon)
507 n.indices = strings.ReplaceAll(n.indices, backslash, colon)
508 if n.children == nil {

binding/form_mapping_test.go1

45:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:45:17

44 {"base type", struct{ F float64 }{}, "9.1", float64(9.1)},
45 {"base type", struct{ F string }{}, "test", string("test")},
46 {"base type", struct{ F *int }{}, "9", intPtr(9)},

render/text.go1

40:2no-naked-returnreturn values must be explicit

render/text.go:40:2

39 _, err = w.Write(bytesconv.StringToBytes(format))
40 return
41}

binding/binding_nomsgpack.go1

82:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:82:2

81 YAML = yamlBinding{}
82 Uri = uriBinding{}
83 Header = headerBinding{}

tree.go1

631:18optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:631:18

630 n = n.children[i]
631 value.tsr = (len(n.path) == 1 && n.handlers != nil) ||
632 (n.nType == catchAll && n.children[0].handlers != nil)

context_appengine.go1

7:9package-commentspackage should have a documentation comment

context_appengine.go:7:9

6
7package gin
8

binding/form_mapping_test.go1

45:47redundant-conversionconversion from string to the identical type is redundant

binding/form_mapping_test.go:45:47

44 {"base type", struct{ F float64 }{}, "9.1", float64(9.1)},
45 {"base type", struct{ F string }{}, "test", string("test")},
46 {"base type", struct{ F *int }{}, "9", intPtr(9)},

logger.go1

136:2single-case-switchswitch with one case can be replaced by an if statement

logger.go:136:2

135
136 switch method {
137 case http.MethodGet:

binding/binding_test.go1

271:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:271:6

270
271func TestBindingFormForTime(t *testing.T) {
272 testFormBindingForTime(t, http.MethodPost,

path_test.go1

20:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

path_test.go:20:1

19
20var cleanTests = []cleanPathTest{
21 // Already clean

recovery_test.go1

204:28unchecked-type-assertionuse the checked two-result form of the type assertion

recovery_test.go:204:28

203 handleRecovery := func(c *Context, err any) {
204 errBuffer.WriteString(err.(string))
205 c.AbortWithStatus(http.StatusBadRequest)

codec/json/go_json.go1

32:7unused-receiverreceiver j is unused

codec/json/go_json.go:32:7

31
32func (j gojsonApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {
33 return json.MarshalIndent(v, prefix, indent)

binding/binding_test.go1

566:20add-constantstring literal "form.go" appears more than twice; define a constant

binding/binding_test.go:566:20

565
566 f, err := os.Open("form.go")
567 require.NoError(t, err)

tree.go1

418:16cognitive-complexityfunction has cognitive complexity 196; maximum is 7

tree.go:418:16

417// given path.
418func (n *node) getValue(path string, params *Params, skippedNodes *[]skippedNode, unescape bool) (value nodeValue) {
419 var globalParamsCount int16

binding/form_mapping_test.go1

962:17discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:962:17

961
962 expected, _ := convertToOidUnmarshalText(val)
963 assert.Equal(t, expected, s.FileData)

context.go1

1376:1doc-comment-perioddocumentation comment should end with punctuation

context.go:1376:1

1375
1376// Stream sends a streaming response and returns a boolean
1377// indicates "Is client disconnected in middle of stream"

binding/binding.go1

77:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:77:2

76var (
77 JSON BindingBody = jsonBinding{}
78 XML BindingBody = xmlBinding{}

deprecated.go1

1:1formatfile is not formatted

deprecated.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt deprecated.go`

recovery_test.go1

343:45insecure-url-schemeURL uses insecure http scheme

recovery_test.go:343:45

342 req: func() *http.Request {
343 r, _ := http.NewRequest(http.MethodGet, "http://example.com", nil)
344 r.Header.Set("Content-Type", "application/json")

gin.go1

686:2modifies-parameterassignment modifies parameter c

gin.go:686:2

685
686 c.index = oldIndexValue
687 c.handlers = oldHandlers

binding/form_mapping_test.go1

46:17nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:46:17

45 {"base type", struct{ F string }{}, "test", string("test")},
46 {"base type", struct{ F *int }{}, "9", intPtr(9)},
47

response_writer.go1

88:2no-naked-returnreturn values must be explicit

response_writer.go:88:2

87 w.size += n
88 return
89}

binding/binding_nomsgpack.go1

83:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:83:2

82 Uri = uriBinding{}
83 Header = headerBinding{}
84 TOML = tomlBinding{}

tree.go1

631:19optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:631:19

630 n = n.children[i]
631 value.tsr = (len(n.path) == 1 && n.handlers != nil) ||
632 (n.nType == catchAll && n.children[0].handlers != nil)

debug.go1

5:9package-commentspackage should have a documentation comment

debug.go:5:9

4
5package gin
6

binding/form_mapping_test.go1

49:41redundant-conversionconversion from int to the identical type is redundant

binding/form_mapping_test.go:49:41

48 // zero values
49 {"zero value", struct{ F int }{}, "", int(0)},
50 {"zero value", struct{ F uint }{}, "", uint(0)},

logger.go1

176:2single-case-switchswitch with one case can be replaced by an if statement

logger.go:176:2

175
176 switch {
177 case param.Latency > time.Minute:

binding/binding_test.go1

289:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:289:6

288
289func TestBindingFormForTime2(t *testing.T) {
290 testFormBindingForTime(t, http.MethodGet,

render/bson.go1

18:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/bson.go:18:1

17
18var bsonContentType = []string{"application/bson"}
19

recovery_test.go1

239:28unchecked-type-assertionuse the checked two-result form of the type assertion

recovery_test.go:239:28

238 handleRecovery := func(c *Context, err any) {
239 errBuffer.WriteString(err.(string))
240 c.AbortWithStatus(http.StatusBadRequest)

codec/json/go_json.go1

36:7unused-receiverreceiver j is unused

codec/json/go_json.go:36:7

35
36func (j gojsonApi) NewEncoder(writer io.Writer) Encoder {
37 return json.NewEncoder(writer)

binding/binding_test.go1

582:14add-constantstring literal "--testboundary" appears more than twice; define a constant

binding/binding_test.go:582:14

581func createFormMultipartRequest(t *testing.T) *http.Request {
582 boundary := "--testboundary"
583 body := new(bytes.Buffer)

tree.go1

703:16cognitive-complexityfunction has cognitive complexity 186; maximum is 7

tree.go:703:16

702// Recursive case-insensitive lookup function used by n.findCaseInsensitivePath
703func (n *node) findCaseInsensitivePathRec(path string, ciPath []byte, rb [4]byte, fixTrailingSlash bool) []byte {
704 npLen := len(n.path)

binding/form_mapping_test.go1

967:12discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:967:12

966func TestMappingCustomArrayOfArrayUnmarshalTextUri(t *testing.T) {
967 id1, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80e`)
968 id2, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80f`)

context_file_test.go1

11:1doc-comment-perioddocumentation comment should end with punctuation

context_file_test.go:11:1

10
11// TestContextFileSimple tests the Context.File() method with a simple case
12func TestContextFileSimple(t *testing.T) {

binding/binding.go1

78:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:78:2

77 JSON BindingBody = jsonBinding{}
78 XML BindingBody = xmlBinding{}
79 Form Binding = formBinding{}

deprecated_test.go1

1:1formatfile is not formatted

deprecated_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt deprecated_test.go`

gin.go1

687:2modifies-parameterassignment modifies parameter c

gin.go:687:2

686 c.index = oldIndexValue
687 c.handlers = oldHandlers
688}

binding/form_mapping_test.go1

49:18nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:49:18

48 // zero values
49 {"zero value", struct{ F int }{}, "", int(0)},
50 {"zero value", struct{ F uint }{}, "", uint(0)},

response_writer.go1

95:2no-naked-returnreturn values must be explicit

response_writer.go:95:2

94 w.size += n
95 return
96}

binding/binding_nomsgpack.go1

84:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:84:2

83 Header = headerBinding{}
84 TOML = tomlBinding{}
85 Plain = plainBinding{}

tree.go1

643:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:643:5

642 value.tsr = path == "/" ||
643 (len(prefix) == len(path)+1 && prefix[len(path)] == '/' &&
644 path == prefix[:len(prefix)-1] && n.handlers != nil)

deprecated.go1

5:9package-commentspackage should have a documentation comment

deprecated.go:5:9

4
5package gin
6

binding/form_mapping_test.go1

50:42redundant-conversionconversion from uint to the identical type is redundant

binding/form_mapping_test.go:50:42

49 {"zero value", struct{ F int }{}, "", int(0)},
50 {"zero value", struct{ F uint }{}, "", uint(0)},
51 {"zero value", struct{ F bool }{}, "", false},

mode.go1

67:2single-case-switchswitch with one case can be replaced by an if statement

mode.go:67:2

66
67 switch value {
68 case DebugMode:

binding/binding_test.go1

307:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:307:6

306
307func TestFormBindingIgnoreField(t *testing.T) {
308 testFormBindingIgnoreField(t, http.MethodPost,

render/html.go1

51:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/html.go:51:1

50
51var htmlContentType = []string{"text/html; charset=utf-8"}
52

recovery_test.go1

274:28unchecked-type-assertionuse the checked two-result form of the type assertion

recovery_test.go:274:28

273 handleRecovery := func(c *Context, err any) {
274 errBuffer.WriteString(err.(string))
275 c.AbortWithStatus(http.StatusBadRequest)

codec/json/go_json.go1

40:7unused-receiverreceiver j is unused

codec/json/go_json.go:40:7

39
40func (j gojsonApi) NewDecoder(reader io.Reader) Decoder {
41 return json.NewDecoder(reader)

binding/binding_test.go1

592:55add-constantstring literal "; boundary=" appears more than twice; define a constant

binding/binding_test.go:592:55

591 require.NoError(t, err)
592 req.Header.Set("Content-Type", MIMEMultipartPOSTForm+"; boundary="+boundary)
593 return req

tree_test.go1

41:6cognitive-complexityfunction has cognitive complexity 19; maximum is 7

tree_test.go:41:6

40
41func checkRequests(t *testing.T, tree *node, requests testRequests, unescapes ...bool) {
42 unescape := false

binding/form_mapping_test.go1

968:12discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:968:12

967 id1, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80e`)
968 id2, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80f`)
969

context_file_test.go1

26:1doc-comment-perioddocumentation comment should end with punctuation

context_file_test.go:26:1

25
26// TestContextFileNotFound tests serving a non-existent file
27func TestContextFileNotFound(t *testing.T) {

binding/binding.go1

79:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:79:2

78 XML BindingBody = xmlBinding{}
79 Form Binding = formBinding{}
80 Query Binding = queryBinding{}

errors.go1

1:1formatfile is not formatted

errors.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt errors.go`

gin.go1

717:4modifies-parameterassignment modifies parameter c

gin.go:717:4

716 if value.params != nil {
717 c.Params = *value.params
718 }

binding/form_mapping_test.go1

50:18nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:50:18

49 {"zero value", struct{ F int }{}, "", int(0)},
50 {"zero value", struct{ F uint }{}, "", uint(0)},
51 {"zero value", struct{ F bool }{}, "", false},

test_helpers.go1

22:2no-naked-returnreturn values must be explicit

test_helpers.go:22:2

21 c.writermem.reset(w)
22 return
23}

binding/binding_nomsgpack.go1

85:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:85:2

84 TOML = tomlBinding{}
85 Plain = plainBinding{}
86 BSON BindingBody = bsonBinding{}

tree.go1

643:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:643:5

642 value.tsr = path == "/" ||
643 (len(prefix) == len(path)+1 && prefix[len(path)] == '/' &&
644 path == prefix[:len(prefix)-1] && n.handlers != nil)

errors.go1

5:9package-commentspackage should have a documentation comment

errors.go:5:9

4
5package gin
6

binding/form_mapping_test.go1

52:45redundant-conversionconversion from float32 to the identical type is redundant

binding/form_mapping_test.go:52:45

51 {"zero value", struct{ F bool }{}, "", false},
52 {"zero value", struct{ F float32 }{}, "", float32(0)},
53 {"file value", struct{ F *multipart.FileHeader }{}, "", &multipart.FileHeader{}},

path.go1

62:3single-case-switchswitch with one case can be replaced by an if statement

path.go:62:3

61 for r < n {
62 switch {
63 case p[r] == '/':

binding/binding_test.go1

313:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:313:6

312
313func TestBindingFormInvalidName(t *testing.T) {
314 testFormBindingInvalidName(t, http.MethodPost,

render/json.go1

50:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/json.go:50:1

49
50var (
51 jsonContentType = []string{"application/json; charset=utf-8"}

render/protobuf.go1

24:36unchecked-type-assertionuse the checked two-result form of the type assertion

render/protobuf.go:24:36

23
24 bytes, err := proto.Marshal(r.Data.(proto.Message))
25 if err != nil {

codec/json/json.go1

23:7unused-receiverreceiver j is unused

codec/json/json.go:23:7

22
23func (j jsonApi) Marshal(v any) ([]byte, error) {
24 return json.Marshal(v)

binding/binding_test.go1

604:47add-constantstring literal "/?map_foo=getfoo" appears more than twice; define a constant

binding/binding_test.go:604:47

603 require.NoError(t, mw.WriteField("map_foo", "{\"bar\":123, \"name\":\"thinkerou\", \"pai\": 3.14}"))
604 req, err := http.NewRequest(http.MethodPost, "/?map_foo=getfoo", body)
605 require.NoError(t, err)

tree_test.go1

376:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

tree_test.go:376:6

375
376func testRoutes(t *testing.T, routes []testRoute) {
377 tree := &node{}

binding/form_mapping_test.go1

979:12discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:979:12

978func TestMappingCustomArrayOfArrayUnmarshalTextForm(t *testing.T) {
979 id1, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80e`)
980 id2, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80f`)

context_test.go1

80:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:80:1

79
80// TestContextFile tests the Context.File() method
81func TestContextFile(t *testing.T) {

binding/binding.go1

80:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:80:2

79 Form Binding = formBinding{}
80 Query Binding = queryBinding{}
81 FormPost Binding = formPostBinding{}

errors_test.go1

1:1formatfile is not formatted

errors_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt errors_test.go`

gin.go1

720:4modifies-parameterassignment modifies parameter c

gin.go:720:4

719 if value.handlers != nil {
720 c.handlers = value.handlers
721 c.fullPath = value.fullPath

binding/form_mapping_test.go1

51:18nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:51:18

50 {"zero value", struct{ F uint }{}, "", uint(0)},
51 {"zero value", struct{ F bool }{}, "", false},
52 {"zero value", struct{ F float32 }{}, "", float32(0)},

test_helpers.go1

34:2no-naked-returnreturn values must be explicit

test_helpers.go:34:2

33 c.writermem.reset(w)
34 return
35}

binding/binding_nomsgpack.go1

86:2no-package-varpackage variables introduce mutable global state

binding/binding_nomsgpack.go:86:2

85 Plain = plainBinding{}
86 BSON BindingBody = bsonBinding{}
87)

tree.go1

643:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:643:5

642 value.tsr = path == "/" ||
643 (len(prefix) == len(path)+1 && prefix[len(path)] == '/' &&
644 path == prefix[:len(prefix)-1] && n.handlers != nil)

fs.go1

5:9package-commentspackage should have a documentation comment

fs.go:5:9

4
5package gin
6

context_test.go1

312:18redundant-conversionconversion from os.FileMode to the identical type is redundant

context_test.go:312:18

311 require.NoError(t, err)
312 assert.Equal(t, os.FileMode(0o700), info.Mode().Perm(),
313 "permissions of a pre-existing directory must not be modified")

routergroup_test.go1

59:2single-case-switchswitch with one case can be replaced by an if statement

routergroup_test.go:59:2

58
59 switch method {
60 case http.MethodGet:

binding/binding_test.go1

319:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:319:6

318
319func TestBindingFormInvalidName2(t *testing.T) {
320 testFormBindingInvalidName2(t, http.MethodPost,

render/msgpack.go1

26:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/msgpack.go:26:1

25
26var msgpackContentType = []string{"application/msgpack; charset=utf-8"}
27

utils_test.go1

122:29unchecked-type-assertionuse the checked two-result form of the type assertion

utils_test.go:122:29

121 called = true
122 value = c.MustGet(BindKey).(*bindTestStruct)
123 })

codec/json/json.go1

27:7unused-receiverreceiver j is unused

codec/json/json.go:27:7

26
27func (j jsonApi) Unmarshal(data []byte, v any) error {
28 return json.Unmarshal(data, v)

binding/binding_test.go1

826:18add-constantstring literal "thinkerou" appears more than twice; define a constant

binding/binding_test.go:826:18

825 require.NoError(t, b.BindUri(m, &tag))
826 assert.Equal(t, "thinkerou", tag.Name)
827

tree_test.go1

570:6cognitive-complexityfunction has cognitive complexity 15; maximum is 7

tree_test.go:570:6

569
570func TestTreeTrailingSlashRedirect(t *testing.T) {
571 tree := &node{}

binding/form_mapping_test.go1

980:12discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:980:12

979 id1, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80e`)
980 id2, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80f`)
981

context_test.go1

1146:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1146:1

1145
1146// Tests that the response is serialized as JSON
1147// and Content-Type is set to application/json

binding/binding.go1

81:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:81:2

80 Query Binding = queryBinding{}
81 FormPost Binding = formPostBinding{}
82 FormMultipart Binding = formMultipartBinding{}

fs.go1

1:1formatfile is not formatted

fs.go:1:1

1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt fs.go`

gin.go1

721:4modifies-parameterassignment modifies parameter c

gin.go:721:4

720 c.handlers = value.handlers
721 c.fullPath = value.fullPath
722 c.Next()

binding/form_mapping_test.go1

52:18nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:52:18

51 {"zero value", struct{ F bool }{}, "", false},
52 {"zero value", struct{ F float32 }{}, "", float32(0)},
53 {"file value", struct{ F *multipart.FileHeader }{}, "", &multipart.FileHeader{}},

tree.go1

42:2no-naked-returnreturn values must be explicit

tree.go:42:2

41 va, _ = ps.Get(name)
42 return
43}

binding/form_mapping.go1

23:2no-package-varpackage variables introduce mutable global state

binding/form_mapping.go:23:2

22var (
23 errUnknownType = errors.New("unknown type")
24

tree.go1

726:10optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:726:10

725 n = n.children[i]
726 if (len(n.path) == 1 && n.handlers != nil) ||
727 (n.nType == catchAll && n.children[0].handlers != nil) {

gin.go1

5:9package-commentspackage should have a documentation comment

gin.go:5:9

4
5package gin
6

context_test.go1

392:4redundant-conversionconversion from int32 to the identical type is redundant

context_test.go:392:4

391 {1},
392 {int32(1)},
393 {int64(1)},

tree.go1

276:4single-case-switchswitch with one case can be replaced by an if statement

tree.go:276:4

275 for end, c := range []byte(path[start+1:]) {
276 switch c {
277 case '/':

binding/binding_test.go1

325:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:325:6

324
325func TestBindingFormForType(t *testing.T) {
326 testFormBindingForType(t, http.MethodPost,

render/pdf.go1

14:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/pdf.go:14:1

13
14var pdfContentType = []string{"application/pdf"}
15

codec/json/json.go1

31:7unused-receiverreceiver j is unused

codec/json/json.go:31:7

30
31func (j jsonApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {
32 return json.MarshalIndent(v, prefix, indent)

binding/binding_test.go1

848:3add-constantstring literal "name" appears more than twice; define a constant

binding/binding_test.go:848:3

847 m := map[string][]string{
848 "name": {expectedName},
849 "age": {strconv.Itoa(expectedAge)},

tree_test.go1

714:6cognitive-complexityfunction has cognitive complexity 27; maximum is 7

tree_test.go:714:6

713
714func TestTreeFindCaseInsensitivePath(t *testing.T) {
715 tree := &node{}

binding/form_mapping_test.go1

991:12discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:991:12

990func TestMappingCustomArrayOfArrayUnmarshalTextDefault(t *testing.T) {
991 id1, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80e`)
992 id2, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80f`)

context_test.go1

1160:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1160:1

1159
1160// Tests that the response is serialized as JSONP
1161// and Content-Type is set to application/javascript

binding/binding.go1

82:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:82:2

81 FormPost Binding = formPostBinding{}
82 FormMultipart Binding = formMultipartBinding{}
83 ProtoBuf BindingBody = protobufBinding{}

fs_test.go1

1:1formatfile is not formatted

fs_test.go:1:1

1package gin
2
  • Fix (safe): run `strider fmt fs_test.go`

gin.go1

751:4modifies-parameterassignment modifies parameter c

gin.go:751:4

750 if len(allowed) > 0 {
751 c.handlers = engine.allNoMethod
752 c.writermem.Header().Set("Allow", strings.Join(allowed, ", "))

binding/form_mapping_test.go1

53:18nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:53:18

52 {"zero value", struct{ F float32 }{}, "", float32(0)},
53 {"file value", struct{ F *multipart.FileHeader }{}, "", &multipart.FileHeader{}},
54 } {

tree_test.go1

368:2no-naked-returnreturn values must be explicit

tree_test.go:368:2

367 testFunc()
368 return
369}

binding/form_mapping.go1

26:2no-package-varpackage variables introduce mutable global state

binding/form_mapping.go:26:2

25 // ErrConvertMapStringSlice can not convert to map[string][]string
26 ErrConvertMapStringSlice = errors.New("can not convert to map slices of strings")
27

tree.go1

726:11optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:726:11

725 n = n.children[i]
726 if (len(n.path) == 1 && n.handlers != nil) ||
727 (n.nType == catchAll && n.children[0].handlers != nil) {

ginS/gins.go1

5:9package-commentspackage should have a documentation comment

ginS/gins.go:5:9

4
5package ginS
6

context_test.go1

393:4redundant-conversionconversion from int64 to the identical type is redundant

context_test.go:393:4

392 {int32(1)},
393 {int64(1)},
394 {uint(1)},

tree.go1

486:5single-case-switchswitch with one case can be replaced by an if statement

tree.go:486:5

485
486 switch n.nType {
487 case param:

binding/binding_test.go1

371:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:371:6

370
371func TestBindingFormStringMap(t *testing.T) {
372 testBodyBindingStringMap(t, Form,

render/protobuf.go1

18:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/protobuf.go:18:1

17
18var protobufContentType = []string{"application/x-protobuf"}
19

codec/json/json.go1

35:7unused-receiverreceiver j is unused

codec/json/json.go:35:7

34
35func (j jsonApi) NewEncoder(writer io.Writer) Encoder {
36 return json.NewEncoder(writer)

binding/binding_test.go1

896:18add-constantstring literal "form" appears more than twice; define a constant

binding/binding_test.go:896:18

895 b := Form
896 assert.Equal(t, "form", b.Name())
897

tree_test.go1

1022:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

tree_test.go:1022:6

1021
1022func TestTreeFindCaseInsensitivePathWithMultipleChildrenAndWildcard(t *testing.T) {
1023 tree := &node{}

binding/form_mapping_test.go1

992:12discarded-error-resulterror result returned by convertToOidUnmarshalText is discarded

binding/form_mapping_test.go:992:12

991 id1, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80e`)
992 id2, _ := convertToOidUnmarshalText(`664a062ac74a8ad104e0e80f`)
993

context_test.go1

1174:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1174:1

1173
1174// Tests that the response is serialized as JSONP
1175// and Content-Type is set to application/json

binding/binding.go1

83:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:83:2

82 FormMultipart Binding = formMultipartBinding{}
83 ProtoBuf BindingBody = protobufBinding{}
84 MsgPack BindingBody = msgpackBinding{}

gin.go2

1:1formatfile is not formatted

gin.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt gin.go`
758:2modifies-parameterassignment modifies parameter c

gin.go:758:2

757
758 c.handlers = engine.allNoRoute
759 serveError(c, http.StatusNotFound, default404Body)

binding/form_mapping_test.go1

72:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:72:8

71func TestMappingDefault(t *testing.T) {
72 var s struct {
73 Str string `form:",default=defaultVal"`

binding/form_mapping.go1

29:2no-package-varpackage variables introduce mutable global state

binding/form_mapping.go:29:2

28 // ErrConvertToMapString can not convert to map[string]string
29 ErrConvertToMapString = errors.New("can not convert to map of strings")
30)

tree.go1

815:7optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:815:7

814 // without a trailing slash if a leaf exists for that path
815 if fixTrailingSlash && path == "/" && n.handlers != nil {
816 return ciPath

internal/bytesconv/bytesconv.go1

5:9package-commentspackage should have a documentation comment

internal/bytesconv/bytesconv.go:5:9

4
5package bytesconv
6

context_test.go1

394:4redundant-conversionconversion from uint to the identical type is redundant

context_test.go:394:4

393 {int64(1)},
394 {uint(1)},
395 {float32(1)},

tree.go1

688:2single-case-switchswitch with one case can be replaced by an if statement

tree.go:688:2

687func shiftNRuneBytes(rb [4]byte, n int) [4]byte {
688 switch n {
689 case 0:

binding/binding_test.go1

381:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:381:6

380
381func TestBindingFormStringSliceMap(t *testing.T) {
382 obj := make(map[string][]string)

render/render.go1

17:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/render.go:17:1

16
17var (
18 _ Render = (*JSON)(nil)

codec/json/json.go1

39:7unused-receiverreceiver j is unused

codec/json/json.go:39:7

38
39func (j jsonApi) NewDecoder(reader io.Reader) Decoder {
40 return json.NewDecoder(reader)

binding/binding_test.go1

926:70add-constantstring literal "foo=bar" appears more than twice; define a constant

binding/binding_test.go:926:70

925 obj := FooBarStruct{}
926 req, err := http.NewRequest(http.MethodPost, "/", strings.NewReader("foo=bar"))
927 require.NoError(t, err)

tree_test.go1

1066:6cognitive-complexityfunction has cognitive complexity 13; maximum is 7

tree_test.go:1066:6

1065
1066func TestTreeFindCaseInsensitivePathWildcardParamAndStaticChild(t *testing.T) {
1067 tree := &node{}

context.go1

718:2discarded-error-resulterror result returned by f.Close is discarded

context.go:718:2

717 }
718 f.Close()
719 return fh, err

context_test.go1

1188:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1188:1

1187
1188// Tests that no JSON is rendered if code is 204
1189func TestContextRenderNoContentJSON(t *testing.T) {

binding/binding.go1

84:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:84:2

83 ProtoBuf BindingBody = protobufBinding{}
84 MsgPack BindingBody = msgpackBinding{}
85 YAML BindingBody = yamlBinding{}

ginS/gins_test.go1

1:1formatfile is not formatted

ginS/gins_test.go:1:1

1// Copyright 2025 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt ginS/gins_test.go`

gin.go1

765:2modifies-parameterassignment modifies parameter c

gin.go:765:2

764func serveError(c *Context, code int, defaultMessage []byte) {
765 c.writermem.status = code
766 c.Next()

binding/form_mapping_test.go1

88:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:88:8

87func TestMappingSkipField(t *testing.T) {
88 var s struct {
89 A int

binding/form_mapping.go1

44:5no-package-varpackage variables introduce mutable global state

binding/form_mapping.go:44:5

43
44var emptyField = reflect.StructField{}
45

tree.go1

891:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:891:8

890 end := 0
891 for end < len(path) && path[end] != '/' {
892 end++

internal/fs/fs.go1

1:9package-commentspackage should have a documentation comment

internal/fs/fs.go:1:9

1package fs
2

context_test.go1

395:4redundant-conversionconversion from float32 to the identical type is redundant

context_test.go:395:4

394 {uint(1)},
395 {float32(1)},
396 {key{}},

tree.go1

887:3single-case-switchswitch with one case can be replaced by an if statement

tree.go:887:3

886 n = n.children[len(n.children)-1]
887 switch n.nType {
888 case param:

binding/binding_test.go1

402:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:402:6

401
402func TestBindingQuery(t *testing.T) {
403 testQueryBinding(t, http.MethodPost,

render/render_msgpack_test.go1

63:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/render_msgpack_test.go:63:1

62
63type failWriter struct {
64 *httptest.ResponseRecorder

codec/json/jsoniter.go1

26:7unused-receiverreceiver j is unused

codec/json/jsoniter.go:26:7

25
26func (j jsoniterApi) Marshal(v any) ([]byte, error) {
27 return json.Marshal(v)

binding/binding_test.go1

947:18add-constantstring literal "multipart/form-data" appears more than twice; define a constant

binding/binding_test.go:947:18

946 b := FormMultipart
947 assert.Equal(t, "multipart/form-data", b.Name())
948

context.go1

824:3discarded-error-resulterror result returned by c.AbortWithError(http.StatusBadRequest, err).SetType is discarded

context.go:824:3

823 if err := c.ShouldBindUri(obj); err != nil {
824 c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) //nolint: errcheck
825 return err

context_test.go1

1200:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1200:1

1199
1200// Tests that the response is serialized as JSON
1201// we change the content-type before

binding/binding.go1

85:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:85:2

84 MsgPack BindingBody = msgpackBinding{}
85 YAML BindingBody = yamlBinding{}
86 Uri BindingUri = uriBinding{}

gin_integration_test.go1

1:1formatfile is not formatted

gin_integration_test.go:1:1

1// Copyright 2017 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt gin_integration_test.go`

gin.go1

771:3modifies-parameterassignment modifies parameter c

gin.go:771:3

770 if c.writermem.Status() == code {
771 c.writermem.Header()["Content-Type"] = mimePlain
772 _, err := c.Writer.Write(defaultMessage)

binding/form_mapping_test.go1

98:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:98:8

97func TestMappingIgnoreField(t *testing.T) {
98 var s struct {
99 A int `form:"A"`

binding/form_mapping_benchmark_test.go1

14:5no-package-varpackage variables introduce mutable global state

binding/form_mapping_benchmark_test.go:14:5

13
14var form = map[string][]string{
15 "name": {"mike"},

tree.go1

944:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:944:6

943 }
944 if len(path)+1 == npLen && n.path[len(path)] == '/' &&
945 strings.EqualFold(path[1:], n.path[1:len(path)]) && n.handlers != nil {

logger.go1

5:9package-commentspackage should have a documentation comment

logger.go:5:9

4
5package gin
6

context_test.go1

423:17redundant-conversionconversion from int32 to the identical type is redundant

context_test.go:423:17

422 c.Set("string", "this is a string")
423 c.Set("int32", int32(-42))
424 c.Set("int64", int64(42424242424242))

utils.go1

148:2single-case-switchswitch with one case can be replaced by an if statement

utils.go:148:2

147func resolveAddress(addr []string) string {
148 switch len(addr) {
149 case 0:

binding/binding_test.go1

408:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:408:6

407
408func TestBindingQuery2(t *testing.T) {
409 testQueryBinding(t, http.MethodGet,

render/render_test.go1

139:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/render_test.go:139:1

138
139type errorWriter struct {
140 bufString string

codec/json/jsoniter.go1

30:7unused-receiverreceiver j is unused

codec/json/jsoniter.go:30:7

29
30func (j jsoniterApi) Unmarshal(data []byte, v any) error {
31 return json.Unmarshal(data, v)

binding/binding_test.go1

1115:7add-constantstring literal "Slice" appears more than twice; define a constant

binding/binding_test.go:1115:7

1114 switch typ {
1115 case "Slice":
1116 obj := FooStructForSliceType{}

context.go1

843:4discarded-error-resulterror result returned by c.AbortWithError(http.StatusRequestEntityTooLarge, err).SetType is discarded

context.go:843:4

842 case errors.As(err, &maxBytesErr):
843 c.AbortWithError(http.StatusRequestEntityTooLarge, err).SetType(ErrorTypeBind) //nolint: errcheck
844 default:

context_test.go1

1214:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1214:1

1213
1214// Tests that no Custom JSON is rendered if code is 204
1215func TestContextRenderNoContentAPIJSON(t *testing.T) {

binding/binding.go1

86:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:86:2

85 YAML BindingBody = yamlBinding{}
86 Uri BindingUri = uriBinding{}
87 Header Binding = headerBinding{}

gin_test.go1

1:1formatfile is not formatted

gin_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt gin_test.go`

mode.go1

61:4modifies-parameterassignment modifies parameter value

mode.go:61:4

60 if flag.Lookup("test.v") != nil {
61 value = TestMode
62 } else {

binding/form_mapping_test.go1

110:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:110:8

109func TestMappingUnexportedField(t *testing.T) {
110 var s struct {
111 A int `form:"a"`

binding/json.go1

19:5no-package-varpackage variables introduce mutable global state

binding/json.go:19:5

18// any as a Number instead of as a float64.
19var EnableDecoderUseNumber = false
20

tree.go1

944:6optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

tree.go:944:6

943 }
944 if len(path)+1 == npLen && n.path[len(path)] == '/' &&
945 strings.EqualFold(path[1:], n.path[1:len(path)]) && n.handlers != nil {

mode.go1

5:9package-commentspackage should have a documentation comment

mode.go:5:9

4
5package gin
6

context_test.go1

424:17redundant-conversionconversion from int64 to the identical type is redundant

context_test.go:424:17

423 c.Set("int32", int32(-42))
424 c.Set("int64", int64(42424242424242))
425 c.Set("uint64", uint64(42))

binding/binding_test.go1

414:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:414:6

413
414func TestBindingQueryFail(t *testing.T) {
415 testQueryBindingFail(t, http.MethodPost,

render/text.go1

20:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/text.go:20:1

19
20var plainContentType = []string{"text/plain; charset=utf-8"}
21

codec/json/jsoniter.go1

34:7unused-receiverreceiver j is unused

codec/json/jsoniter.go:34:7

33
34func (j jsoniterApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {
35 return json.MarshalIndent(v, prefix, indent)

binding/binding_test.go1

1125:7add-constantstring literal "Struct" appears more than twice; define a constant

binding/binding_test.go:1125:7

1124 require.Error(t, err)
1125 case "Struct":
1126 obj := FooStructForStructType{}

context.go1

845:4discarded-error-resulterror result returned by c.AbortWithError(http.StatusBadRequest, err).SetType is discarded

context.go:845:4

844 default:
845 c.AbortWithError(http.StatusBadRequest, err).SetType(ErrorTypeBind) //nolint: errcheck
846 }

context_test.go1

1227:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1227:1

1226
1227// Tests that the response is serialized as JSON
1228// and Content-Type is set to application/json

binding/binding.go1

87:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:87:2

86 Uri BindingUri = uriBinding{}
87 Header Binding = headerBinding{}
88 Plain BindingBody = plainBinding{}

githubapi_test.go1

1:1formatfile is not formatted

githubapi_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt githubapi_test.go`

mode.go1

63:4modifies-parameterassignment modifies parameter value

mode.go:63:4

62 } else {
63 value = DebugMode
64 }

binding/form_mapping_test.go1

122:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:122:8

121func TestMappingPrivateField(t *testing.T) {
122 var s struct {
123 f int `form:"field"`

binding/json.go1

25:5no-package-varpackage variables introduce mutable global state

binding/json.go:25:5

24// keys which do not match any non-ignored, exported fields in the destination.
25var EnableDecoderDisallowUnknownFields = false
26

path.go1

6:9package-commentspackage should have a documentation comment

path.go:6:9

5
6package gin
7

context_test.go1

425:18redundant-conversionconversion from uint64 to the identical type is redundant

context_test.go:425:18

424 c.Set("int64", int64(42424242424242))
425 c.Set("uint64", uint64(42))
426 c.Set("float32", float32(4.2))

binding/binding_test.go1

420:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:420:6

419
420func TestBindingQueryFail2(t *testing.T) {
421 testQueryBindingFail(t, http.MethodGet,

render/toml.go1

18:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/toml.go:18:1

17
18var tomlContentType = []string{"application/toml; charset=utf-8"}
19

codec/json/jsoniter.go1

38:7unused-receiverreceiver j is unused

codec/json/jsoniter.go:38:7

37
38func (j jsoniterApi) NewEncoder(writer io.Writer) Encoder {
39 return json.NewEncoder(writer)

binding/binding_test.go1

1134:7add-constantstring literal "StructPointer" appears more than twice; define a constant

binding/binding_test.go:1134:7

1133 obj.StructFoo)
1134 case "StructPointer":
1135 obj := FooStructForStructPointerType{}

context.go1

1197:12discarded-error-resulterror result returned by url.QueryUnescape is discarded

context.go:1197:12

1196 }
1197 val, _ := url.QueryUnescape(cookie.Value)
1198 return val, nil

context_test.go1

1240:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1240:1

1239
1240// Tests that no Custom JSON is rendered if code is 204
1241func TestContextRenderNoContentIndentedJSON(t *testing.T) {

binding/binding.go1

88:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:88:2

87 Header Binding = headerBinding{}
88 Plain BindingBody = plainBinding{}
89 TOML BindingBody = tomlBinding{}

internal/bytesconv/bytesconv.go1

1:1formatfile is not formatted

internal/bytesconv/bytesconv.go:1:1

1// Copyright 2023 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt internal/bytesconv/bytesconv.go`

path.go1

142:4modifies-parameterassignment modifies parameter buf

path.go:142:4

141 if length > cap(b) {
142 *buf = make([]byte, length)
143 } else {

binding/form_mapping_test.go1

131:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:131:8

130func TestMappingUnknownFieldType(t *testing.T) {
131 var s struct {
132 U uintptr

binding/json_test.go1

72:5no-package-varpackage variables introduce mutable global state

binding/json_test.go:72:5

71
72var customConfig = jsoniter.Config{
73 EscapeHTML: true,

recovery.go1

5:9package-commentspackage should have a documentation comment

recovery.go:5:9

4
5package gin
6

context_test.go1

426:19redundant-conversionconversion from float32 to the identical type is redundant

context_test.go:426:19

425 c.Set("uint64", uint64(42))
426 c.Set("float32", float32(4.2))
427 c.Set("float64", 4.2)

binding/binding_test.go1

426:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:426:6

425
426func TestBindingQueryBoolFail(t *testing.T) {
427 testQueryBindingBoolFail(t, http.MethodGet,

render/xml.go1

17:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/xml.go:17:1

16
17var xmlContentType = []string{"application/xml; charset=utf-8"}
18

codec/json/jsoniter.go1

42:7unused-receiverreceiver j is unused

codec/json/jsoniter.go:42:7

41
42func (j jsoniterApi) NewDecoder(reader io.Reader) Decoder {
43 return json.NewDecoder(reader)

binding/binding_test.go1

1148:7add-constantstring literal "SliceMap" appears more than twice; define a constant

binding/binding_test.go:1148:7

1147 assert.InDelta(t, float64(123), obj.MapFoo["bar"].(float64), 0.01)
1148 case "SliceMap":
1149 obj := FooStructForSliceMapType{}

context.go1

1213:7discarded-error-resulterror result returned by c.Error is discarded

context.go:1213:7

1212 // Pushing error to c.Errors
1213 _ = c.Error(err)
1214 c.Abort()

context_test.go1

1283:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1283:1

1282
1283// Tests that the response is serialized as Secure JSON
1284// and Content-Type is set to application/json

binding/binding.go1

89:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:89:2

88 Plain BindingBody = plainBinding{}
89 TOML BindingBody = tomlBinding{}
90 BSON BindingBody = bsonBinding{}

internal/bytesconv/bytesconv_test.go1

1:1formatfile is not formatted

internal/bytesconv/bytesconv_test.go:1:1

1// Copyright 2020 Gin Core Team. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt internal/bytesconv/bytesconv_test.go`

path.go1

144:4modifies-parameterassignment modifies parameter buf

path.go:144:4

143 } else {
144 *buf = (*buf)[:length]
145 }

binding/form_mapping_test.go1

141:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:141:8

140func TestMappingURI(t *testing.T) {
141 var s struct {
142 F int `uri:"field"`

binding/json_test.go1

108:2no-package-varpackage variables introduce mutable global state

binding/json_test.go:108:2

107var (
108 zeroTime = time.Time{}
109 timeType = reflect2.TypeOfPtr((*time.Time)(nil)).Elem()

render/bson.go1

5:9package-commentspackage should have a documentation comment

render/bson.go:5:9

4
5package render
6

context_test.go1

432:20redundant-conversionconversion from int32 to the identical type is redundant

context_test.go:432:20

431 assert.Exactly(t, "this is a string", c.MustGet("string").(string))
432 assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))
433 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))

binding/binding_test.go1

432:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:432:6

431
432func TestBindingQueryStringMap(t *testing.T) {
433 b := Query

render/yaml.go1

18:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

render/yaml.go:18:1

17
18var yamlContentType = []string{"application/yaml; charset=utf-8"}
19

codec/json/sonic.go1

26:7unused-receiverreceiver j is unused

codec/json/sonic.go:26:7

25
26func (j sonicApi) Marshal(v any) ([]byte, error) {
27 return json.Marshal(v)

binding/binding_test.go1

1152:7add-constantstring literal "Ptr" appears more than twice; define a constant

binding/binding_test.go:1152:7

1151 require.Error(t, err)
1152 case "Ptr":
1153 obj := FooStructForStringPtrType{}

context.go1

1445:3discarded-error-resulterror result returned by c.AbortWithError is discarded

context.go:1445:3

1444 default:
1445 c.AbortWithError(http.StatusNotAcceptable, errors.New("the accepted formats are not offered by the server")) //nolint: errcheck
1446 }

context_test.go1

1297:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1297:1

1296
1297// Tests that no Custom JSON is rendered if code is 204
1298func TestContextRenderNoContentSecureJSON(t *testing.T) {

binding/binding.go1

90:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding.go:90:2

89 TOML BindingBody = tomlBinding{}
90 BSON BindingBody = bsonBinding{}
91)

internal/fs/fs_test.go1

1:1formatfile is not formatted

internal/fs/fs_test.go:1:1

1package fs
2
  • Fix (safe): run `strider fmt internal/fs/fs_test.go`

render/render_test.go1

288:2modifies-parameterassignment modifies parameter start

render/render_test.go:288:2

287func (h xmlmap) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
288 start.Name = xml.Name{
289 Space: "",

binding/form_mapping_test.go1

150:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:150:8

149func TestMappingForm(t *testing.T) {
150 var s struct {
151 F int `form:"field"`

binding/json_test.go1

109:2no-package-varpackage variables introduce mutable global state

binding/json_test.go:109:2

108 zeroTime = time.Time{}
109 timeType = reflect2.TypeOfPtr((*time.Time)(nil)).Elem()
110 defaultTimeCodec = &timeCodec{}

render/data.go1

5:9package-commentspackage should have a documentation comment

render/data.go:5:9

4
5package render
6

context_test.go1

433:20redundant-conversionconversion from int64 to the identical type is redundant

context_test.go:433:20

432 assert.Exactly(t, int32(-42), c.MustGet("int32").(int32))
433 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))
434 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))

binding/binding_test.go1

454:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:454:6

453
454func TestBindingXML(t *testing.T) {
455 testBodyBinding(t,

response_writer.go1

55:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

response_writer.go:55:1

54
55var _ ResponseWriter = (*responseWriter)(nil)
56

codec/json/sonic.go1

30:7unused-receiverreceiver j is unused

codec/json/sonic.go:30:7

29
30func (j sonicApi) Unmarshal(data []byte, v any) error {
31 return json.Unmarshal(data, v)

binding/binding_test.go1

1206:18add-constantstring literal "query" appears more than twice; define a constant

binding/binding_test.go:1206:18

1205 b := Query
1206 assert.Equal(t, "query", b.Name())
1207

context_test.go2

160:2discarded-error-resulterror result returned by mw.Close is discarded

context_test.go:160:2

159 require.NoError(t, err)
160 mw.Close()
161 c, _ := CreateTestContext(httptest.NewRecorder())
1320:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1320:1

1319
1320// Tests that the response is serialized as JSON
1321// and Content-Type is set to application/json

binding/binding.go1

95:6exported-declaration-commentexported function or method should have a comment beginning with its name

binding/binding.go:95:6

94// and the content type.
95func Default(method, contentType string) Binding {
96 if method == http.MethodGet {

logger.go1

1:1formatfile is not formatted

logger.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt logger.go`

routergroup.go1

88:2modifies-parameterassignment modifies parameter handlers

routergroup.go:88:2

87 absolutePath := group.calculateAbsolutePath(relativePath)
88 handlers = group.combineHandlers(handlers)
89 group.engine.addRoute(httpMethod, absolutePath, handlers)

binding/form_mapping_test.go1

159:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:159:8

158func TestMappingFormFieldNotSent(t *testing.T) {
159 var s struct {
160 F string `form:"field,default=defVal"`

binding/json_test.go1

110:2no-package-varpackage variables introduce mutable global state

binding/json_test.go:110:2

109 timeType = reflect2.TypeOfPtr((*time.Time)(nil)).Elem()
110 defaultTimeCodec = &timeCodec{}
111)

render/html.go1

5:9package-commentspackage should have a documentation comment

render/html.go:5:9

4
5package render
6

context_test.go1

434:20redundant-conversionconversion from uint64 to the identical type is redundant

context_test.go:434:20

433 assert.Exactly(t, int64(42424242424242), c.MustGet("int64").(int64))
434 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))
435 assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)

binding/binding_test.go1

461:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:461:6

460
461func TestBindingXMLFail(t *testing.T) {
462 testBodyBindingFail(t,

response_writer_test.go1

38:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

response_writer_test.go:38:1

37// nonFlusherWriter is a minimal http.ResponseWriter that does NOT implement http.Flusher.
38type nonFlusherWriter struct {
39 header http.Header

codec/json/sonic.go1

34:7unused-receiverreceiver j is unused

codec/json/sonic.go:34:7

33
34func (j sonicApi) MarshalIndent(v any, prefix, indent string) ([]byte, error) {
35 return json.MarshalIndent(v, prefix, indent)

binding/binding_test.go1

1351:18add-constantstring literal "yes" appears more than twice; define a constant

binding/binding_test.go:1351:18

1350 require.NoError(t, err)
1351 assert.Equal(t, "yes", *obj.Label)
1352

context_test.go2

162:17discarded-error-resulterror result returned by http.NewRequest is discarded

context_test.go:162:17

161 c, _ := CreateTestContext(httptest.NewRecorder())
162 c.Request, _ = http.NewRequest(http.MethodPost, "/", buf)
163 c.Request.Header.Set("Content-Type", mw.FormDataContentType())
1332:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1332:1

1331
1332// Tests that the response executes the templates
1333// and responds with Content-Type set to text/html

binding/binding_nomsgpack.go1

13:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding_nomsgpack.go:13:2

12const (
13 MIMEJSON = "application/json"
14 MIMEHTML = "text/html"

logger_test.go1

1:1formatfile is not formatted

logger_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt logger_test.go`

tree.go1

179:4modifies-parameterassignment modifies parameter path

tree.go:179:4

178 if i < len(path) {
179 path = path[i:]
180 c := path[0]

binding/form_mapping_test.go1

168:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:168:8

167func TestMappingFormWithEmptyToDefault(t *testing.T) {
168 var s struct {
169 F string `form:"field,default=DefVal"`

binding/json_test.go1

165:2no-package-varpackage variables introduce mutable global state

binding/json_test.go:165:2

164var (
165 timePointerType = reflect2.TypeOfPtr((**time.Time)(nil)).Elem()
166 defaultTimePointerCodec = &timePointerCodec{}

render/json.go1

5:9package-commentspackage should have a documentation comment

render/json.go:5:9

4
5package render
6

context_test.go1

435:20redundant-conversionconversion from float32 to the identical type is redundant

context_test.go:435:20

434 assert.Exactly(t, uint64(42), c.MustGet("uint64").(uint64))
435 assert.InDelta(t, float32(4.2), c.MustGet("float32").(float32), 0.01)
436 assert.InDelta(t, 4.2, c.MustGet("float64").(float64), 0.01)

binding/binding_test.go1

468:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:468:6

467
468func TestBindingTOML(t *testing.T) {
469 testBodyBinding(t,

routergroup.go1

62:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

routergroup.go:62:1

61
62var _ IRouter = (*RouterGroup)(nil)
63

codec/json/sonic.go1

38:7unused-receiverreceiver j is unused

codec/json/sonic.go:38:7

37
38func (j sonicApi) NewEncoder(writer io.Writer) Encoder {
39 return json.NewEncoder(writer)

binding/default_validator_test.go1

68:72add-constantstring literal "12345678" appears more than twice; define a constant

binding/default_validator_test.go:68:72

67 {"validate *struct failed-1", &defaultValidator{}, &exampleStruct{A: "123456789", B: 1}, true},
68 {"validate *struct failed-2", &defaultValidator{}, &exampleStruct{A: "12345678", B: 0}, true},
69 {"validate *struct passed", &defaultValidator{}, &exampleStruct{A: "12345678", B: 1}, false},

context_test.go2

174:2discarded-error-resulterror result returned by mw.Close is discarded

context_test.go:174:2

173 mw := multipart.NewWriter(buf)
174 mw.Close()
175 c, _ := CreateTestContext(httptest.NewRecorder())
1372:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1372:1

1371
1372// Tests that no HTML is rendered if code is 204
1373func TestContextRenderNoContentHTML(t *testing.T) {

binding/binding_nomsgpack.go1

14:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding_nomsgpack.go:14:2

13 MIMEJSON = "application/json"
14 MIMEHTML = "text/html"
15 MIMEXML = "application/xml"

middleware_test.go1

1:1formatfile is not formatted

middleware_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt middleware_test.go`

tree.go1

311:5modifies-parameterassignment modifies parameter path

tree.go:311:5

310 n.path = path[:i]
311 path = path[i:]
312 }

binding/form_mapping_test.go1

177:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:177:8

176func TestMapFormWithTag(t *testing.T) {
177 var s struct {
178 F int `externalTag:"field"`

binding/json_test.go1

166:2no-package-varpackage variables introduce mutable global state

binding/json_test.go:166:2

165 timePointerType = reflect2.TypeOfPtr((**time.Time)(nil)).Elem()
166 defaultTimePointerCodec = &timePointerCodec{}
167)

render/msgpack.go1

7:9package-commentspackage should have a documentation comment

render/msgpack.go:7:9

6
7package render
8

context_test.go1

474:11redundant-conversionconversion from int8 to the identical type is redundant

context_test.go:474:11

473 key := "int8"
474 value := int8(0x7F)
475 c.Set(key, value)

binding/binding_test.go1

475:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:475:6

474
475func TestBindingTOMLFail(t *testing.T) {
476 testBodyBindingFail(t,

tree.go1

45:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

tree.go:45:1

44
45type methodTree struct {
46 method string

codec/json/sonic.go1

42:7unused-receiverreceiver j is unused

codec/json/sonic.go:42:7

41
42func (j sonicApi) NewDecoder(reader io.Reader) Decoder {
43 return json.NewDecoder(reader)

binding/default_validator_test.go1

70:75add-constantstring literal "123456789" appears more than twice; define a constant

binding/default_validator_test.go:70:75

69 {"validate *struct passed", &defaultValidator{}, &exampleStruct{A: "12345678", B: 1}, false},
70 {"validate []struct failed-1", &defaultValidator{}, []exampleStruct{{A: "123456789", B: 1}}, true},
71 {"validate []struct failed-2", &defaultValidator{}, []exampleStruct{{A: "12345678", B: 0}}, true},

context_test.go2

176:17discarded-error-resulterror result returned by http.NewRequest is discarded

context_test.go:176:17

175 c, _ := CreateTestContext(httptest.NewRecorder())
176 c.Request, _ = http.NewRequest(http.MethodPost, "/", nil)
177 c.Request.Header.Set("Content-Type", mw.FormDataContentType())
1386:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1386:1

1385
1386// TestContextRenderXML tests that the response is serialized as XML
1387// and Content-Type is set to application/xml

binding/binding_nomsgpack.go1

15:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding_nomsgpack.go:15:2

14 MIMEHTML = "text/html"
15 MIMEXML = "application/xml"
16 MIMEXML2 = "text/xml"

mode_test.go1

1:1formatfile is not formatted

mode_test.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt mode_test.go`

tree.go1

327:5modifies-parameterassignment modifies parameter path

tree.go:327:5

326 if len(wildcard) < len(path) {
327 path = path[len(wildcard):]
328

binding/form_mapping_test.go1

186:8nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:186:8

185func TestMappingTime(t *testing.T) {
186 var s struct {
187 Time time.Time

binding/multipart_form_mapping.go1

20:2no-package-varpackage variables introduce mutable global state

binding/multipart_form_mapping.go:20:2

19 // ErrMultiFileHeader multipart.FileHeader invalid
20 ErrMultiFileHeader = errors.New("unsupported field type for multipart.FileHeader")
21

render/pdf.go1

5:9package-commentspackage should have a documentation comment

render/pdf.go:5:9

4
5package render
6

context_test.go1

482:11redundant-conversionconversion from int16 to the identical type is redundant

context_test.go:482:11

481 key := "int16"
482 value := int16(0x7FFF)
483 c.Set(key, value)

binding/binding_test.go1

482:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:482:6

481
482func TestBindingYAML(t *testing.T) {
483 testBodyBinding(t,

tree_test.go1

24:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

tree_test.go:24:1

23
24type testRequests []struct {
25 path string

context.go1

734:7unused-receiverreceiver c is unused

context.go:734:7

733// modified.
734func (c *Context) SaveUploadedFile(file *multipart.FileHeader, dst string, perm ...fs.FileMode) error {
735 src, err := file.Open()

binding/form_mapping.go1

171:55add-constantstring literal "," appears more than twice; define a constant

binding/form_mapping.go:171:55

170 if cfTag == "" || cfTag == "multi" || cfTag == "csv" {
171 setOpt.defaultValue = strings.ReplaceAll(v, ";", ",")
172 }

context_test.go2

192:2discarded-error-resulterror result returned by mw.Close is discarded

context_test.go:192:2

191 require.NoError(t, err)
192 mw.Close()
193 c, _ := CreateTestContext(httptest.NewRecorder())
1399:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1399:1

1398
1399// Tests that no XML is rendered if code is 204
1400func TestContextRenderNoContentXML(t *testing.T) {

binding/binding_nomsgpack.go1

16:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding_nomsgpack.go:16:2

15 MIMEXML = "application/xml"
16 MIMEXML2 = "text/xml"
17 MIMEPlain = "text/plain"

path_test.go1

1:1formatfile is not formatted

path_test.go:1:1

1// Copyright 2013 Julien Schmidt. All rights reserved.
2// Based on the path package, Copyright 2009 The Go Authors.
  • Fix (safe): run `strider fmt path_test.go`

tree.go1

426:5modifies-parameterassignment modifies parameter path

tree.go:426:5

425 if path[:len(prefix)] == prefix {
426 path = path[len(prefix):]
427

binding/form_mapping_test.go1

216:15nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:216:15

215 // wrong location
216 var wrongLoc struct {
217 Time time.Time `time_location:"wrong"`

binding/multipart_form_mapping.go1

23:2no-package-varpackage variables introduce mutable global state

binding/multipart_form_mapping.go:23:2

22 // ErrMultiFileHeaderLenInvalid array for []*multipart.FileHeader len invalid
23 ErrMultiFileHeaderLenInvalid = errors.New("unsupported len of array for []*multipart.FileHeader")
24)

render/protobuf.go1

5:9package-commentspackage should have a documentation comment

render/protobuf.go:5:9

4
5package render
6

context_test.go1

490:11redundant-conversionconversion from int32 to the identical type is redundant

context_test.go:490:11

489 key := "int32"
490 value := int32(0x7FFFFFFF)
491 c.Set(key, value)

binding/binding_test.go1

489:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:489:6

488
489func TestBindingYAMLStringMap(t *testing.T) {
490 // YAML is a superset of JSON, so the test below is JSON (to avoid newlines)

utils.go1

61:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

utils.go:61:1

60// H is a shortcut for map[string]any
61type H map[string]any
62

fs.go1

33:7unused-receiverreceiver n is unused

fs.go:33:7

32// Readdir overrides the http.File default implementation and always returns nil.
33func (n neutralizedReaddirFile) Readdir(_ int) ([]os.FileInfo, error) {
34 // this disables directory listing

binding/form_mapping.go1

260:27add-constantstring literal "collection_format" appears more than twice; define a constant

binding/form_mapping.go:260:27

259 // pre-process the default value for multi if present
260 cfTag := field.Tag.Get("collection_format")
261 if cfTag == "" || cfTag == "multi" {

context_test.go2

194:17discarded-error-resulterror result returned by http.NewRequest is discarded

context_test.go:194:17

193 c, _ := CreateTestContext(httptest.NewRecorder())
194 c.Request, _ = http.NewRequest(http.MethodPost, "/", buf)
195 c.Request.Header.Set("Content-Type", mw.FormDataContentType())
1411:1doc-comment-perioddocumentation comment should end with punctuation

context_test.go:1411:1

1410
1411// TestContextRenderPDF tests that the response is serialized as PDF
1412// and Content-Type is set to application/pdf

binding/binding_nomsgpack.go1

17:2exported-declaration-commentexported declaration should have a comment beginning with its name

binding/binding_nomsgpack.go:17:2

16 MIMEXML2 = "text/xml"
17 MIMEPlain = "text/plain"
18 MIMEPOSTForm = "application/x-www-form-urlencoded"

recovery.go1

1:1formatfile is not formatted

recovery.go:1:1

1// Copyright 2014 Manu Martinez-Almeida. All rights reserved.
2// Use of this source code is governed by a MIT style
  • Fix (safe): run `strider fmt recovery.go`

tree.go1

435:8modifies-parameterassignment modifies parameter skippedNodes

tree.go:435:8

434 index := len(*skippedNodes)
435 *skippedNodes = (*skippedNodes)[:index+1]
436 (*skippedNodes)[index] = skippedNode{

binding/form_mapping_test.go1

223:16nested-structsmove nested anonymous struct types to named declarations

binding/form_mapping_test.go:223:16

222 // wrong time value
223 var wrongTime struct {
224 Time time.Time

codec/json/api.go1

10:5no-package-varpackage variables introduce mutable global state

codec/json/api.go:10:5

9// API the json codec in use.
10var API Core
11

render/reader.go1

5:9package-commentspackage should have a documentation comment

render/reader.go:5:9

4
5package render
6

context_test.go1

497:17redundant-conversionconversion from int64 to the identical type is redundant

context_test.go:497:17

496 c, _ := CreateTestContext(httptest.NewRecorder())
497 c.Set("int64", int64(42424242424242))
498 assert.Equal(t, int64(42424242424242), c.GetInt64("int64"))

binding/binding_test.go1

496:6test-parallelismconsider calling t.Parallel() when this test begins

binding/binding_test.go:496:6

495
496func TestBindingYAMLFail(t *testing.T) {
497 testBodyBindingFail(t,

utils_test.go1

29:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

utils_test.go:29:1

28
29type testStruct struct {
30 T *testing.T

logger.go1

157:7unused-receiverreceiver p is unused

logger.go:157:7

156// ResetColor resets all escape attributes.
157func (p *LogFormatterParams) ResetColor() string {
158 return reset

binding/form_mapping.go1

261:31add-constantstring literal "multi" appears more than twice; define a constant

binding/form_mapping.go:261:31

260 cfTag := field.Tag.Get("collection_format")
261 if cfTag == "" || cfTag == "multi" {
262 vs = strings.Split(opt.defaultValue, ",")