49 msformat290 mscheck 818total 194errors 322warnings 302notes

client.go35

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

client.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
1:1formatfile is not formatted

client.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt client.go`
5:9package-commentspackage should have a documentation comment

client.go:5:9

4
5package websocket
6
24:5exported-declaration-commentexported declaration should have a comment beginning with its name

client.go:24:5

23// invalid.
24var ErrBadHandshake = errors.New("websocket: bad handshake")
25
24:5no-package-varpackage variables introduce mutable global state

client.go:24:5

23// invalid.
24var ErrBadHandshake = errors.New("websocket: bad handshake")
25
26:5no-package-varpackage variables introduce mutable global state

client.go:26:5

25
26var errInvalidCompression = errors.New("websocket: invalid compression negotiation")
27
39:6exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:39:6

38// Deprecated: Use Dialer instead.
39func NewClient(netConn net.Conn, u *url.URL, requestHeader http.Header, readBufSize, writeBufSize int) (c *Conn, response *http.Response, err error) {
40 d := Dialer{
43:17import-shadowingidentifier net shadows an imported package

client.go:43:17

42 WriteBufferSize: writeBufSize,
43 NetDial: func(net, addr string) (net.Conn, error) {
44 return netConn, nil
53:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

client.go:53:1

52// It is safe to call Dialer's methods concurrently.
53type Dialer struct {
54 // The following custom dial functions can be set to establish
53:6exported-declaration-commentexported type should have a comment beginning with its name

client.go:53:6

52// It is safe to call Dialer's methods concurrently.
53type Dialer struct {
54 // The following custom dial functions can be set to establish
135:5no-package-varpackage variables introduce mutable global state

client.go:135:5

134
135var errMalformedURL = errors.New("malformed ws or wss URL")
136
143:3single-case-switchswitch with one case can be replaced by an if statement

client.go:143:3

142 } else {
143 switch u.Scheme {
144 case "wss":
156:5no-package-varpackage variables introduce mutable global state

client.go:156:5

155// DefaultDialer is a dialer with all fields set to the default values.
156var DefaultDialer = &Dialer{
157 Proxy: http.ProxyFromEnvironment,
162:5no-package-varpackage variables introduce mutable global state

client.go:162:5

161// nilDialer is dialer to use when receiver is nil.
162var nilDialer = *DefaultDialer
163
175:18cognitive-complexityfunction has cognitive complexity 60; maximum is 7

client.go:175:18

174// need to be closed by the application.
175func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
176 if d == nil {
175:18cyclomatic-complexityfunction complexity is 60; maximum is 10

client.go:175:18

174// need to be closed by the application.
175func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
176 if d == nil {
175:18exported-declaration-commentexported function or method should have a comment beginning with its name

client.go:175:18

174// need to be closed by the application.
175func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
176 if d == nil {
175:18function-lengthfunction has 108 statements and 225 lines; maximum is 50 statements or 75 lines

client.go:175:18

174// need to be closed by the application.
175func (d *Dialer) DialContext(ctx context.Context, urlStr string, requestHeader http.Header) (*Conn, *http.Response, error) {
176 if d == nil {
190:2single-case-switchswitch with one case can be replaced by an if statement

client.go:190:2

189
190 switch u.Scheme {
191 case "ws":
234:3single-case-switchswitch with one case can be replaced by an if statement

client.go:234:3

233 for k, vs := range requestHeader {
234 switch {
235 case k == "Host":
239:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:239:8

238 }
239 case k == "Upgrade" ||
240 k == "Connection" ||
239:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:239:8

238 }
239 case k == "Upgrade" ||
240 k == "Connection" ||
239:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:239:8

238 }
239 case k == "Upgrade" ||
240 k == "Connection" ||
239:13add-constantstring literal "Upgrade" appears more than twice; define a constant

client.go:239:13

238 }
239 case k == "Upgrade" ||
240 k == "Connection" ||
259:3modifies-parameterassignment modifies parameter ctx

client.go:259:3

258 var cancel func()
259 ctx, cancel = context.WithTimeout(ctx, d.HandshakeTimeout)
260 defer cancel()
299:8discarded-error-resulterror result returned by netConn.Close is discarded

client.go:299:8

298 // application.
299 _ = netConn.Close()
300 }
304:36add-constantstring literal "https" appears more than twice; define a constant

client.go:304:36

303 // Do TLS handshake over established connection if a proxy exists.
304 if proxyURL != nil && u.Scheme == "https" {
305
360:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

client.go:360:5

359
360 if resp.StatusCode != 101 ||
361 !tokenListContainsValue(resp.Header, "Upgrade", "websocket") ||
362:40add-constantstring literal "Connection" appears more than twice; define a constant

client.go:362:40

361 !tokenListContainsValue(resp.Header, "Upgrade", "websocket") ||
362 !tokenListContainsValue(resp.Header, "Connection", "upgrade") ||
363 resp.Header.Get("Sec-Websocket-Accept") != computeAcceptKey(challengeKey) {
368:11discarded-error-resulterror result returned by io.ReadFull is discarded

client.go:368:11

367 buf := make([]byte, 1024)
368 n, _ := io.ReadFull(resp.Body, buf)
369 resp.Body = io.NopCloser(bytes.NewReader(buf[:n]))
388:37add-constantstring literal "Sec-Websocket-Protocol" appears more than twice; define a constant

client.go:388:37

387 resp.Body = io.NopCloser(bytes.NewReader([]byte{}))
388 conn.subprotocol = resp.Header.Get("Sec-Websocket-Protocol")
389
428:2single-case-switchswitch with one case can be replaced by an if statement

client.go:428:2

427 var netDial netDialerFunc
428 switch {
429 case d.NetDialContext != nil:
432:39import-shadowingidentifier net shadows an imported package

client.go:432:39

431 case d.NetDial != nil:
432 netDial = func(ctx context.Context, net, addr string) (net.Conn, error) {
433 return d.NetDial(net, addr)
477:4discarded-error-resulterror result returned by tlsConn.Close is discarded

client.go:477:4

476 if err != nil {
477 tlsConn.Close()
478 return nil, err
493:4discarded-error-resulterror result returned by c.Close is discarded

client.go:493:4

492 if err != nil {
493 c.Close()
494 return nil, err

client_proxy_server_test.go96

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

client_proxy_server_test.go:1:1

1// Copyright 2025 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
1:1formatfile is not formatted

client_proxy_server_test.go:1:1

1// Copyright 2025 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt client_proxy_server_test.go`
38:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:38:1

37
38// Permutation 1
39//
42:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:42:6

41// Proxy: HTTP
42func TestHTTPProxyAndBackend(t *testing.T) {
43 websocketTLS := false
47:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:47:2

46 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
47 defer websocketServer.Close()
48 if err != nil {
53:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:53:2

52 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
53 defer proxyServer.Close()
54 if err != nil {
69:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:69:13

68 // Validate the proxy server was called.
69 if e, a := int64(1), proxyServer.numCalls(); e != a {
70 t.Errorf("proxy not called")
74:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:74:1

73
74// Permutation 2
75//
79:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:79:6

78// DialFn: NetDial (dials proxy)
79func TestHTTPProxyWithNetDial(t *testing.T) {
80 websocketTLS := false
84:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:84:2

83 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
84 defer websocketServer.Close()
85 if err != nil {
90:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:90:2

89 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
90 defer proxyServer.Close()
91 if err != nil {
110:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:110:13

109 sendReceiveData(t, wsClient)
110 if e, a := int64(1), netDialCalled.Load(); e != a {
111 t.Errorf("netDial not called")
114:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:114:13

113 // Validate the proxy server was called.
114 if e, a := int64(1), proxyServer.numCalls(); e != a {
115 t.Errorf("proxy not called")
119:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:119:1

118
119// Permutation 3
120//
124:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:124:6

123// DialFn: NetDialContext (dials proxy)
124func TestHTTPProxyWithNetDialContext(t *testing.T) {
125 websocketTLS := false
129:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:129:2

128 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
129 defer websocketServer.Close()
130 if err != nil {
131:12add-constantstring literal "error starting websocket server: %v" appears more than twice; define a constant

client_proxy_server_test.go:131:12

130 if err != nil {
131 t.Fatalf("error starting websocket server: %v", err)
132 }
135:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:135:2

134 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
135 defer proxyServer.Close()
136 if err != nil {
137:12add-constantstring literal "error starting proxy server: %v" appears more than twice; define a constant

client_proxy_server_test.go:137:12

136 if err != nil {
137 t.Fatalf("error starting proxy server: %v", err)
138 }
151:12add-constantstring literal "websocket dial error: %v" appears more than twice; define a constant

client_proxy_server_test.go:151:12

150 if err != nil {
151 t.Fatalf("websocket dial error: %v", err)
152 }
155:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:155:13

154 sendReceiveData(t, wsClient)
155 if e, a := int64(1), netDialCalled.Load(); e != a {
156 t.Errorf("netDial not called")
159:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:159:13

158 // Validate the proxy server was called.
159 if e, a := int64(1), proxyServer.numCalls(); e != a {
160 t.Errorf("proxy not called")
160:12add-constantstring literal "proxy not called" appears more than twice; define a constant

client_proxy_server_test.go:160:12

159 if e, a := int64(1), proxyServer.numCalls(); e != a {
160 t.Errorf("proxy not called")
161 }
164:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:164:1

163
164// Permutation 4
165//
170:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:170:6

169// TLS Config: set (used for backend TLS)
170func TestHTTPProxyWithHTTPSBackend(t *testing.T) {
171 websocketTLS := true
175:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:175:2

174 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
175 defer websocketServer.Close()
176 if err != nil {
181:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:181:2

180 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
181 defer proxyServer.Close()
182 if err != nil {
205:12error-stringserror string should not be capitalized or end with punctuation

client_proxy_server_test.go:205:12

204 if numTLSDials := netDialTLSCalled.Load(); numTLSDials > 0 {
205 t.Errorf("NetDialTLS should have been ignored")
206 }
208:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:208:13

207 // Validate the proxy server was called.
208 if e, a := int64(1), proxyServer.numCalls(); e != a {
209 t.Errorf("proxy not called")
213:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:213:1

212
213// Permutation 5
214//
218:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:218:6

217// TLS Config: set (used for both proxy and backend TLS)
218func TestHTTPSProxyAndBackend(t *testing.T) {
219 websocketTLS := true
223:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:223:2

222 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
223 defer websocketServer.Close()
224 if err != nil {
229:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:229:2

228 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
229 defer proxyServer.Close()
230 if err != nil {
245:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:245:13

244 // Validate the proxy server was called.
245 if e, a := int64(1), proxyServer.numCalls(); e != a {
246 t.Errorf("proxy not called")
250:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:250:1

249
250// Permutation 6
251//
256:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:256:6

255// TLS Config: set (used for both proxy and backend TLS)
256func TestHTTPSProxyUsingNetDial(t *testing.T) {
257 websocketTLS := true
261:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:261:2

260 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
261 defer websocketServer.Close()
262 if err != nil {
267:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:267:2

266 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
267 defer proxyServer.Close()
268 if err != nil {
287:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:287:13

286 sendReceiveData(t, wsClient)
287 if e, a := int64(1), netDialCalled.Load(); e != a {
288 t.Errorf("netDial not called")
288:12add-constantstring literal "netDial not called" appears more than twice; define a constant

client_proxy_server_test.go:288:12

287 if e, a := int64(1), netDialCalled.Load(); e != a {
288 t.Errorf("netDial not called")
289 }
291:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:291:13

290 // Validate the proxy server was called.
291 if e, a := int64(1), proxyServer.numCalls(); e != a {
292 t.Errorf("proxy not called")
296:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:296:1

295
296// Permutation 7
297//
302:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:302:6

301// TLS Config: set (used for both proxy and backend TLS)
302func TestHTTPSProxyUsingNetDialContext(t *testing.T) {
303 websocketTLS := true
307:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:307:2

306 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
307 defer websocketServer.Close()
308 if err != nil {
313:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:313:2

312 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
313 defer proxyServer.Close()
314 if err != nil {
333:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:333:13

332 sendReceiveData(t, wsClient)
333 if e, a := int64(1), netDialCalled.Load(); e != a {
334 t.Errorf("netDial not called")
337:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:337:13

336 // Validate the proxy server was called.
337 if e, a := int64(1), proxyServer.numCalls(); e != a {
338 t.Errorf("proxy not called")
342:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:342:1

341
342// Permutation 8
343//
348:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:348:6

347// TLS Config: set (used for backend TLS)
348func TestHTTPSProxyUsingNetDialTLSContext(t *testing.T) {
349 websocketTLS := true
353:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:353:2

352 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
353 defer websocketServer.Close()
354 if err != nil {
359:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:359:2

358 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
359 defer proxyServer.Close()
360 if err != nil {
393:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:393:13

392 sendReceiveData(t, wsClient)
393 if e, a := int64(1), proxyDialCalled.Load(); e != a {
394 t.Errorf("netDial not called")
397:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:397:13

396 // Validate the proxy server was called.
397 if e, a := int64(1), proxyServer.numCalls(); e != a {
398 t.Errorf("proxy not called")
402:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:402:1

401
402// Permutation 9
403//
407:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:407:6

406// TLS Config: set (used for proxy TLS)
407func TestHTTPSProxyHTTPBackend(t *testing.T) {
408 websocketTLS := false
412:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:412:2

411 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
412 defer websocketServer.Close()
413 if err != nil {
418:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:418:2

417 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
418 defer proxyServer.Close()
419 if err != nil {
434:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:434:13

433 // Validate the proxy server was called.
434 if e, a := int64(1), proxyServer.numCalls(); e != a {
435 t.Errorf("proxy not called")
439:1doc-comment-perioddocumentation comment should end with punctuation

client_proxy_server_test.go:439:1

438
439// Permutation 10
440//
445:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:445:6

444// TLS Config: set (ignored)
445func TestHTTPSProxyUsingNetDialTLSContextWithHTTPBackend(t *testing.T) {
446 websocketTLS := false
450:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:450:2

449 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
450 defer websocketServer.Close()
451 if err != nil {
456:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:456:2

455 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
456 defer proxyServer.Close()
457 if err != nil {
476:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:476:13

475 sendReceiveData(t, wsClient)
476 if e, a := int64(1), proxyDialCalled.Load(); e != a {
477 t.Errorf("netDial not called")
480:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:480:13

479 // Validate the proxy server was called.
480 if e, a := int64(1), proxyServer.numCalls(); e != a {
481 t.Errorf("proxy not called")
485:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

client_proxy_server_test.go:485:6

484
485func TestTLSValidationErrors(t *testing.T) {
486 // Both websocket and proxy servers are started with TLS.
485:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:485:6

484
485func TestTLSValidationErrors(t *testing.T) {
486 // Both websocket and proxy servers are started with TLS.
490:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:490:2

489 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
490 defer websocketServer.Close()
491 if err != nil {
495:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:495:2

494 proxyServer, proxyServerURL, err := newProxyServer(proxyTLS)
495 defer proxyServer.Close()
496 if err != nil {
514:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:514:13

513 // server TLS validation failed).
514 if e, a := int64(0), proxyServer.numCalls(); e != a {
515 t.Errorf("proxy should not have been called")
531:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:531:13

530 // websocket server failed TLS validation).
531 if e, a := int64(1), proxyServer.numCalls(); e != a {
532 t.Errorf("proxy have been called")
536:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:536:6

535
536func TestProxyFnErrorIsPropagated(t *testing.T) {
537 websocketServer, websocketURL, err := newWebsocketServer(false)
538:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:538:2

537 websocketServer, websocketURL, err := newWebsocketServer(false)
538 defer websocketServer.Close()
539 if err != nil {
559:6test-parallelismconsider calling t.Parallel() when this test begins

client_proxy_server_test.go:559:6

558
559func TestProxyFnNilMeansNoProxy(t *testing.T) {
560 // Both websocket and proxy servers are started.
564:2defer-close-before-error-checkcheck the error from newWebsocketServer before deferring websocketServer.Close

client_proxy_server_test.go:564:2

563 websocketServer, websocketURL, err := newWebsocketServer(websocketTLS)
564 defer websocketServer.Close()
565 if err != nil {
569:2defer-close-before-error-checkcheck the error from newProxyServer before deferring proxyServer.Close

client_proxy_server_test.go:569:2

568 proxyServer, _, err := newProxyServer(proxyTLS)
569 defer proxyServer.Close()
570 if err != nil {
578:4nil-value-with-nil-errornil payload is returned with a nil error; return a meaningful value or a descriptive error

client_proxy_server_test.go:578:4

577 Proxy: func(r *http.Request) (*url.URL, error) {
578 return nil, nil
579 },
589:13redundant-conversionconversion from int64 to the identical type is redundant

client_proxy_server_test.go:589:13

588 // URL generation returned nil).
589 if e, a := int64(0), proxyServer.numCalls(); e != a {
590 t.Errorf("proxy should not have been called")
596:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

client_proxy_server_test.go:596:1

595// of the number of times a handler was called, as well as "Close".
596type counter interface {
597 increment()
620:23exported-declaration-commentexported function or method should have a comment beginning with its name

client_proxy_server_test.go:620:23

619
620func (ts *testServer) Close() {
621 if ts.server != nil {
628:5no-package-varpackage variables introduce mutable global state

client_proxy_server_test.go:628:5

627// echoes binary messages read off the websocket connection back to the client.
628var websocketEchoHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
629 upgrader := Upgrader{
668:25flag-parameterboolean parameter tlsServer controls function flow

client_proxy_server_test.go:668:25

667// func newWebsocketServer(tlsServer bool) (*httptest.Server, *url.URL, error) {
668func newWebsocketServer(tlsServer bool) (closer, *url.URL, error) {
669 // Start the websocket server, which echoes data back to sender.
698:5no-package-varpackage variables introduce mutable global state

client_proxy_server_test.go:698:5

697// to the "Host". Creates two goroutines to copy between connections in each direction.
698var proxyHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
699 // Validate the CONNECT method.
714:21unchecked-type-assertionuse the checked two-result form of the type assertion

client_proxy_server_test.go:714:21

713 // Hijack client connection.
714 client, _, err := w.(http.Hijacker).Hijack()
715 if err != nil {
721:20nested-structsmove nested anonymous struct types to named declarations

client_proxy_server_test.go:721:20

720 // Create duplex streaming between client and upstream connections.
721 done := make(chan struct{}, 2)
722 go func() {
723:10discarded-error-resulterror result returned by io.Copy is discarded

client_proxy_server_test.go:723:10

722 go func() {
723 _, _ = io.Copy(upstream, client)
724 done <- struct{}{}
724:11nested-structsmove nested anonymous struct types to named declarations

client_proxy_server_test.go:724:11

723 _, _ = io.Copy(upstream, client)
724 done <- struct{}{}
725 }()
727:10discarded-error-resulterror result returned by io.Copy is discarded

client_proxy_server_test.go:727:10

726 go func() {
727 _, _ = io.Copy(client, upstream)
728 done <- struct{}{}
728:11nested-structsmove nested anonymous struct types to named declarations

client_proxy_server_test.go:728:11

727 _, _ = io.Copy(client, upstream)
728 done <- struct{}{}
729 }()
736:21flag-parameterboolean parameter tlsServer controls function flow

client_proxy_server_test.go:736:21

735// times the proxy handler was called with this server.
736func newProxyServer(tlsServer bool) (counter, *url.URL, error) {
737 // Start the proxy server, keeping track of how many times the handler is called.
764:16flag-parameterboolean parameter websocketTLS controls function flow

client_proxy_server_test.go:764:16

763// neither websocket nor proxy server uses TLS, returns nil.
764func tlsConfig(websocketTLS bool, proxyTLS bool) *tls.Config {
765 if !websocketTLS && !proxyTLS {
764:35flag-parameterboolean parameter proxyTLS controls function flow

client_proxy_server_test.go:764:35

763// neither websocket nor proxy server uses TLS, returns nil.
764func tlsConfig(websocketTLS bool, proxyTLS bool) *tls.Config {
765 if !websocketTLS && !proxyTLS {
798:2overwritten-before-usethis value of err is overwritten before use

client_proxy_server_test.go:798:2

797 // read data is the same as the previously sent data.
798 _, received, err := wsConn.ReadMessage()
799 if !bytes.Equal(randomData, received) {
810:5no-package-varpackage variables introduce mutable global state

client_proxy_server_test.go:810:5

809// proxyServerCert is a self-signed.
810var proxyServerCert = []byte(`-----BEGIN CERTIFICATE-----
811MIIDGTCCAgGgAwIBAgIRALL5AZcefF4kkYV1SEG6YrMwDQYJKoZIhvcNAQELBQAw
831:5no-package-varpackage variables introduce mutable global state

client_proxy_server_test.go:831:5

830// proxyServerKey is the private key for proxyServerCert.
831var proxyServerKey = []byte(`-----BEGIN RSA PRIVATE KEY-----
832MIIEogIBAAKCAQEAtD8UdzJXB0UfEBFtsPYoG0NRPsSeL7yKg12O0Zya1eoG/jkQ
861:5no-package-varpackage variables introduce mutable global state

client_proxy_server_test.go:861:5

860// websocketServerCert is self-signed.
861var websocketServerCert = []byte(`-----BEGIN CERTIFICATE-----
862MIIDOTCCAiGgAwIBAgIQYSN1VY/favsLUo+B7gJ5tTANBgkqhkiG9w0BAQsFADAS
883:5no-package-varpackage variables introduce mutable global state

client_proxy_server_test.go:883:5

882// websocketServerKey is the private key for websocketServerCert.
883var websocketServerKey = []byte(`-----BEGIN PRIVATE KEY-----
884MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCkGWKe2OQvV87V

client_server_test.go128

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

client_server_test.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
1:1formatfile is not formatted

client_server_test.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt client_server_test.go`
32:5no-package-varpackage variables introduce mutable global state

client_server_test.go:32:5

31
32var cstUpgrader = Upgrader{
33 Subprotocols: []string{"p0", "p1"},
42:5no-package-varpackage variables introduce mutable global state

client_server_test.go:42:5

41
42var cstDialer = Dialer{
43 Subprotocols: []string{"p1", "p2"},
60:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

client_server_test.go:60:1

59
60const (
61 cstPath = "/a/b"
66:21exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:66:21

65
66func (s *cstServer) Close() {
67 s.Server.Close()
88:21cognitive-complexityfunction has cognitive complexity 9; maximum is 7

client_server_test.go:88:21

87
88func (t cstHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
89 // Because tests wait for a response from a server, we are guaranteed that
120:3discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:120:3

119 t.Logf("Subprotocol() = %s, want p1", ws.Subprotocol())
120 ws.Close()
121 return
167:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:167:6

166
167func TestProxyDial(t *testing.T) {
168
172:13discarded-error-resulterror result returned by url.Parse is discarded

client_server_test.go:172:13

171
172 surl, _ := url.Parse(s.Server.URL)
173
205:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:205:6

204
205func TestProxyAuthorizationDial(t *testing.T) {
206 s := newServer(t)
209:13discarded-error-resulterror result returned by url.Parse is discarded

client_server_test.go:209:13

208
209 surl, _ := url.Parse(s.Server.URL)
210 surl.User = url.UserPassword("username", "password")
245:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:245:6

244
245func TestDial(t *testing.T) {
246 s := newServer(t)
251:12add-constantstring literal "Dial: %v" appears more than twice; define a constant

client_server_test.go:251:12

250 if err != nil {
251 t.Fatalf("Dial: %v", err)
252 }
257:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

client_server_test.go:257:6

256
257func TestDialCookieJar(t *testing.T) {
258 s := newServer(t)
257:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:257:6

256
257func TestDialCookieJar(t *testing.T) {
258 s := newServer(t)
261:12discarded-error-resulterror result returned by cookiejar.New is discarded

client_server_test.go:261:12

260
261 jar, _ := cookiejar.New(nil)
262 d := cstDialer
265:10discarded-error-resulterror result returned by url.Parse is discarded

client_server_test.go:265:10

264
265 u, _ := url.Parse(s.URL)
266
267:2single-case-switchswitch with one case can be replaced by an if statement

client_server_test.go:267:2

266
267 switch u.Scheme {
268 case "ws":
274:53add-constantstring literal "ws" appears more than twice; define a constant

client_server_test.go:274:53

273
274 cookies := []*http.Cookie{{Name: "gorilla", Value: "ws", Path: "/"}}
275 d.Jar.SetCookies(u, cookies)
319:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:319:6

318
319func TestDialTLS(t *testing.T) {
320 s := newTLSServer(t)
333:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:333:6

332
333func TestDialTimeout(t *testing.T) {
334 s := newServer(t)
341:3discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:341:3

340 if err == nil {
341 ws.Close()
342 t.Fatalf("Dial: nil")
355:34exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:355:34

354
355func (c *requireDeadlineNetConn) SetDeadline(t time.Time) error {
356 c.writeDeadlineIsSet = !t.Equal(time.Time{})
361:34exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:361:34

360
361func (c *requireDeadlineNetConn) SetReadDeadline(t time.Time) error {
362 c.readDeadlineIsSet = !t.Equal(time.Time{})
366:34exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:366:34

365
366func (c *requireDeadlineNetConn) SetWriteDeadline(t time.Time) error {
367 c.writeDeadlineIsSet = !t.Equal(time.Time{})
385:34exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:385:34

384
385func (c *requireDeadlineNetConn) Close() error { return c.c.Close() }
386func (c *requireDeadlineNetConn) LocalAddr() net.Addr { return c.c.LocalAddr() }
386:34exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:386:34

385func (c *requireDeadlineNetConn) Close() error { return c.c.Close() }
386func (c *requireDeadlineNetConn) LocalAddr() net.Addr { return c.c.LocalAddr() }
387func (c *requireDeadlineNetConn) RemoteAddr() net.Addr { return c.c.RemoteAddr() }
387:34exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:387:34

386func (c *requireDeadlineNetConn) LocalAddr() net.Addr { return c.c.LocalAddr() }
387func (c *requireDeadlineNetConn) RemoteAddr() net.Addr { return c.c.RemoteAddr() }
388
389:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:389:6

388
389func TestHandshakeTimeout(t *testing.T) {
390 s := newServer(t)
402:2discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:402:2

401 }
402 ws.Close()
403}
405:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:405:6

404
405func TestHandshakeTimeoutInContext(t *testing.T) {
406 s := newServer(t)
423:2discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:423:2

422 }
423 ws.Close()
424}
426:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:426:6

425
426func TestDialBadScheme(t *testing.T) {
427 s := newServer(t)
432:3discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:432:3

431 if err == nil {
432 ws.Close()
433 t.Fatalf("Dial: nil")
437:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:437:6

436
437func TestDialBadOrigin(t *testing.T) {
438 s := newServer(t)
443:3discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:443:3

442 if err == nil {
443 ws.Close()
444 t.Fatalf("Dial: nil")
444:12add-constantstring literal "Dial: nil" appears more than twice; define a constant

client_server_test.go:444:12

443 ws.Close()
444 t.Fatalf("Dial: nil")
445 }
449:10possible-nil-dereferencepointer is dereferenced on a path where its nil check does not prove it is non-nil

client_server_test.go:449:10

448 }
449 if resp.StatusCode != http.StatusForbidden {
450 t.Fatalf("status=%d, want %d", resp.StatusCode, http.StatusForbidden)
450:39possible-nil-dereferencepointer is dereferenced on a path where its nil check does not prove it is non-nil

client_server_test.go:450:39

449 if resp.StatusCode != http.StatusForbidden {
450 t.Fatalf("status=%d, want %d", resp.StatusCode, http.StatusForbidden)
451 }
454:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:454:6

453
454func TestDialBadHeader(t *testing.T) {
455 s := newServer(t)
465:62add-constantstring literal "bad" appears more than twice; define a constant

client_server_test.go:465:62

464 h.Set(k, "bad")
465 ws, _, err := cstDialer.Dial(s.URL, http.Header{"Origin": {"bad"}})
466 if err == nil {
467:4discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:467:4

466 if err == nil {
467 ws.Close()
468 t.Errorf("Dial with header %s returned nil", k)
468:13error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:468:13

467 ws.Close()
468 t.Errorf("Dial with header %s returned nil", k)
469 }
473:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:473:6

472
473func TestBadMethod(t *testing.T) {
474 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
478:4discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:478:4

477 t.Errorf("handshake succeeded, expect fail")
478 ws.Close()
479 }
495:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_server_test.go:495:2

494 }
495 resp.Body.Close()
496 if resp.StatusCode != http.StatusMethodNotAllowed {
497:12error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:497:12

496 if resp.StatusCode != http.StatusMethodNotAllowed {
497 t.Errorf("Status = %d, want %d", resp.StatusCode, http.StatusMethodNotAllowed)
498 }
507:4discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:507:4

506 t.Errorf("handshake succeeded, expect fail")
507 ws.Close()
508 }
516:17add-constantstring literal "Connection" appears more than twice; define a constant

client_server_test.go:516:17

515 }
516 req.Header.Set("Connection", "upgrade")
517 req.Header.Set("Sec-Websocket-Version", "13")
517:17add-constantstring literal "Sec-Websocket-Version" appears more than twice; define a constant

client_server_test.go:517:17

516 req.Header.Set("Connection", "upgrade")
517 req.Header.Set("Sec-Websocket-Version", "13")
518
523:2discarded-error-resulterror result returned by resp.Body.Close is discarded

client_server_test.go:523:2

522 }
523 resp.Body.Close()
524 if u := resp.Header.Get("Upgrade"); u != "websocket" {
524:26add-constantstring literal "Upgrade" appears more than twice; define a constant

client_server_test.go:524:26

523 resp.Body.Close()
524 if u := resp.Header.Get("Upgrade"); u != "websocket" {
525 t.Errorf("Upgrade response header is %q, want %q", u, "websocket")
525:12error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:525:12

524 if u := resp.Header.Get("Upgrade"); u != "websocket" {
525 t.Errorf("Upgrade response header is %q, want %q", u, "websocket")
526 }
525:57add-constantstring literal "websocket" appears more than twice; define a constant

client_server_test.go:525:57

524 if u := resp.Header.Get("Upgrade"); u != "websocket" {
525 t.Errorf("Upgrade response header is %q, want %q", u, "websocket")
526 }
528:12error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:528:12

527 if resp.StatusCode != http.StatusUpgradeRequired {
528 t.Errorf("Status = %d, want %d", resp.StatusCode, http.StatusUpgradeRequired)
529 }
532:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:532:6

531
532func TestDialExtraTokensInRespHeaders(t *testing.T) {
533 s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
549:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:549:6

548
549func TestHandshake(t *testing.T) {
550 s := newServer(t)
553:53add-constantstring literal "Origin" appears more than twice; define a constant

client_server_test.go:553:53

552
553 ws, resp, err := cstDialer.Dial(s.URL, http.Header{"Origin": {s.URL}})
554 if err != nil {
575:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:575:6

574
575func TestRespOnBadHandshake(t *testing.T) {
576 const expectedStatus = http.StatusGone
581:10discarded-error-resulterror result returned by io.WriteString is discarded

client_server_test.go:581:10

580 w.WriteHeader(expectedStatus)
581 _, _ = io.WriteString(w, expectedBody)
582 }))
587:3discarded-error-resulterror result returned by ws.Close is discarded

client_server_test.go:587:3

586 if err == nil {
587 ws.Close()
588 t.Fatalf("Dial: nil")
595:10possible-nil-dereferencepointer is dereferenced on a path where its nil check does not prove it is non-nil

client_server_test.go:595:10

594
595 if resp.StatusCode != expectedStatus {
596 t.Errorf("resp.StatusCode=%d, want %d", resp.StatusCode, expectedStatus)
596:48possible-nil-dereferencepointer is dereferenced on a path where its nil check does not prove it is non-nil

client_server_test.go:596:48

595 if resp.StatusCode != expectedStatus {
596 t.Errorf("resp.StatusCode=%d, want %d", resp.StatusCode, expectedStatus)
597 }
599:28possible-nil-dereferencepointer is dereferenced on a path where its nil check does not prove it is non-nil

client_server_test.go:599:28

598
599 p, err := io.ReadAll(resp.Body)
600 if err != nil {
619:6cognitive-complexityfunction has cognitive complexity 19; maximum is 7

client_server_test.go:619:6

618// TestHost tests handling of host names and confirms that it matches net/http.
619func TestHost(t *testing.T) {
620
619:6cyclomatic-complexityfunction complexity is 16; maximum is 10

client_server_test.go:619:6

618// TestHost tests handling of host names and confirms that it matches net/http.
619func TestHost(t *testing.T) {
620
619:6function-lengthfunction has 51 statements and 180 lines; maximum is 50 statements or 75 lines

client_server_test.go:619:6

618// TestHost tests handling of host names and confirms that it matches net/http.
619func TestHost(t *testing.T) {
620
619:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:619:6

618// TestHost tests handling of host names and confirms that it matches net/http.
619func TestHost(t *testing.T) {
620
628:4discarded-error-resulterror result returned by c.Close is discarded

client_server_test.go:628:4

627 }
628 c.Close()
629 } else {
641:50insecure-url-schemeURL uses insecure ws scheme

client_server_test.go:641:50

640 addrs := map[*httptest.Server]string{server: server.Listener.Addr().String(), tlsServer: tlsServer.Listener.Addr().String()}
641 wsProtos := map[*httptest.Server]string{server: "ws://", tlsServer: "wss://"}
642 httpProtos := map[*httptest.Server]string{server: "http://", tlsServer: "https://"}
642:52insecure-url-schemeURL uses insecure http scheme

client_server_test.go:642:52

641 wsProtos := map[*httptest.Server]string{server: "ws://", tlsServer: "wss://"}
642 httpProtos := map[*httptest.Server]string{server: "http://", tlsServer: "https://"}
643
650:13nested-structsmove nested anonymous struct types to named declarations

client_server_test.go:650:13

649
650 tests := []struct {
651 fail bool // true if dial / get should fail
653:3import-shadowingidentifier url shadows an imported package

client_server_test.go:653:3

652 server *httptest.Server // server to use
653 url string // host for request URI
654 header string // optional request host header
655:3import-shadowingidentifier tls shadows an imported package

client_server_test.go:655:3

654 header string // optional request host header
655 tls string // optional host for tls ServerName
656 wantAddr string // expected host for dial
683:16add-constantstring literal "badhost.com" appears more than twice; define a constant

client_server_test.go:683:16

682 url: addrs[tlsServer],
683 header: "badhost.com",
684 wantAddr: addrs[tlsServer],
706:16add-constantstring literal "example.com" appears more than twice; define a constant

client_server_test.go:706:16

705 url: "badhost.com",
706 header: "example.com",
707 wantAddr: "badhost.com:80",
728:16add-constantstring literal "badhost.com:443" appears more than twice; define a constant

client_server_test.go:728:16

727 tls: "example.com",
728 wantAddr: "badhost.com:443",
729 wantHeader: "badhost.com",
735:3import-shadowingidentifier tls shadows an imported package

client_server_test.go:735:3

734
735 tls := &tls.Config{
736 RootCAs: cas,
735:10range-value-addresstaking the address of range value tt can be misleading

client_server_test.go:735:10

734
735 tls := &tls.Config{
736 RootCAs: cas,
743:13range-value-captureclosure captures reused range variable tt

client_server_test.go:743:13

742 dialer := Dialer{
743 NetDial: func(network, addr string) (net.Conn, error) {
744 gotAddr = addr
758:4discarded-error-resulterror result returned by c.Close is discarded

client_server_test.go:758:4

757 if err == nil {
758 c.Close()
759 }
761:12range-value-captureclosure captures reused range variables i, tt

client_server_test.go:761:12

760
761 check := func(protos map[*httptest.Server]string) {
762 name := fmt.Sprintf("%d: %s%s/ header[Host]=%q, tls.ServerName=%q", i+1, protos[tt.server], tt.url, tt.header, tt.tls)
766:4single-case-switchswitch with one case can be replaced by an if statement

client_server_test.go:766:4

765 }
766 switch {
767 case tt.fail && err == nil:
772:35add-constantstring literal "X-Test-Host" appears more than twice; define a constant

client_server_test.go:772:35

771 case !tt.fail && err == nil:
772 if gotHost := resp.Header.Get("X-Test-Host"); gotHost != tt.wantHeader {
773 t.Errorf("%s: got host %s, want %s", name, gotHost, tt.wantHeader)
786:13discarded-error-resulterror result returned by http.NewRequest is discarded

client_server_test.go:786:13

785 }
786 req, _ := http.NewRequest(http.MethodGet, httpProtos[tt.server]+tt.url+"/", nil)
787 if tt.header != "" {
786:74add-constantstring literal "/" appears more than twice; define a constant

client_server_test.go:786:74

785 }
786 req, _ := http.NewRequest(http.MethodGet, httpProtos[tt.server]+tt.url+"/", nil)
787 if tt.header != "" {
791:15unclosed-http-response-bodylocally acquired HTTP response body is not closed on every path before the function exits

client_server_test.go:791:15

790 client := &http.Client{Transport: transport}
791 resp, err = client.Do(req)
792 if err == nil {
791:24external-call-in-loopnet/http.Do is called synchronously inside a loop; batch or move the external operation outside the loop

client_server_test.go:791:24

790 client := &http.Client{Transport: transport}
791 resp, err = client.Do(req)
792 if err == nil {
793:4discarded-error-resulterror result returned by resp.Body.Close is discarded

client_server_test.go:793:4

792 if err == nil {
793 resp.Body.Close()
794 }
800:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:800:6

799
800func TestDialCompression(t *testing.T) {
801 s := newServer(t)
814:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

client_server_test.go:814:6

813
814func TestSocksProxyDial(t *testing.T) {
815 s := newServer(t)
814:6cyclomatic-complexityfunction complexity is 12; maximum is 10

client_server_test.go:814:6

813
814func TestSocksProxyDial(t *testing.T) {
815 s := newServer(t)
814:6function-lengthfunction has 55 statements and 78 lines; maximum is 50 statements or 75 lines

client_server_test.go:814:6

813
814func TestSocksProxyDial(t *testing.T) {
815 s := newServer(t)
814:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:814:6

813
814func TestSocksProxyDial(t *testing.T) {
815 s := newServer(t)
831:7discarded-error-resulterror result returned by c1.SetDeadline is discarded

client_server_test.go:831:7

830
831 _ = c1.SetDeadline(time.Now().Add(30 * time.Second))
832
868:21nested-structsmove nested anonymous struct types to named declarations

client_server_test.go:868:21

867 defer c2.Close()
868 done := make(chan struct{})
869 go func() {
870:11discarded-error-resulterror result returned by io.Copy is discarded

client_server_test.go:870:11

869 go func() {
870 _, _ = io.Copy(c1, c2)
871 close(done)
873:10discarded-error-resulterror result returned by io.Copy is discarded

client_server_test.go:873:10

872 }()
873 _, _ = io.Copy(c2, c1)
874 <-done
893:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:893:6

892
893func TestTracingDialWithContext(t *testing.T) {
894
952:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:952:6

951
952func TestEmptyTracingDialWithContext(t *testing.T) {
953
972:1doc-comment-perioddocumentation comment should end with punctuation

client_server_test.go:972:1

971
972// TestNetDialConnect tests selection of dial method between NetDial, NetDialContext, NetDialTLS or NetDialTLSContext
973func TestNetDialConnect(t *testing.T) {
973:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

client_server_test.go:973:6

972// TestNetDialConnect tests selection of dial method between NetDial, NetDialContext, NetDialTLS or NetDialTLSContext
973func TestNetDialConnect(t *testing.T) {
974
973:6function-lengthfunction has 50 statements and 175 lines; maximum is 50 statements or 75 lines

client_server_test.go:973:6

972// TestNetDialConnect tests selection of dial method between NetDial, NetDialContext, NetDialTLS or NetDialTLSContext
973func TestNetDialConnect(t *testing.T) {
974
973:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:973:6

972// TestNetDialConnect tests selection of dial method between NetDial, NetDialContext, NetDialTLS or NetDialTLSContext
973func TestNetDialConnect(t *testing.T) {
974
982:4discarded-error-resulterror result returned by c.Close is discarded

client_server_test.go:982:4

981 }
982 c.Close()
983 } else {
995:14insecure-url-schemeURL uses insecure ws scheme

client_server_test.go:995:14

994 testUrls := map[*httptest.Server]string{
995 server: "ws://" + server.Listener.Addr().String() + "/",
996 tlsServer: "wss://" + tlsServer.Listener.Addr().String() + "/",
1006:13nested-structsmove nested anonymous struct types to named declarations

client_server_test.go:1006:13

1005
1006 tests := []struct {
1007 name string
1019:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1019:28

1018 netDial: func(network, addr string) (net.Conn, error) {
1019 return nil, errors.New("NetDial should not be called")
1020 },
1025:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1025:28

1024 netDialTLSContext: func(_ context.Context, network, addr string) (net.Conn, error) {
1025 return nil, errors.New("NetDialTLSContext should not be called")
1026 },
1045:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1045:28

1044 netDialTLSContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
1045 return nil, errors.New("NetDialTLSContext should not be called")
1046 },
1053:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1053:28

1052 netDial: func(network, addr string) (net.Conn, error) {
1053 return nil, errors.New("NetDial should not be called")
1054 },
1056:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1056:28

1055 netDialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
1056 return nil, errors.New("NetDialContext should not be called")
1057 },
1076:28add-constantstring literal "NetDial should not be called" appears more than twice; define a constant

client_server_test.go:1076:28

1075 netDial: func(network, addr string) (net.Conn, error) {
1076 return nil, errors.New("NetDial should not be called")
1077 },
1076:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1076:28

1075 netDial: func(network, addr string) (net.Conn, error) {
1076 return nil, errors.New("NetDial should not be called")
1077 },
1106:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1106:28

1105 netDial: func(network, addr string) (net.Conn, error) {
1106 return nil, errors.New("NetDial should not be called")
1107 },
1109:28error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1109:28

1108 netDialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
1109 return nil, errors.New("NetDialContext should not be called")
1110 },
1142:13error-stringserror string should not be capitalized or end with punctuation

client_server_test.go:1142:13

1141 if err != nil {
1142 t.Errorf("FAILED %s, err: %s", tc.name, err.Error())
1143 } else {
1144:4discarded-error-resulterror result returned by c.Close is discarded

client_server_test.go:1144:4

1143 } else {
1144 c.Close()
1145 }
1148:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:1148:6

1147}
1148func TestNextProtos(t *testing.T) {
1149 ts := httptest.NewUnstartedServer(
1157:41unchecked-type-assertionuse the checked two-result form of the type assertion

client_server_test.go:1157:41

1156 d := Dialer{
1157 TLSClientConfig: ts.Client().Transport.(*http.Transport).TLSClientConfig,
1158 }
1164:2discarded-error-resulterror result returned by r.Body.Close is discarded

client_server_test.go:1164:2

1163 }
1164 r.Body.Close()
1165
1168:27var-declarationomit the explicit zero value from the variable declaration

client_server_test.go:1168:27

1167 // after the Client.Get call from net/http above.
1168 var containsHTTP2 bool = false
1169 for _, proto := range d.TLSClientConfig.NextProtos {
1197:44exported-declaration-commentexported function or method should have a comment beginning with its name

client_server_test.go:1197:44

1196
1197func (w dataBeforeHandshakeResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
1198 // Example single-frame masked text message from section 5.7 of the RFC.
1208:3discarded-error-resulterror result returned by rw.Reader.Peek is discarded

client_server_test.go:1208:3

1207 rw.Reader.Reset(bytes.NewReader(message[:n]))
1208 rw.Reader.Peek(n)
1209 }
1220:6test-parallelismconsider calling t.Parallel() when this test begins

client_server_test.go:1220:6

1219
1220func TestDataReceivedBeforeHandshake(t *testing.T) {
1221 s := newServer(t)
1231:59range-value-captureclosure captures reused range variable readBufferSize

client_server_test.go:1231:59

1230 for _, readBufferSize := range []int{0, 1024} {
1231 t.Run(fmt.Sprintf("ReadBufferSize=%d", readBufferSize), func(t *testing.T) {
1232 dialer := cstDialer
1231:59test-parallelismconsider calling t.Parallel() when this subtest begins

client_server_test.go:1231:59

1230 for _, readBufferSize := range []int{0, 1024} {
1231 t.Run(fmt.Sprintf("ReadBufferSize=%d", readBufferSize), func(t *testing.T) {
1232 dialer := cstDialer

client_test.go4

1:1formatfile is not formatted

client_test.go:1:1

1// Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt client_test.go`
12:5no-package-varpackage variables introduce mutable global state

client_test.go:12:5

11
12var hostPortNoPortTests = []struct {
13 u *url.URL
12:29nested-structsmove nested anonymous struct types to named declarations

client_test.go:12:29

11
12var hostPortNoPortTests = []struct {
13 u *url.URL
22:6test-parallelismconsider calling t.Parallel() when this test begins

client_test.go:22:6

21
22func TestHostPortNoPort(t *testing.T) {
23 for _, tt := range hostPortNoPortTests {

compression.go12

1:1formatfile is not formatted

compression.go:1:1

1// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt compression.go`
5:9package-commentspackage should have a documentation comment

compression.go:5:9

4
5package websocket
6
22:2no-package-varpackage variables introduce mutable global state

compression.go:22:2

21var (
22 flateWriterPools [maxCompressionLevel - minCompressionLevel + 1]sync.Pool
23 flateReaderPool = sync.Pool{New: func() interface{} {
23:2no-package-varpackage variables introduce mutable global state

compression.go:23:2

22 flateWriterPools [maxCompressionLevel - minCompressionLevel + 1]sync.Pool
23 flateReaderPool = sync.Pool{New: func() interface{} {
24 return flate.NewReader(nil)
23:43use-anyuse any instead of interface{}

compression.go:23:43

22 flateWriterPools [maxCompressionLevel - minCompressionLevel + 1]sync.Pool
23 flateReaderPool = sync.Pool{New: func() interface{} {
24 return flate.NewReader(nil)
37:14unchecked-type-assertionuse the checked two-result form of the type assertion

compression.go:37:14

36 mr := io.MultiReader(r, strings.NewReader(tail))
37 if err := fr.(flate.Resetter).Reset(mr, nil); err != nil {
38 // Reset never fails, but handle error in case that changes.
53:11discarded-error-resulterror result returned by flate.NewWriter is discarded

compression.go:53:11

52 if fw == nil {
53 fw, _ = flate.NewWriter(tw, level)
54 } else {
62:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

compression.go:62:1

61// stream to another io.Writer.
62type truncWriter struct {
63 w io.WriteCloser
74:3modifies-parameterassignment modifies parameter p

compression.go:74:3

73 n = copy(w.p[w.n:], p)
74 p = p[n:]
75 w.n += n
109:29exported-declaration-commentexported function or method should have a comment beginning with its name

compression.go:109:29

108
109func (w *flateWriteWrapper) Close() error {
110 if w.fw == nil {
139:3discarded-error-resulterror result returned by r.Close is discarded

compression.go:139:3

138 // this final read.
139 r.Close()
140 }
144:28exported-declaration-commentexported function or method should have a comment beginning with its name

compression.go:144:28

143
144func (r *flateReadWrapper) Close() error {
145 if r.fr == nil {

compression_test.go8

1:1formatfile is not formatted

compression_test.go:1:1

1package websocket
2
  • Fix (safe): run `strider fmt compression_test.go`
12:18exported-declaration-commentexported function or method should have a comment beginning with its name

compression_test.go:12:18

11
12func (nopCloser) Close() error { return nil }
13
14:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

compression_test.go:14:6

13
14func TestTruncWriter(t *testing.T) {
15 const data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijlkmnopqrstuvwxyz987654321"
14:6test-parallelismconsider calling t.Parallel() when this test begins

compression_test.go:14:6

13
14func TestTruncWriter(t *testing.T) {
15 const data = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijlkmnopqrstuvwxyz987654321"
25:11discarded-error-resulterror result returned by w.Write is discarded

compression_test.go:25:11

24 }
25 _, _ = w.Write(p[:m])
26 p = p[m:]
49:7discarded-error-resulterror result returned by c.WriteMessage is discarded

compression_test.go:49:7

48 for i := 0; i < b.N; i++ {
49 _ = c.WriteMessage(TextMessage, messages[i%len(messages)])
50 }
62:7discarded-error-resulterror result returned by c.WriteMessage is discarded

compression_test.go:62:7

61 for i := 0; i < b.N; i++ {
62 _ = c.WriteMessage(TextMessage, messages[i%len(messages)])
63 }
67:6test-parallelismconsider calling t.Parallel() when this test begins

compression_test.go:67:6

66
67func TestValidCompressionLevel(t *testing.T) {
68 c := newTestConn(nil, nil, false)

conn.go132

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

conn.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
1:1formatfile is not formatted

conn.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt conn.go`
5:9package-commentspackage should have a documentation comment

conn.go:5:9

4
5package websocket
6
45:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:45:2

44const (
45 CloseNormalClosure = 1000
46 CloseGoingAway = 1001
46:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:46:2

45 CloseNormalClosure = 1000
46 CloseGoingAway = 1001
47 CloseProtocolError = 1002
47:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:47:2

46 CloseGoingAway = 1001
47 CloseProtocolError = 1002
48 CloseUnsupportedData = 1003
48:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:48:2

47 CloseProtocolError = 1002
48 CloseUnsupportedData = 1003
49 CloseNoStatusReceived = 1005
49:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:49:2

48 CloseUnsupportedData = 1003
49 CloseNoStatusReceived = 1005
50 CloseAbnormalClosure = 1006
50:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:50:2

49 CloseNoStatusReceived = 1005
50 CloseAbnormalClosure = 1006
51 CloseInvalidFramePayloadData = 1007
51:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:51:2

50 CloseAbnormalClosure = 1006
51 CloseInvalidFramePayloadData = 1007
52 ClosePolicyViolation = 1008
52:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:52:2

51 CloseInvalidFramePayloadData = 1007
52 ClosePolicyViolation = 1008
53 CloseMessageTooBig = 1009
53:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:53:2

52 ClosePolicyViolation = 1008
53 CloseMessageTooBig = 1009
54 CloseMandatoryExtension = 1010
54:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:54:2

53 CloseMessageTooBig = 1009
54 CloseMandatoryExtension = 1010
55 CloseInternalServerErr = 1011
55:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:55:2

54 CloseMandatoryExtension = 1010
55 CloseInternalServerErr = 1011
56 CloseServiceRestart = 1012
56:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:56:2

55 CloseInternalServerErr = 1011
56 CloseServiceRestart = 1012
57 CloseTryAgainLater = 1013
57:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:57:2

56 CloseServiceRestart = 1012
57 CloseTryAgainLater = 1013
58 CloseTLSHandshake = 1015
58:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:58:2

57 CloseTryAgainLater = 1013
58 CloseTLSHandshake = 1015
59)
65:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:65:2

64 // interpreted as UTF-8 encoded text data.
65 TextMessage = 1
66
73:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:73:2

72 // function to format a close message payload.
73 CloseMessage = 8
74
77:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:77:2

76 // is UTF-8 encoded text.
77 PingMessage = 9
78
81:2exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:81:2

80 // is UTF-8 encoded text.
81 PongMessage = 10
82)
86:5exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:86:5

85// connection after sending a close message.
86var ErrCloseSent = errors.New("websocket: close sent")
87
86:5no-package-varpackage variables introduce mutable global state

conn.go:86:5

85// connection after sending a close message.
86var ErrCloseSent = errors.New("websocket: close sent")
87
90:5exported-declaration-commentexported declaration should have a comment beginning with its name

conn.go:90:5

89// read limit set for the connection.
90var ErrReadLimit = errors.New("websocket: read limit exceeded")
91
90:5no-package-varpackage variables introduce mutable global state

conn.go:90:5

89// read limit set for the connection.
90var ErrReadLimit = errors.New("websocket: read limit exceeded")
91
100:20exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:100:20

99func (e *netError) Error() string { return e.msg }
100func (e *netError) Temporary() bool { return e.temporary }
101func (e *netError) Timeout() bool { return e.timeout }
101:20exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:101:20

100func (e *netError) Temporary() bool { return e.temporary }
101func (e *netError) Timeout() bool { return e.timeout }
102
104:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

conn.go:104:1

103// CloseError represents a close message.
104type CloseError struct {
105 // Code is defined in RFC 6455, section 11.7.
112:22cyclomatic-complexityfunction complexity is 14; maximum is 10

conn.go:112:22

111
112func (e *CloseError) Error() string {
113 s := []byte("websocket: close ")
115:2single-case-switchswitch with one case can be replaced by an if statement

conn.go:115:2

114 s = strconv.AppendInt(s, int64(e.Code), 10)
115 switch e.Code {
116 case CloseNormalClosure:
150:6exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:150:6

149// with one of the specified codes.
150func IsCloseError(err error, codes ...int) bool {
151 if e, ok := err.(*CloseError); ok {
163:6exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:163:6

162// *CloseError with a code not in the list of expected codes.
163func IsUnexpectedCloseError(err error, expectedCodes ...int) bool {
164 if e, ok := err.(*CloseError); ok {
176:2no-package-varpackage variables introduce mutable global state

conn.go:176:2

175var (
176 errWriteTimeout = &netError{msg: "websocket: write timeout", timeout: true, temporary: true}
177 errUnexpectedEOF = &CloseError{Code: CloseAbnormalClosure, Text: io.ErrUnexpectedEOF.Error()}
177:2no-package-varpackage variables introduce mutable global state

conn.go:177:2

176 errWriteTimeout = &netError{msg: "websocket: write timeout", timeout: true, temporary: true}
177 errUnexpectedEOF = &CloseError{Code: CloseAbnormalClosure, Text: io.ErrUnexpectedEOF.Error()}
178 errBadWriteOpCode = errors.New("websocket: bad write message type")
178:2no-package-varpackage variables introduce mutable global state

conn.go:178:2

177 errUnexpectedEOF = &CloseError{Code: CloseAbnormalClosure, Text: io.ErrUnexpectedEOF.Error()}
178 errBadWriteOpCode = errors.New("websocket: bad write message type")
179 errWriteClosed = errors.New("websocket: write closed")
179:2no-package-varpackage variables introduce mutable global state

conn.go:179:2

178 errBadWriteOpCode = errors.New("websocket: bad write message type")
179 errWriteClosed = errors.New("websocket: write closed")
180 errInvalidControlFrame = errors.New("websocket: invalid control frame")
180:2no-package-varpackage variables introduce mutable global state

conn.go:180:2

179 errWriteClosed = errors.New("websocket: write closed")
180 errInvalidControlFrame = errors.New("websocket: invalid control frame")
181)
186:5no-package-varpackage variables introduce mutable global state

conn.go:186:5

185// reproducible results.
186var maskRand = rand.Reader
187
191:9discarded-error-resulterror result returned by io.ReadFull is discarded

conn.go:191:9

190 var k [4]byte
191 _, _ = io.ReadFull(maskRand, k[:])
192 return k
196:9optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn.go:196:9

195func isControl(frameType int) bool {
196 return frameType == CloseMessage || frameType == PingMessage || frameType == PongMessage
197}
203:5no-package-varpackage variables introduce mutable global state

conn.go:203:5

202
203var validReceivedCloseCodes = map[int]bool{
204 // see http://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number
228:6exported-declaration-commentexported type should have a comment beginning with its name

conn.go:228:6

227// interface. The type of the value stored in a pool is not specified.
228type BufferPool interface {
229 // Get gets a value from the pool or returns nil if the pool is empty.
230:8use-anyuse any instead of interface{}

conn.go:230:8

229 // Get gets a value from the pool or returns nil if the pool is empty.
230 Get() interface{}
231 // Put adds a value to the pool.
232:6use-anyuse any instead of interface{}

conn.go:232:6

231 // Put adds a value to the pool.
232 Put(interface{})
233}
241:6exported-declaration-commentexported type should have a comment beginning with its name

conn.go:241:6

240// The Conn type represents a WebSocket connection.
241type Conn struct {
242 conn net.Conn
247:21nested-structsmove nested anonymous struct types to named declarations

conn.go:247:21

246 // Write fields
247 mu chan struct{} // used as mutex to protect write to conn
248 writeBuf []byte // frame is constructed in this buffer.
284:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

conn.go:284:6

283
284func newConn(conn net.Conn, isServer bool, readBufferSize, writeBufferSize int, writeBufferPool BufferPool, br *bufio.Reader, writeBuf []byte) *Conn {
285
288:4modifies-parameterassignment modifies parameter readBufferSize

conn.go:288:4

287 if readBufferSize == 0 {
288 readBufferSize = defaultReadBufferSize
289 } else if readBufferSize < maxControlFramePayloadSize {
291:4modifies-parameterassignment modifies parameter readBufferSize

conn.go:291:4

290 // must be large enough for control frame
291 readBufferSize = maxControlFramePayloadSize
292 }
293:3modifies-parameterassignment modifies parameter br

conn.go:293:3

292 }
293 br = bufio.NewReaderSize(conn, readBufferSize)
294 }
297:3modifies-parameterassignment modifies parameter writeBufferSize

conn.go:297:3

296 if writeBufferSize <= 0 {
297 writeBufferSize = defaultWriteBufferSize
298 }
299:2modifies-parameterassignment modifies parameter writeBufferSize

conn.go:299:2

298 }
299 writeBufferSize += maxFrameHeaderSize
300
302:3modifies-parameterassignment modifies parameter writeBuf

conn.go:302:3

301 if writeBuf == nil && writeBufferPool == nil {
302 writeBuf = make([]byte, writeBufferSize)
303 }
305:18nested-structsmove nested anonymous struct types to named declarations

conn.go:305:18

304
305 mu := make(chan struct{}, 1)
306 mu <- struct{}{}
306:8nested-structsmove nested anonymous struct types to named declarations

conn.go:306:8

305 mu := make(chan struct{}, 1)
306 mu <- struct{}{}
307 c := &Conn{
343:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:343:16

342// for a close message.
343func (c *Conn) Close() error {
344 return c.conn.Close()
375:9discarded-error-resulterror result returned by c.br.Discard is discarded

conn.go:375:9

374 // is less than or equal to the number of bytes buffered.
375 _, _ = c.br.Discard(len(p))
376 return p, err
381:25nested-structsmove nested anonymous struct types to named declarations

conn.go:381:25

380 <-c.mu
381 defer func() { c.mu <- struct{}{} }()
382
402:7discarded-error-resulterror result returned by c.writeFatal is discarded

conn.go:402:7

401 if frameType == CloseMessage {
402 _ = c.writeFatal(ErrCloseSent)
403 }
415:16cognitive-complexityfunction has cognitive complexity 16; maximum is 7

conn.go:415:16

414// message types are CloseMessage, PingMessage and PongMessage.
415func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error {
416 if !isControl(messageType) {
415:16cyclomatic-complexityfunction complexity is 14; maximum is 10

conn.go:415:16

414// message types are CloseMessage, PingMessage and PongMessage.
415func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error {
416 if !isControl(messageType) {
415:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:415:16

414// message types are CloseMessage, PingMessage and PongMessage.
415func (c *Conn) WriteControl(messageType int, data []byte, deadline time.Time) error {
416 if !isControl(messageType) {
462:25nested-structsmove nested anonymous struct types to named declarations

conn.go:462:25

461
462 defer func() { c.mu <- struct{}{} }()
463
478:7discarded-error-resulterror result returned by c.writeFatal is discarded

conn.go:478:7

477 if messageType == CloseMessage {
478 _ = c.writeFatal(ErrCloseSent)
479 }
489:3discarded-error-resulterror result returned by c.writer.Close is discarded

conn.go:489:3

488 if c.writer != nil {
489 c.writer.Close()
490 c.writer = nil
504:2modifies-parameterassignment modifies parameter mw

conn.go:504:2

503
504 mw.c = c
505 mw.frameType = messageType
505:2modifies-parameterassignment modifies parameter mw

conn.go:505:2

504 mw.c = c
505 mw.frameType = messageType
506 mw.pos = maxFrameHeaderSize
506:2modifies-parameterassignment modifies parameter mw

conn.go:506:2

505 mw.frameType = messageType
506 mw.pos = maxFrameHeaderSize
507
527:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:527:16

526// PongMessage) are supported.
527func (c *Conn) NextWriter(messageType int) (io.WriteCloser, error) {
528 var mw messageWriter
533:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn.go:533:5

532 c.writer = &mw
533 if c.newCompressionWriter != nil && c.enableWriteCompression && isData(messageType) {
534 w := c.newCompressionWriter(c.writer, c.compressionLevel)
565:25cognitive-complexityfunction has cognitive complexity 13; maximum is 7

conn.go:565:25

564// final argument indicates that this is the last frame in the message.
565func (w *messageWriter) flushFrame(final bool, extra []byte) error {
566 c := w.c
565:25cyclomatic-complexityfunction complexity is 16; maximum is 10

conn.go:565:25

564// final argument indicates that this is the last frame in the message.
565func (w *messageWriter) flushFrame(final bool, extra []byte) error {
566 c := w.c
565:25function-lengthfunction has 48 statements and 86 lines; maximum is 50 statements or 75 lines

conn.go:565:25

564// final argument indicates that this is the last frame in the message.
565func (w *messageWriter) flushFrame(final bool, extra []byte) error {
566 c := w.c
565:36flag-parameterboolean parameter final controls function flow

conn.go:565:36

564// final argument indicates that this is the last frame in the message.
565func (w *messageWriter) flushFrame(final bool, extra []byte) error {
566 c := w.c
570:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn.go:570:5

569 // Check for invalid control frames.
570 if isControl(w.frameType) &&
571 (!final || length > maxControlFramePayloadSize) {
584:8redundant-conversionconversion from byte to the identical type is redundant

conn.go:584:8

583
584 b1 := byte(0)
585 if !c.isServer {
596:2single-case-switchswitch with one case can be replaced by an if statement

conn.go:596:2

595
596 switch {
597 case length >= 65536:
642:7discarded-error-resulterror result returned by w.endMessage is discarded

conn.go:642:7

641 if final {
642 _ = w.endMessage(errWriteClosed)
643 return nil
652:31redefines-builtin-ididentifier max shadows a predeclared identifier

conn.go:652:31

651
652func (w *messageWriter) ncopy(max int) (int, error) {
653 n := len(w.c.writeBuf) - w.pos
671:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn.go:671:5

670
671 if len(p) > 2*len(w.c.writeBuf) && w.c.isServer {
672 // Don't buffer large messages.
688:3modifies-parameterassignment modifies parameter p

conn.go:688:3

687 w.pos += n
688 p = p[n:]
689 }
693:25exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:693:25

692
693func (w *messageWriter) WriteString(p string) (int, error) {
694 if w.err != nil {
706:3modifies-parameterassignment modifies parameter p

conn.go:706:3

705 w.pos += n
706 p = p[n:]
707 }
711:25cognitive-complexityfunction has cognitive complexity 14; maximum is 7

conn.go:711:25

710
711func (w *messageWriter) ReadFrom(r io.Reader) (nn int64, err error) {
712 if w.err != nil {
711:25exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:711:25

710
711func (w *messageWriter) ReadFrom(r io.Reader) (nn int64, err error) {
712 if w.err != nil {
736:25exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:736:25

735
736func (w *messageWriter) Close() error {
737 if w.err != nil {
747:21optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn.go:747:21

746 isServer: c.isServer,
747 compress: c.newCompressionWriter != nil && c.enableWriteCompression && isData(pm.messageType),
748 compressionLevel: c.compressionLevel,
754:9add-constantstring literal "concurrent write to websocket connection" appears more than twice; define a constant

conn.go:754:9

753 if c.isWriting {
754 panic("concurrent write to websocket connection")
755 }
767:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:767:16

766// writing the message and closing the writer.
767func (c *Conn) WriteMessage(messageType int, data []byte) error {
768
769:20optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn.go:769:20

768
769 if c.isServer && (c.newCompressionWriter == nil || !c.enableWriteCompression) {
770 // Fast path with no allocations and single frame.
778:3modifies-parameterassignment modifies parameter data

conn.go:778:3

777 mw.pos += n
778 data = data[n:]
779 return mw.flushFrame(true, data)
796:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:796:16

795// not time out.
796func (c *Conn) SetWriteDeadline(t time.Time) error {
797 c.writeDeadline = t
803:16cognitive-complexityfunction has cognitive complexity 57; maximum is 7

conn.go:803:16

802
803func (c *Conn) advanceFrame() (int, error) {
804 // 1. Skip remainder of previous frame.
803:16cyclomatic-complexityfunction complexity is 43; maximum is 10

conn.go:803:16

802
803func (c *Conn) advanceFrame() (int, error) {
804 // 1. Skip remainder of previous frame.
803:16function-lengthfunction has 90 statements and 185 lines; maximum is 50 statements or 75 lines

conn.go:803:16

802
803func (c *Conn) advanceFrame() (int, error) {
804 // 1. Skip remainder of previous frame.
816:6import-shadowingidentifier errors shadows an imported package

conn.go:816:6

815
816 var errors []string
817
829:6discarded-error-resulterror result returned by c.setReadRemaining is discarded

conn.go:829:6

828 mask := p[1]&maskBit != 0
829 _ = c.setReadRemaining(int64(p[1] & 0x7f)) // will not fail because argument is >= 0
830
890:2single-case-switchswitch with one case can be replaced by an if statement

conn.go:890:2

889
890 switch c.readRemaining {
891 case 126:
924:5optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn.go:924:5

923
924 if frameType == continuationFrame || frameType == TextMessage || frameType == BinaryMessage {
925
935:8discarded-error-resulterror result returned by c.WriteControl is discarded

conn.go:935:8

934 // Make a best effort to send a close message describing the problem.
935 _ = c.WriteControl(CloseMessage, FormatCloseMessage(CloseMessageTooBig, ""), time.Now().Add(writeWait))
936 return noFrame, ErrReadLimit
947:7discarded-error-resulterror result returned by c.setReadRemaining is discarded

conn.go:947:7

946 payload, err = c.read(int(c.readRemaining))
947 _ = c.setReadRemaining(0) // will not fail because argument is >= 0
948 if err != nil {
958:2single-case-switchswitch with one case can be replaced by an if statement

conn.go:958:2

957
958 switch frameType {
959 case PongMessage:
995:6discarded-error-resulterror result returned by c.WriteControl is discarded

conn.go:995:6

994 // Make a best effor to send a close message describing the problem.
995 _ = c.WriteControl(CloseMessage, data, time.Now().Add(writeWait))
996 return errors.New("websocket: " + message)
1009:16cognitive-complexityfunction has cognitive complexity 11; maximum is 7

conn.go:1009:16

1008// this method return the same error.
1009func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
1010 // Close previous reader, only relevant for decompression.
1009:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1009:16

1008// this method return the same error.
1009func (c *Conn) NextReader() (messageType int, r io.Reader, err error) {
1010 // Close previous reader, only relevant for decompression.
1012:3discarded-error-resulterror result returned by c.reader.Close is discarded

conn.go:1012:3

1011 if c.reader != nil {
1012 c.reader.Close()
1013 c.reader = nil
1049:25cognitive-complexityfunction has cognitive complexity 18; maximum is 7

conn.go:1049:25

1048
1049func (r *messageReader) Read(b []byte) (int, error) {
1050 c := r.c
1049:25cyclomatic-complexityfunction complexity is 14; maximum is 10

conn.go:1049:25

1048
1049func (r *messageReader) Read(b []byte) (int, error) {
1050 c := r.c
1059:5modifies-parameterassignment modifies parameter b

conn.go:1059:5

1058 if int64(len(b)) > c.readRemaining {
1059 b = b[:c.readRemaining]
1060 }
1068:8discarded-error-resulterror result returned by c.setReadRemaining is discarded

conn.go:1068:8

1067 rem -= int64(n)
1068 _ = c.setReadRemaining(rem) // rem is guaranteed to be >= 0
1069 if c.readRemaining > 0 && c.readErr == io.EOF {
1081:3single-case-switchswitch with one case can be replaced by an if statement

conn.go:1081:3

1080 frameType, err := c.advanceFrame()
1081 switch {
1082 case err != nil:
1096:7unused-receiverreceiver r is unused

conn.go:1096:7

1095
1096func (r *messageReader) Close() error {
1097 return nil
1096:25exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1096:25

1095
1096func (r *messageReader) Close() error {
1097 return nil
1102:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1102:16

1101// reading from that reader to a buffer.
1102func (c *Conn) ReadMessage() (messageType int, p []byte, err error) {
1103 var r io.Reader
1116:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1116:16

1115// not time out.
1116func (c *Conn) SetReadDeadline(t time.Time) error {
1117 return c.conn.SetReadDeadline(t)
1123:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1123:16

1122// and returns ErrReadLimit to the application.
1123func (c *Conn) SetReadLimit(limit int64) {
1124 c.readLimit = limit
1127:1doc-comment-perioddocumentation comment should end with punctuation

conn.go:1127:1

1126
1127// CloseHandler returns the current close handler
1128func (c *Conn) CloseHandler() func(code int, text string) error {
1146:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1146:16

1145// the peer.
1146func (c *Conn) SetCloseHandler(h func(code int, text string) error) {
1147 if h == nil {
1148:3modifies-parameterassignment modifies parameter h

conn.go:1148:3

1147 if h == nil {
1148 h = func(code int, text string) error {
1149 message := FormatCloseMessage(code, "")
1151:8discarded-error-resulterror result returned by c.WriteControl is discarded

conn.go:1151:8

1150 // Make a best effor to send the close message.
1151 _ = c.WriteControl(CloseMessage, message, time.Now().Add(writeWait))
1152 return nil
1158:1doc-comment-perioddocumentation comment should end with punctuation

conn.go:1158:1

1157
1158// PingHandler returns the current ping handler
1159func (c *Conn) PingHandler() func(appData string) error {
1170:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1170:16

1169// ping messages as described in the section on Control Messages above.
1170func (c *Conn) SetPingHandler(h func(appData string) error) {
1171 if h == nil {
1172:3modifies-parameterassignment modifies parameter h

conn.go:1172:3

1171 if h == nil {
1172 h = func(message string) error {
1173 // Make a best effort to send the pong message.
1174:8discarded-error-resulterror result returned by c.WriteControl is discarded

conn.go:1174:8

1173 // Make a best effort to send the pong message.
1174 _ = c.WriteControl(PongMessage, []byte(message), time.Now().Add(writeWait))
1175 return nil
1181:1doc-comment-perioddocumentation comment should end with punctuation

conn.go:1181:1

1180
1181// PongHandler returns the current pong handler
1182func (c *Conn) PongHandler() func(appData string) error {
1193:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1193:16

1192// pong messages as described in the section on Control Messages above.
1193func (c *Conn) SetPongHandler(h func(appData string) error) {
1194 if h == nil {
1195:3modifies-parameterassignment modifies parameter h

conn.go:1195:3

1194 if h == nil {
1195 h = func(string) error { return nil }
1196 }
1203:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1203:16

1202// WebSocket connection.
1203func (c *Conn) NetConn() net.Conn {
1204 return c.conn
1210:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1210:16

1209// Deprecated: Use the NetConn method.
1210func (c *Conn) UnderlyingConn() net.Conn {
1211 return c.conn
1217:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1217:16

1216// compression was not negotiated with the peer.
1217func (c *Conn) EnableWriteCompression(enable bool) {
1218 c.enableWriteCompression = enable
1225:16exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1225:16

1224// compression levels.
1225func (c *Conn) SetCompressionLevel(level int) error {
1226 if !isValidCompressionLevel(level) {
1235:6exported-declaration-commentexported function or method should have a comment beginning with its name

conn.go:1235:6

1234// An empty message is returned for code CloseNoStatusReceived.
1235func FormatCloseMessage(closeCode int, text string) []byte {
1236 if closeCode == CloseNoStatusReceived {

conn_broadcast_test.go12

1:1formatfile is not formatted

conn_broadcast_test.go:1:1

1// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt conn_broadcast_test.go`
20:19nested-structsmove nested anonymous struct types to named declarations

conn_broadcast_test.go:20:19

19 w io.Writer
20 closeCh chan struct{}
21 doneCh chan struct{}
21:19nested-structsmove nested anonymous struct types to named declarations

conn_broadcast_test.go:21:19

20 closeCh chan struct{}
21 doneCh chan struct{}
22 count int32
48:26nested-structsmove nested anonymous struct types to named declarations

conn_broadcast_test.go:48:26

47 w: io.Discard,
48 doneCh: make(chan struct{}),
49 closeCh: make(chan struct{}),
49:26nested-structsmove nested anonymous struct types to named declarations

conn_broadcast_test.go:49:26

48 doneCh: make(chan struct{}),
49 closeCh: make(chan struct{}),
50 usePrepared: usePrepared,
57:26cognitive-complexityfunction has cognitive complexity 16; maximum is 7

conn_broadcast_test.go:57:26

56
57func (b *broadcastBench) makeConns(numConns int) {
58 conns := make([]*broadcastConn, numConns)
72:11discarded-error-resulterror result returned by c.conn.WritePreparedMessage is discarded

conn_broadcast_test.go:72:11

71 if msg.prepared != nil {
72 _ = c.conn.WritePreparedMessage(msg.prepared)
73 } else {
74:11discarded-error-resulterror result returned by c.conn.WriteMessage is discarded

conn_broadcast_test.go:74:11

73 } else {
74 _ = c.conn.WriteMessage(TextMessage, msg.payload)
75 }
78:19nested-structsmove nested anonymous struct types to named declarations

conn_broadcast_test.go:78:19

77 if val%int32(numConns) == 0 {
78 b.doneCh <- struct{}{}
79 }
101:18nested-structsmove nested anonymous struct types to named declarations

conn_broadcast_test.go:101:18

100func BenchmarkBroadcast(b *testing.B) {
101 benchmarks := []struct {
102 name string
113:18range-value-captureclosure captures reused range variable bm

conn_broadcast_test.go:113:18

112 for _, bm := range benchmarks {
113 b.Run(bm.name, func(b *testing.B) {
114 bench := newBroadcastBench(bm.usePrepared, bm.compression)
122:15discarded-error-resulterror result returned by NewPreparedMessage is discarded

conn_broadcast_test.go:122:15

121 if bench.usePrepared {
122 pm, _ := NewPreparedMessage(TextMessage, message.payload)
123 message.prepared = pm

conn_test.go131

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

conn_test.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
1:1formatfile is not formatted

conn_test.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt conn_test.go`
28:7unused-receiverreceiver c is unused

conn_test.go:28:7

27
28func (c fakeNetConn) Close() error { return nil }
29func (c fakeNetConn) LocalAddr() net.Addr { return localAddr }
28:22exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:28:22

27
28func (c fakeNetConn) Close() error { return nil }
29func (c fakeNetConn) LocalAddr() net.Addr { return localAddr }
29:7unused-receiverreceiver c is unused

conn_test.go:29:7

28func (c fakeNetConn) Close() error { return nil }
29func (c fakeNetConn) LocalAddr() net.Addr { return localAddr }
30func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
29:22exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:29:22

28func (c fakeNetConn) Close() error { return nil }
29func (c fakeNetConn) LocalAddr() net.Addr { return localAddr }
30func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
30:7unused-receiverreceiver c is unused

conn_test.go:30:7

29func (c fakeNetConn) LocalAddr() net.Addr { return localAddr }
30func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
30:22exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:30:22

29func (c fakeNetConn) LocalAddr() net.Addr { return localAddr }
30func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
31:7unused-receiverreceiver c is unused

conn_test.go:31:7

30func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
31:22exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:31:22

30func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
31:34unused-parameterparameter t is unused

conn_test.go:31:34

30func (c fakeNetConn) RemoteAddr() net.Addr { return remoteAddr }
31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
32:7unused-receiverreceiver c is unused

conn_test.go:32:7

31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
33func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
32:22exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:32:22

31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
33func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
32:38unused-parameterparameter t is unused

conn_test.go:32:38

31func (c fakeNetConn) SetDeadline(t time.Time) error { return nil }
32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
33func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
33:7unused-receiverreceiver c is unused

conn_test.go:33:7

32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
33func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
34
33:22exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:33:22

32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
33func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
34
33:39unused-parameterparameter t is unused

conn_test.go:33:39

32func (c fakeNetConn) SetReadDeadline(t time.Time) error { return nil }
33func (c fakeNetConn) SetWriteDeadline(t time.Time) error { return nil }
34
35:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

conn_test.go:35:1

34
35type fakeAddr int
36
38:2no-package-varpackage variables introduce mutable global state

conn_test.go:38:2

37var (
38 localAddr = fakeAddr(1)
39 remoteAddr = fakeAddr(2)
38:15redundant-conversionconversion from fakeAddr to the identical type is redundant

conn_test.go:38:15

37var (
38 localAddr = fakeAddr(1)
39 remoteAddr = fakeAddr(2)
39:2no-package-varpackage variables introduce mutable global state

conn_test.go:39:2

38 localAddr = fakeAddr(1)
39 remoteAddr = fakeAddr(2)
40)
39:15redundant-conversionconversion from fakeAddr to the identical type is redundant

conn_test.go:39:15

38 localAddr = fakeAddr(1)
39 remoteAddr = fakeAddr(2)
40)
42:7unused-receiverreceiver a is unused

conn_test.go:42:7

41
42func (a fakeAddr) Network() string {
43 return "net"
42:19exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:42:19

41
42func (a fakeAddr) Network() string {
43 return "net"
46:7unused-receiverreceiver a is unused

conn_test.go:46:7

45
46func (a fakeAddr) String() string {
47 return "str"
56:6cognitive-complexityfunction has cognitive complexity 76; maximum is 7

conn_test.go:56:6

55
56func TestFraming(t *testing.T) {
57 frameSizes := []int{
56:6cyclomatic-complexityfunction complexity is 18; maximum is 10

conn_test.go:56:6

55
56func TestFraming(t *testing.T) {
57 frameSizes := []int{
56:6function-lengthfunction has 51 statements and 94 lines; maximum is 50 statements or 75 lines

conn_test.go:56:6

55
56func TestFraming(t *testing.T) {
57 frameSizes := []int{
56:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:56:6

55
56func TestFraming(t *testing.T) {
57 frameSizes := []int{
61:23nested-structsmove nested anonymous struct types to named declarations

conn_test.go:61:23

60 }
61 var readChunkers = []struct {
62 name string
73:18nested-structsmove nested anonymous struct types to named declarations

conn_test.go:73:18

72 }
73 var writers = []struct {
74 name string
85:11byte-string-writewrite the byte slice directly instead of converting it for io.WriteString

conn_test.go:85:11

84 {"string", func(w io.Writer, n int) (int, error) {
85 return io.WriteString(w, string(writeBuf[:n]))
86 }},
105:7max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:105:7

104 w, err := wc.NextWriter(TextMessage)
105 if err != nil {
106 t.Errorf("%s: wc.NextWriter() returned %v", name, err)
110:7max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:110:7

109 nn, err := writer.f(w, n)
110 if err != nil || nn != n {
111 t.Errorf("%s: w.Write(writeBuf[:n]) returned %d, %v", name, nn, err)
115:7max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:115:7

114 err = w.Close()
115 if err != nil {
116 t.Errorf("%s: w.Close() returned %v", name, err)
121:7max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:121:7

120 opCode, r, err := rc.NextReader()
121 if err != nil || opCode != TextMessage {
122 t.Errorf("%s: NextReader() returned %d, r, %v", name, opCode, err)
128:7max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:128:7

127 rbuf, err := io.ReadAll(r)
128 if err != nil {
129 t.Errorf("%s: ReadFull() returned rbuf, %v", name, err)
133:7max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:133:7

132
133 if len(rbuf) != n {
134 t.Errorf("%s: len(rbuf) is %d, want %d", name, len(rbuf), n)
138:7max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:138:7

137
138 for i, b := range rbuf {
139 if byte(i) != b {
139:8max-control-nestingcontrol-flow nesting exceeds 5 levels

conn_test.go:139:8

138 for i, b := range rbuf {
139 if byte(i) != b {
140 t.Errorf("%s: bad byte at offset %d", name, i)
157:12error-stringserror string should not be capitalized or end with punctuation

conn_test.go:157:12

156 if err := c.WriteControl(PongMessage, message, time.Time{}); err != nil {
157 t.Errorf("WriteControl(..., zero deadline) = %v, want nil", err)
158 }
160:12error-stringserror string should not be capitalized or end with punctuation

conn_test.go:160:12

159 if err := c.WriteControl(PongMessage, message, time.Now().Add(time.Second)); err != nil {
160 t.Errorf("WriteControl(..., future deadline) = %v, want nil", err)
161 }
163:12error-stringserror string should not be capitalized or end with punctuation

conn_test.go:163:12

162 if err := c.WriteControl(PongMessage, message, time.Now().Add(-time.Second)); err == nil {
163 t.Errorf("WriteControl(..., past deadline) = nil, want timeout error")
164 }
167:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:167:6

166
167func TestConcurrencyWriteControl(t *testing.T) {
168 const message = "this is a ping/pong messsage"
188:3discarded-error-resulterror result returned by wc.Close is discarded

conn_test.go:188:3

187 wg.Wait()
188 wc.Close()
189 }
192:6cognitive-complexityfunction has cognitive complexity 26; maximum is 7

conn_test.go:192:6

191
192func TestControl(t *testing.T) {
193 const message = "this is a ping/pong message"
192:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:192:6

191
192func TestControl(t *testing.T) {
193 const message = "this is a ping/pong message"
201:9discarded-error-resulterror result returned by wc.WriteControl is discarded

conn_test.go:201:9

200 if isWriteControl {
201 _ = wc.WriteControl(PongMessage, []byte(message), time.Now().Add(time.Second))
202 } else {
218:5excessive-blank-identifiersassignment discards three or more results; name meaningful results or simplify the return contract

conn_test.go:218:5

217 rc.SetPongHandler(func(s string) error { actualMessage = s; return nil })
218 _, _, _ = rc.NextReader()
219 if actualMessage != message {
218:15discarded-error-resulterror result returned by rc.NextReader is discarded

conn_test.go:218:15

217 rc.SetPongHandler(func(s string) error { actualMessage = s; return nil })
218 _, _, _ = rc.NextReader()
219 if actualMessage != message {
230:4use-anyuse any instead of interface{}

conn_test.go:230:4

229type simpleBufferPool struct {
230 v interface{}
231}
233:28exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:233:28

232
233func (p *simpleBufferPool) Get() interface{} {
234 v := p.v
233:34use-anyuse any instead of interface{}

conn_test.go:233:34

232
233func (p *simpleBufferPool) Get() interface{} {
234 v := p.v
239:28exported-declaration-commentexported function or method should have a comment beginning with its name

conn_test.go:239:28

238
239func (p *simpleBufferPool) Put(v interface{}) {
240 p.v = v
239:34use-anyuse any instead of interface{}

conn_test.go:239:34

238
239func (p *simpleBufferPool) Put(v interface{}) {
240 p.v = v
243:6cognitive-complexityfunction has cognitive complexity 14; maximum is 7

conn_test.go:243:6

242
243func TestWriteBufferPool(t *testing.T) {
244 const message = "Now is the time for all good people to come to the aid of the party."
243:6cyclomatic-complexityfunction complexity is 21; maximum is 10

conn_test.go:243:6

242
243func TestWriteBufferPool(t *testing.T) {
244 const message = "Now is the time for all good people to come to the aid of the party."
243:6function-lengthfunction has 37 statements and 76 lines; maximum is 50 statements or 75 lines

conn_test.go:243:6

242
243func TestWriteBufferPool(t *testing.T) {
244 const message = "Now is the time for all good people to come to the aid of the party."
243:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:243:6

242
243func TestWriteBufferPool(t *testing.T) {
244 const message = "Now is the time for all good people to come to the aid of the party."
283:40optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn_test.go:283:40

282
283 if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
284 t.Fatal("writeBuf not returned to pool")
306:40optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn_test.go:306:40

305
306 if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
307 t.Fatal("writeBuf not returned to pool after WriteMessage")
321:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:321:6

320// TestWriteBufferPoolSync ensures that *sync.Pool works as a buffer pool.
321func TestWriteBufferPoolSync(t *testing.T) {
322 var buf bytes.Buffer
334:13add-constantstring literal "ReadMessage() returned %d, p, %v" appears more than twice; define a constant

conn_test.go:334:13

333 if opCode != TextMessage || err != nil {
334 t.Fatalf("ReadMessage() returned %d, p, %v", opCode, err)
335 }
337:13add-constantstring literal "message is %s, want %s" appears more than twice; define a constant

conn_test.go:337:13

336 if s := string(p); s != message {
337 t.Fatalf("message is %s, want %s", s, message)
338 }
345:7unused-receiverreceiver ew is unused

conn_test.go:345:7

344
345func (ew errorWriter) Write(p []byte) (int, error) { return 0, errors.New("error") }
346
345:29unused-parameterparameter p is unused

conn_test.go:345:29

344
345func (ew errorWriter) Write(p []byte) (int, error) { return 0, errors.New("error") }
346
349:6cyclomatic-complexityfunction complexity is 12; maximum is 10

conn_test.go:349:6

348// on write.
349func TestWriteBufferPoolError(t *testing.T) {
350
349:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:349:6

348// on write.
349func TestWriteBufferPoolError(t *testing.T) {
350
375:40optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn_test.go:375:40

374
375 if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
376 t.Fatal("writeBuf not returned to pool")
387:40optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

conn_test.go:387:40

386
387 if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
388 t.Fatal("writeBuf not returned to pool")
388:11add-constantstring literal "writeBuf not returned to pool" appears more than twice; define a constant

conn_test.go:388:11

387 if wpd, ok := pool.v.(writePoolData); !ok || len(wpd.buf) == 0 || &wpd.buf[0] != writeBufAddr {
388 t.Fatal("writeBuf not returned to pool")
389 }
392:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:392:6

391
392func TestCloseFrameBeforeFinalMessageFrame(t *testing.T) {
393 const bufSize = 512
401:10discarded-error-resulterror result returned by wc.NextWriter is discarded

conn_test.go:401:10

400
401 w, _ := wc.NextWriter(BinaryMessage)
402 _, _ = w.Write(make([]byte, bufSize+bufSize/2))
402:9discarded-error-resulterror result returned by w.Write is discarded

conn_test.go:402:9

401 w, _ := wc.NextWriter(BinaryMessage)
402 _, _ = w.Write(make([]byte, bufSize+bufSize/2))
403 _ = wc.WriteControl(CloseMessage, FormatCloseMessage(expectedErr.Code, expectedErr.Text), time.Now().Add(10*time.Second))
403:6discarded-error-resulterror result returned by wc.WriteControl is discarded

conn_test.go:403:6

402 _, _ = w.Write(make([]byte, bufSize+bufSize/2))
403 _ = wc.WriteControl(CloseMessage, FormatCloseMessage(expectedErr.Code, expectedErr.Text), time.Now().Add(10*time.Second))
404 w.Close()
404:2discarded-error-resulterror result returned by w.Close is discarded

conn_test.go:404:2

403 _ = wc.WriteControl(CloseMessage, FormatCloseMessage(expectedErr.Code, expectedErr.Text), time.Now().Add(10*time.Second))
404 w.Close()
405
420:6cognitive-complexityfunction has cognitive complexity 13; maximum is 7

conn_test.go:420:6

419
420func TestEOFWithinFrame(t *testing.T) {
421 const bufSize = 64
420:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:420:6

419
420func TestEOFWithinFrame(t *testing.T) {
421 const bufSize = 64
428:11discarded-error-resulterror result returned by wc.NextWriter is discarded

conn_test.go:428:11

427
428 w, _ := wc.NextWriter(BinaryMessage)
429 _, _ = w.Write(make([]byte, bufSize))
429:10discarded-error-resulterror result returned by w.Write is discarded

conn_test.go:429:10

428 w, _ := wc.NextWriter(BinaryMessage)
429 _, _ = w.Write(make([]byte, bufSize))
430 w.Close()
430:3discarded-error-resulterror result returned by w.Close is discarded

conn_test.go:430:3

429 _, _ = w.Write(make([]byte, bufSize))
430 w.Close()
431
455:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:455:6

454
455func TestEOFBeforeFinalFrame(t *testing.T) {
456 const bufSize = 512
462:10discarded-error-resulterror result returned by wc.NextWriter is discarded

conn_test.go:462:10

461
462 w, _ := wc.NextWriter(BinaryMessage)
463 _, _ = w.Write(make([]byte, bufSize+bufSize/2))
463:9discarded-error-resulterror result returned by w.Write is discarded

conn_test.go:463:9

462 w, _ := wc.NextWriter(BinaryMessage)
463 _, _ = w.Write(make([]byte, bufSize+bufSize/2))
464
479:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:479:6

478
479func TestWriteAfterMessageWriterClose(t *testing.T) {
480 wc := newTestConn(nil, &bytes.Buffer{}, false)
481:10discarded-error-resulterror result returned by wc.NextWriter is discarded

conn_test.go:481:10

480 wc := newTestConn(nil, &bytes.Buffer{}, false)
481 w, _ := wc.NextWriter(BinaryMessage)
482 _, _ = io.WriteString(w, "hello")
482:9discarded-error-resulterror result returned by io.WriteString is discarded

conn_test.go:482:9

481 w, _ := wc.NextWriter(BinaryMessage)
482 _, _ = io.WriteString(w, "hello")
483 if err := w.Close(); err != nil {
482:27add-constantstring literal "hello" appears more than twice; define a constant

conn_test.go:482:27

481 w, _ := wc.NextWriter(BinaryMessage)
482 _, _ = io.WriteString(w, "hello")
483 if err := w.Close(); err != nil {
491:9discarded-error-resulterror result returned by wc.NextWriter is discarded

conn_test.go:491:9

490
491 w, _ = wc.NextWriter(BinaryMessage)
492 _, _ = io.WriteString(w, "hello")
492:9discarded-error-resulterror result returned by io.WriteString is discarded

conn_test.go:492:9

491 w, _ = wc.NextWriter(BinaryMessage)
492 _, _ = io.WriteString(w, "hello")
493
505:6cyclomatic-complexityfunction complexity is 14; maximum is 10

conn_test.go:505:6

504
505func TestReadLimit(t *testing.T) {
506 t.Run("Test ReadLimit is enforced", func(t *testing.T) {
505:6function-lengthfunction has 50 statements and 89 lines; maximum is 50 statements or 75 lines

conn_test.go:505:6

504
505func TestReadLimit(t *testing.T) {
506 t.Run("Test ReadLimit is enforced", func(t *testing.T) {
505:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:505:6

504
505func TestReadLimit(t *testing.T) {
506 t.Run("Test ReadLimit is enforced", func(t *testing.T) {
506:38test-parallelismconsider calling t.Parallel() when this subtest begins

conn_test.go:506:38

505func TestReadLimit(t *testing.T) {
506 t.Run("Test ReadLimit is enforced", func(t *testing.T) {
507 const readLimit = 512
516:11discarded-error-resulterror result returned by wc.NextWriter is discarded

conn_test.go:516:11

515 // Send message at the limit with interleaved pong.
516 w, _ := wc.NextWriter(BinaryMessage)
517 _, _ = w.Write(message[:readLimit-1])
517:10discarded-error-resulterror result returned by w.Write is discarded

conn_test.go:517:10

516 w, _ := wc.NextWriter(BinaryMessage)
517 _, _ = w.Write(message[:readLimit-1])
518 _ = wc.WriteControl(PongMessage, []byte("this is a pong"), time.Now().Add(10*time.Second))
518:7discarded-error-resulterror result returned by wc.WriteControl is discarded

conn_test.go:518:7

517 _, _ = w.Write(message[:readLimit-1])
518 _ = wc.WriteControl(PongMessage, []byte("this is a pong"), time.Now().Add(10*time.Second))
519 _, _ = w.Write(message[:1])
519:10discarded-error-resulterror result returned by w.Write is discarded

conn_test.go:519:10

518 _ = wc.WriteControl(PongMessage, []byte("this is a pong"), time.Now().Add(10*time.Second))
519 _, _ = w.Write(message[:1])
520 w.Close()
520:3discarded-error-resulterror result returned by w.Close is discarded

conn_test.go:520:3

519 _, _ = w.Write(message[:1])
520 w.Close()
521
523:7discarded-error-resulterror result returned by wc.WriteMessage is discarded

conn_test.go:523:7

522 // Send message larger than the limit.
523 _ = wc.WriteMessage(BinaryMessage, message[:readLimit+1])
524
539:52test-parallelismconsider calling t.Parallel() when this subtest begins

conn_test.go:539:52

538
539 t.Run("Test that ReadLimit cannot be overflowed", func(t *testing.T) {
540 const readLimit = 1
565:19add-constantstring literal "\x00\x00\x00\x00" appears more than twice; define a constant

conn_test.go:565:19

564 // Mask key
565 b1.Write([]byte("\x00\x00\x00\x00"))
566
595:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:595:6

594
595func TestAddrs(t *testing.T) {
596 c := newTestConn(nil, nil, true)
598:12error-stringserror string should not be capitalized or end with punctuation

conn_test.go:598:12

597 if c.LocalAddr() != localAddr {
598 t.Errorf("LocalAddr = %v, want %v", c.LocalAddr(), localAddr)
599 }
601:12error-stringserror string should not be capitalized or end with punctuation

conn_test.go:601:12

600 if c.RemoteAddr() != remoteAddr {
601 t.Errorf("RemoteAddr = %v, want %v", c.RemoteAddr(), remoteAddr)
602 }
605:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:605:6

604
605func TestDeprecatedUnderlyingConn(t *testing.T) {
606 var b1, b2 bytes.Buffer
615:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:615:6

614
615func TestNetConn(t *testing.T) {
616 var b1, b2 bytes.Buffer
625:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:625:6

624
625func TestBufioReadBytes(t *testing.T) {
626 // Test calling bufio.ReadBytes for value longer than read buffer size.
635:10discarded-error-resulterror result returned by wc.NextWriter is discarded

conn_test.go:635:10

634
635 w, _ := wc.NextWriter(BinaryMessage)
636 _, _ = w.Write(m)
636:9discarded-error-resulterror result returned by w.Write is discarded

conn_test.go:636:9

635 w, _ := wc.NextWriter(BinaryMessage)
636 _, _ = w.Write(m)
637 w.Close()
637:2discarded-error-resulterror result returned by w.Close is discarded

conn_test.go:637:2

636 _, _ = w.Write(m)
637 w.Close()
638
641:12add-constantstring literal "NextReader() returned %d, %v" appears more than twice; define a constant

conn_test.go:641:12

640 if op != BinaryMessage || err != nil {
641 t.Fatalf("NextReader() returned %d, %v", op, err)
642 }
654:5no-package-varpackage variables introduce mutable global state

conn_test.go:654:5

653
654var closeErrorTests = []struct {
655 err error
654:25nested-structsmove nested anonymous struct types to named declarations

conn_test.go:654:25

653
654var closeErrorTests = []struct {
655 err error
665:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:665:6

664
665func TestCloseError(t *testing.T) {
666 for _, tt := range closeErrorTests {
669:13error-stringserror string should not be capitalized or end with punctuation

conn_test.go:669:13

668 if ok != tt.ok {
669 t.Errorf("IsCloseError(%#v, %#v) returned %v, want %v", tt.err, tt.codes, ok, tt.ok)
670 }
674:5no-package-varpackage variables introduce mutable global state

conn_test.go:674:5

673
674var unexpectedCloseErrorTests = []struct {
675 err error
674:35nested-structsmove nested anonymous struct types to named declarations

conn_test.go:674:35

673
674var unexpectedCloseErrorTests = []struct {
675 err error
685:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:685:6

684
685func TestUnexpectedCloseErrors(t *testing.T) {
686 for _, tt := range unexpectedCloseErrorTests {
689:13error-stringserror string should not be capitalized or end with punctuation

conn_test.go:689:13

688 if ok != tt.ok {
689 t.Errorf("IsUnexpectedCloseError(%#v, %#v) returned %v, want %v", tt.err, tt.codes, ok, tt.ok)
690 }
695:14nested-structsmove nested anonymous struct types to named declarations

conn_test.go:695:14

694type blockingWriter struct {
695 c1, c2 chan struct{}
696}
706:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:706:6

705
706func TestConcurrentWritePanic(t *testing.T) {
707 w := blockingWriter{make(chan struct{}), make(chan struct{})}
707:32nested-structsmove nested anonymous struct types to named declarations

conn_test.go:707:32

706func TestConcurrentWritePanic(t *testing.T) {
707 w := blockingWriter{make(chan struct{}), make(chan struct{})}
708 c := newTestConn(nil, w, false)
707:53nested-structsmove nested anonymous struct types to named declarations

conn_test.go:707:53

706func TestConcurrentWritePanic(t *testing.T) {
707 w := blockingWriter{make(chan struct{}), make(chan struct{})}
708 c := newTestConn(nil, w, false)
710:7discarded-error-resulterror result returned by c.WriteMessage is discarded

conn_test.go:710:7

709 go func() {
710 _ = c.WriteMessage(TextMessage, []byte{})
711 }()
723:6discarded-error-resulterror result returned by c.WriteMessage is discarded

conn_test.go:723:6

722
723 _ = c.WriteMessage(TextMessage, []byte{})
724 t.Fatal("should not get here")
729:7unused-receiverreceiver r is unused

conn_test.go:729:7

728
729func (r failingReader) Read(p []byte) (int, error) {
730 return 0, io.EOF
729:29unused-parameterparameter p is unused

conn_test.go:729:29

728
729func (r failingReader) Read(p []byte) (int, error) {
730 return 0, io.EOF
733:6test-parallelismconsider calling t.Parallel() when this test begins

conn_test.go:733:6

732
733func TestFailedConnectionReadPanic(t *testing.T) {
734 c := newTestConn(failingReader{}, nil, false)
743:3excessive-blank-identifiersassignment discards three or more results; name meaningful results or simplify the return contract

conn_test.go:743:3

742 for i := 0; i < 20000; i++ {
743 _, _, _ = c.ReadMessage()
744 }
743:13discarded-error-resulterror result returned by c.ReadMessage is discarded

conn_test.go:743:13

742 for i := 0; i < 20000; i++ {
743 _, _, _ = c.ReadMessage()
744 }

doc.go1

1:1formatfile is not formatted

doc.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt doc.go`

example_test.go6

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

example_test.go:16:2

15var (
16 c *websocket.Conn
17 req *http.Request
17:2no-package-varpackage variables introduce mutable global state

example_test.go:17:2

16 c *websocket.Conn
17 req *http.Request
18)
41:21unused-parameterparameter mt is unused

example_test.go:41:21

40
41func processMessage(mt int, p []byte) {}
42
41:29unused-parameterparameter p is unused

example_test.go:41:29

40
41func processMessage(mt int, p []byte) {}
42
45:6test-parallelismconsider calling t.Parallel() when this test begins

example_test.go:45:6

44// this function when a second example is added.
45func TestX(t *testing.T) {}
46
45:12unused-parameterparameter t is unused

example_test.go:45:12

44// this function when a second example is added.
45func TestX(t *testing.T) {}
46

examples/autobahn/server.go23

1:1formatfile is not formatted

examples/autobahn/server.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt examples/autobahn/server.go`
6:9package-commentspackage should have a documentation comment

examples/autobahn/server.go:6:9

5// Command server is a test server for the Autobahn WebSockets Test Suite.
6package main
7
20:5no-package-varpackage variables introduce mutable global state

examples/autobahn/server.go:20:5

19
20var upgrader = websocket.Upgrader{
21 ReadBufferSize: 4096,
30:6cognitive-complexityfunction has cognitive complexity 22; maximum is 7

examples/autobahn/server.go:30:6

29// echoCopy echoes messages from the client using io.Copy.
30func echoCopy(w http.ResponseWriter, r *http.Request, writerOnly bool) {
31 conn, err := upgrader.Upgrade(w, r, nil)
30:6cyclomatic-complexityfunction complexity is 12; maximum is 10

examples/autobahn/server.go:30:6

29// echoCopy echoes messages from the client using io.Copy.
30func echoCopy(w http.ResponseWriter, r *http.Request, writerOnly bool) {
31 conn, err := upgrader.Upgrade(w, r, nil)
30:55flag-parameterboolean parameter writerOnly controls function flow

examples/autobahn/server.go:30:55

29// echoCopy echoes messages from the client using io.Copy.
30func echoCopy(w http.ResponseWriter, r *http.Request, writerOnly bool) {
31 conn, err := upgrader.Upgrade(w, r, nil)
46:4modifies-parameterassignment modifies parameter r

examples/autobahn/server.go:46:4

45 if mt == websocket.TextMessage {
46 r = &validator{r: r}
47 }
54:4modifies-parameterassignment modifies parameter r

examples/autobahn/server.go:54:4

53 if mt == websocket.TextMessage {
54 r = &validator{r: r}
55 }
57:21nested-structsmove nested anonymous struct types to named declarations

examples/autobahn/server.go:57:21

56 if writerOnly {
57 _, err = io.Copy(struct{ io.Writer }{w}, r)
58 } else {
63:5discarded-error-resulterror result returned by conn.WriteControl is discarded

examples/autobahn/server.go:63:5

62 if err == errInvalidUTF8 {
63 conn.WriteControl(websocket.CloseMessage,
64 websocket.FormatCloseMessage(websocket.CloseInvalidFramePayloadData, ""),
88:6cognitive-complexityfunction has cognitive complexity 38; maximum is 7

examples/autobahn/server.go:88:6

87// with io.ReadAll.
88func echoReadAll(w http.ResponseWriter, r *http.Request, writeMessage, writePrepared bool) {
89 conn, err := upgrader.Upgrade(w, r, nil)
88:6cyclomatic-complexityfunction complexity is 15; maximum is 10

examples/autobahn/server.go:88:6

87// with io.ReadAll.
88func echoReadAll(w http.ResponseWriter, r *http.Request, writeMessage, writePrepared bool) {
89 conn, err := upgrader.Upgrade(w, r, nil)
88:58flag-parameterboolean parameter writeMessage controls function flow

examples/autobahn/server.go:88:58

87// with io.ReadAll.
88func echoReadAll(w http.ResponseWriter, r *http.Request, writeMessage, writePrepared bool) {
89 conn, err := upgrader.Upgrade(w, r, nil)
88:72flag-parameterboolean parameter writePrepared controls function flow

examples/autobahn/server.go:88:72

87// with io.ReadAll.
88func echoReadAll(w http.ResponseWriter, r *http.Request, writeMessage, writePrepared bool) {
89 conn, err := upgrader.Upgrade(w, r, nil)
105:5discarded-error-resulterror result returned by conn.WriteControl is discarded

examples/autobahn/server.go:105:5

104 if !utf8.Valid(b) {
105 conn.WriteControl(websocket.CloseMessage,
106 websocket.FormatCloseMessage(websocket.CloseInvalidFramePayloadData, ""),
168:2discarded-error-resulterror result returned by io.WriteString is discarded

examples/autobahn/server.go:168:2

167 w.Header().Set("Content-Type", "text/html; charset=utf-8")
168 io.WriteString(w, "<html><body>Echo Server</body></html>")
169}
171:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

examples/autobahn/server.go:171:1

170
171var addr = flag.String("addr", ":9000", "http service address")
172
171:5no-package-varpackage variables introduce mutable global state

examples/autobahn/server.go:171:5

170
171var addr = flag.String("addr", ":9000", "http service address")
172
193:5no-package-varpackage variables introduce mutable global state

examples/autobahn/server.go:193:5

192
193var errInvalidUTF8 = errors.New("invalid utf8")
194
234:5no-package-varpackage variables introduce mutable global state

examples/autobahn/server.go:234:5

233// IN THE SOFTWARE.
234var utf8d = [...]byte{
235 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1f
259:3modifies-parameterassignment modifies parameter x

examples/autobahn/server.go:259:3

258 if state != utf8Accept {
259 x = rune(b&0x3f) | (x << 6)
260 } else {
261:3modifies-parameterassignment modifies parameter x

examples/autobahn/server.go:261:3

260 } else {
261 x = rune((0xff >> t) & b)
262 }
263:2modifies-parameterassignment modifies parameter state

examples/autobahn/server.go:263:2

262 }
263 state = int(utf8d[256+state*16+int(t)])
264 return state, x

examples/chat/client.go16

1:1formatfile is not formatted

examples/chat/client.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt examples/chat/client.go`
5:9package-commentspackage should have a documentation comment

examples/chat/client.go:5:9

4
5package main
6
31:2no-package-varpackage variables introduce mutable global state

examples/chat/client.go:31:2

30var (
31 newline = []byte{'\n'}
32 space = []byte{' '}
32:2no-package-varpackage variables introduce mutable global state

examples/chat/client.go:32:2

31 newline = []byte{'\n'}
32 space = []byte{' '}
33)
35:5no-package-varpackage variables introduce mutable global state

examples/chat/client.go:35:5

34
35var upgrader = websocket.Upgrader{
36 ReadBufferSize: 1024,
59:3discarded-error-resulterror result returned by c.conn.Close is discarded

examples/chat/client.go:59:3

58 c.hub.unregister <- c
59 c.conn.Close()
60 }()
62:2discarded-error-resulterror result returned by c.conn.SetReadDeadline is discarded

examples/chat/client.go:62:2

61 c.conn.SetReadLimit(maxMessageSize)
62 c.conn.SetReadDeadline(time.Now().Add(pongWait))
63 c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
63:45discarded-error-resulterror result returned by c.conn.SetReadDeadline is discarded

examples/chat/client.go:63:45

62 c.conn.SetReadDeadline(time.Now().Add(pongWait))
63 c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
64 for {
82:18cognitive-complexityfunction has cognitive complexity 18; maximum is 7

examples/chat/client.go:82:18

81// executing all writes from this goroutine.
82func (c *Client) writePump() {
83 ticker := time.NewTicker(pingPeriod)
86:3discarded-error-resulterror result returned by c.conn.Close is discarded

examples/chat/client.go:86:3

85 ticker.Stop()
86 c.conn.Close()
87 }()
91:4discarded-error-resulterror result returned by c.conn.SetWriteDeadline is discarded

examples/chat/client.go:91:4

90 case message, ok := <-c.send:
91 c.conn.SetWriteDeadline(time.Now().Add(writeWait))
92 if !ok {
94:5discarded-error-resulterror result returned by c.conn.WriteMessage is discarded

examples/chat/client.go:94:5

93 // The hub closed the channel.
94 c.conn.WriteMessage(websocket.CloseMessage, []byte{})
95 return
102:4discarded-error-resulterror result returned by w.Write is discarded

examples/chat/client.go:102:4

101 }
102 w.Write(message)
103
107:5discarded-error-resulterror result returned by w.Write is discarded

examples/chat/client.go:107:5

106 for i := 0; i < n; i++ {
107 w.Write(newline)
108 w.Write(<-c.send)
108:5discarded-error-resulterror result returned by w.Write is discarded

examples/chat/client.go:108:5

107 w.Write(newline)
108 w.Write(<-c.send)
109 }
115:4discarded-error-resulterror result returned by c.conn.SetWriteDeadline is discarded

examples/chat/client.go:115:4

114 case <-ticker.C:
115 c.conn.SetWriteDeadline(time.Now().Add(writeWait))
116 if err := c.conn.WriteMessage(websocket.PingMessage, nil); err != nil {

examples/chat/hub.go3

5:9package-commentspackage should have a documentation comment

examples/chat/hub.go:5:9

4
5package main
6
9:6exported-declaration-commentexported type should have a comment beginning with its name

examples/chat/hub.go:9:6

8// clients.
9type Hub struct {
10 // Registered clients.
32:15cognitive-complexityfunction has cognitive complexity 13; maximum is 7

examples/chat/hub.go:32:15

31
32func (h *Hub) run() {
33 for {

examples/chat/main.go2

5:9package-commentspackage should have a documentation comment

examples/chat/main.go:5:9

4
5package main
6
13:5no-package-varpackage variables introduce mutable global state

examples/chat/main.go:13:5

12
13var addr = flag.String("addr", ":8080", "http service address")
14

examples/command/main.go21

1:1formatfile is not formatted

examples/command/main.go:1:1

1// Copyright 2015 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt examples/command/main.go`
5:9package-commentspackage should have a documentation comment

examples/command/main.go:5:9

4
5package main
6
21:2no-package-varpackage variables introduce mutable global state

examples/command/main.go:21:2

20var (
21 addr = flag.String("addr", "127.0.0.1:8080", "http service address")
22 cmdPath string
22:2no-package-varpackage variables introduce mutable global state

examples/command/main.go:22:2

21 addr = flag.String("addr", "127.0.0.1:8080", "http service address")
22 cmdPath string
23)
25:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

examples/command/main.go:25:1

24
25const (
26 // Time allowed to write a message to the peer.
45:2discarded-error-resulterror result returned by ws.SetReadDeadline is discarded

examples/command/main.go:45:2

44 ws.SetReadLimit(maxMessageSize)
45 ws.SetReadDeadline(time.Now().Add(pongWait))
46 ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil })
46:41discarded-error-resulterror result returned by ws.SetReadDeadline is discarded

examples/command/main.go:46:41

45 ws.SetReadDeadline(time.Now().Add(pongWait))
46 ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil })
47 for {
59:60nested-structsmove nested anonymous struct types to named declarations

examples/command/main.go:59:60

58
59func pumpStdout(ws *websocket.Conn, r io.Reader, done chan struct{}) {
60 defer func() {
64:3discarded-error-resulterror result returned by ws.SetWriteDeadline is discarded

examples/command/main.go:64:3

63 for s.Scan() {
64 ws.SetWriteDeadline(time.Now().Add(writeWait))
65 if err := ws.WriteMessage(websocket.TextMessage, s.Bytes()); err != nil {
66:4discarded-error-resulterror result returned by ws.Close is discarded

examples/command/main.go:66:4

65 if err := ws.WriteMessage(websocket.TextMessage, s.Bytes()); err != nil {
66 ws.Close()
67 break
75:2discarded-error-resulterror result returned by ws.SetWriteDeadline is discarded

examples/command/main.go:75:2

74
75 ws.SetWriteDeadline(time.Now().Add(writeWait))
76 ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
76:2discarded-error-resulterror result returned by ws.WriteMessage is discarded

examples/command/main.go:76:2

75 ws.SetWriteDeadline(time.Now().Add(writeWait))
76 ws.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
77 time.Sleep(closeGracePeriod)
78:2discarded-error-resulterror result returned by ws.Close is discarded

examples/command/main.go:78:2

77 time.Sleep(closeGracePeriod)
78 ws.Close()
79}
81:41nested-structsmove nested anonymous struct types to named declarations

examples/command/main.go:81:41

80
81func ping(ws *websocket.Conn, done chan struct{}) {
82 ticker := time.NewTicker(pingPeriod)
98:2discarded-error-resulterror result returned by ws.WriteMessage is discarded

examples/command/main.go:98:2

97 log.Println(msg, err)
98 ws.WriteMessage(websocket.TextMessage, []byte("Internal server error."))
99}
101:5no-package-varpackage variables introduce mutable global state

examples/command/main.go:101:5

100
101var upgrader = websocket.Upgrader{}
102
103:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

examples/command/main.go:103:6

102
103func serveWs(w http.ResponseWriter, r *http.Request) {
104 ws, err := upgrader.Upgrade(w, r, nil)
136:2discarded-error-resulterror result returned by inr.Close is discarded

examples/command/main.go:136:2

135
136 inr.Close()
137 outw.Close()
137:2discarded-error-resulterror result returned by outw.Close is discarded

examples/command/main.go:137:2

136 inr.Close()
137 outw.Close()
138
139:26nested-structsmove nested anonymous struct types to named declarations

examples/command/main.go:139:26

138
139 stdoutDone := make(chan struct{})
140 go pumpStdout(ws, outr, stdoutDone)
146:2discarded-error-resulterror result returned by inw.Close is discarded

examples/command/main.go:146:2

145 // Some commands will exit when stdin is closed.
146 inw.Close()
147

examples/echo/client.go7

1:1formatfile is not formatted

examples/echo/client.go:1:1

1// Copyright 2015 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt examples/echo/client.go`
6:1redundant-build-taglegacy +build line is redundant with go:build

examples/echo/client.go:6:1

5//go:build ignore
6// +build ignore
7
8:9package-commentspackage should have a documentation comment

examples/echo/client.go:8:9

7
8package main
9
21:5no-package-varpackage variables introduce mutable global state

examples/echo/client.go:21:5

20
21var addr = flag.String("addr", "localhost:8080", "http service address")
22
23:6cognitive-complexityfunction has cognitive complexity 16; maximum is 7

examples/echo/client.go:23:6

22
23func main() {
24 flag.Parse()
23:6cyclomatic-complexityfunction complexity is 12; maximum is 10

examples/echo/client.go:23:6

22
23func main() {
24 flag.Parse()
39:20nested-structsmove nested anonymous struct types to named declarations

examples/echo/client.go:39:20

38
39 done := make(chan struct{})
40

examples/echo/server.go8

1:1formatfile is not formatted

examples/echo/server.go:1:1

1// Copyright 2015 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt examples/echo/server.go`
6:1redundant-build-taglegacy +build line is redundant with go:build

examples/echo/server.go:6:1

5//go:build ignore
6// +build ignore
7
8:9package-commentspackage should have a documentation comment

examples/echo/server.go:8:9

7
8package main
9
19:5no-package-varpackage variables introduce mutable global state

examples/echo/server.go:19:5

18
19var addr = flag.String("addr", "localhost:8080", "http service address")
20
21:5no-package-varpackage variables introduce mutable global state

examples/echo/server.go:21:5

20
21var upgrader = websocket.Upgrader{} // use default options
22
23:6cognitive-complexityfunction has cognitive complexity 8; maximum is 7

examples/echo/server.go:23:6

22
23func echo(w http.ResponseWriter, r *http.Request) {
24 c, err := upgrader.Upgrade(w, r, nil)
46:26insecure-url-schemeURL uses insecure ws scheme

examples/echo/server.go:46:26

45func home(w http.ResponseWriter, r *http.Request) {
46 homeTemplate.Execute(w, "ws://"+r.Host+"/echo")
47}
57:5no-package-varpackage variables introduce mutable global state

examples/echo/server.go:57:5

56
57var homeTemplate = template.Must(template.New("").Parse(`
58<!DOCTYPE html>

examples/filewatch/main.go16

1:1formatfile is not formatted

examples/filewatch/main.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt examples/filewatch/main.go`
5:9package-commentspackage should have a documentation comment

examples/filewatch/main.go:5:9

4
5package main
6
34:2no-package-varpackage variables introduce mutable global state

examples/filewatch/main.go:34:2

33var (
34 addr = flag.String("addr", ":8080", "http service address")
35 homeTempl = template.Must(template.New("").Parse(homeHTML))
35:2no-package-varpackage variables introduce mutable global state

examples/filewatch/main.go:35:2

34 addr = flag.String("addr", ":8080", "http service address")
35 homeTempl = template.Must(template.New("").Parse(homeHTML))
36 filename string
36:2no-package-varpackage variables introduce mutable global state

examples/filewatch/main.go:36:2

35 homeTempl = template.Must(template.New("").Parse(homeHTML))
36 filename string
37 upgrader = websocket.Upgrader{
37:2no-package-varpackage variables introduce mutable global state

examples/filewatch/main.go:37:2

36 filename string
37 upgrader = websocket.Upgrader{
38 ReadBufferSize: 1024,
61:2discarded-error-resulterror result returned by ws.SetReadDeadline is discarded

examples/filewatch/main.go:61:2

60 ws.SetReadLimit(512)
61 ws.SetReadDeadline(time.Now().Add(pongWait))
62 ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil })
62:41discarded-error-resulterror result returned by ws.SetReadDeadline is discarded

examples/filewatch/main.go:62:41

61 ws.SetReadDeadline(time.Now().Add(pongWait))
62 ws.SetPongHandler(func(string) error { ws.SetReadDeadline(time.Now().Add(pongWait)); return nil })
63 for {
71:6cognitive-complexityfunction has cognitive complexity 20; maximum is 7

examples/filewatch/main.go:71:6

70
71func writer(ws *websocket.Conn, lastMod time.Time) {
72 lastError := ""
78:3discarded-error-resulterror result returned by ws.Close is discarded

examples/filewatch/main.go:78:3

77 fileTicker.Stop()
78 ws.Close()
79 }()
86:7modifies-parameterassignment modifies parameter lastMod

examples/filewatch/main.go:86:7

85
86 p, lastMod, err = readFileIfModified(lastMod)
87
98:5discarded-error-resulterror result returned by ws.SetWriteDeadline is discarded

examples/filewatch/main.go:98:5

97 if p != nil {
98 ws.SetWriteDeadline(time.Now().Add(writeWait))
99 if err := ws.WriteMessage(websocket.TextMessage, p); err != nil {
104:4discarded-error-resulterror result returned by ws.SetWriteDeadline is discarded

examples/filewatch/main.go:104:4

103 case <-pingTicker.C:
104 ws.SetWriteDeadline(time.Now().Add(writeWait))
105 if err := ws.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
145:10nested-structsmove nested anonymous struct types to named declarations

examples/filewatch/main.go:145:10

144 }
145 var v = struct {
146 Host string
154:2discarded-error-resulterror result returned by homeTempl.Execute is discarded

examples/filewatch/main.go:154:2

153 }
154 homeTempl.Execute(w, &v)
155}
170:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

examples/filewatch/main.go:170:1

169
170const homeHTML = `<!DOCTYPE html>
171<html lang="en">

join.go4

1:1formatfile is not formatted

join.go:1:1

1// Copyright 2019 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt join.go`
5:9package-commentspackage should have a documentation comment

join.go:5:9

4
5package websocket
6
15:6exported-declaration-commentexported function or method should have a comment beginning with its name

join.go:15:6

14// support concurrent calls to the Read method.
15func JoinMessages(c *Conn, term string) io.Reader {
16 return &joinReader{c: c, term: term}
19:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

join.go:19:1

18
19type joinReader struct {
20 c *Conn

join_test.go4

1:1formatfile is not formatted

join_test.go:1:1

1// Copyright 2019 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt join_test.go`
14:6cognitive-complexityfunction has cognitive complexity 12; maximum is 7

join_test.go:14:6

13
14func TestJoinMessages(t *testing.T) {
15 messages := []string{"a", "bc", "def", "ghij", "klmno", "0", "12", "345", "6789"}
14:6test-parallelismconsider calling t.Parallel() when this test begins

join_test.go:14:6

13
14func TestJoinMessages(t *testing.T) {
15 messages := []string{"a", "bc", "def", "ghij", "klmno", "0", "12", "345", "6789"}
22:9discarded-error-resulterror result returned by wc.WriteMessage is discarded

join_test.go:22:9

21 for _, m := range messages {
22 _ = wc.WriteMessage(BinaryMessage, []byte(m))
23 }

json.go9

5:9package-commentspackage should have a documentation comment

json.go:5:9

4
5package websocket
6
15:6exported-declaration-commentexported function or method should have a comment beginning with its name

json.go:15:6

14// Deprecated: Use c.WriteJSON instead.
15func WriteJSON(c *Conn, v interface{}) error {
16 return c.WriteJSON(v)
15:27use-anyuse any instead of interface{}

json.go:15:27

14// Deprecated: Use c.WriteJSON instead.
15func WriteJSON(c *Conn, v interface{}) error {
16 return c.WriteJSON(v)
23:16exported-declaration-commentexported function or method should have a comment beginning with its name

json.go:23:16

22// conversion of Go values to JSON.
23func (c *Conn) WriteJSON(v interface{}) error {
24 w, err := c.NextWriter(TextMessage)
23:28use-anyuse any instead of interface{}

json.go:23:28

22// conversion of Go values to JSON.
23func (c *Conn) WriteJSON(v interface{}) error {
24 w, err := c.NextWriter(TextMessage)
40:6exported-declaration-commentexported function or method should have a comment beginning with its name

json.go:40:6

39// Deprecated: Use c.ReadJSON instead.
40func ReadJSON(c *Conn, v interface{}) error {
41 return c.ReadJSON(v)
40:26use-anyuse any instead of interface{}

json.go:40:26

39// Deprecated: Use c.ReadJSON instead.
40func ReadJSON(c *Conn, v interface{}) error {
41 return c.ReadJSON(v)
49:16exported-declaration-commentexported function or method should have a comment beginning with its name

json.go:49:16

48// about the conversion of JSON to a Go value.
49func (c *Conn) ReadJSON(v interface{}) error {
50 _, r, err := c.NextReader()
49:27use-anyuse any instead of interface{}

json.go:49:27

48// about the conversion of JSON to a Go value.
49func (c *Conn) ReadJSON(v interface{}) error {
50 _, r, err := c.NextReader()

json_test.go9

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

json_test.go:15:6

14
15func TestJSON(t *testing.T) {
16 var buf bytes.Buffer
20:21nested-structsmove nested anonymous struct types to named declarations

json_test.go:20:21

19
20 var actual, expect struct {
21 A int
40:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

json_test.go:40:6

39
40func TestPartialJSONRead(t *testing.T) {
41 var buf0, buf1 bytes.Buffer
40:6test-parallelismconsider calling t.Parallel() when this test begins

json_test.go:40:6

39
40func TestPartialJSONRead(t *testing.T) {
41 var buf0, buf1 bytes.Buffer
45:8nested-structsmove nested anonymous struct types to named declarations

json_test.go:45:8

44
45 var v struct {
46 A int
93:6test-parallelismconsider calling t.Parallel() when this test begins

json_test.go:93:6

92
93func TestDeprecatedJSON(t *testing.T) {
94 var buf bytes.Buffer
98:21nested-structsmove nested anonymous struct types to named declarations

json_test.go:98:21

97
98 var actual, expect struct {
99 A int
103:13add-constantstring literal "hello" appears more than twice; define a constant

json_test.go:103:13

102 expect.A = 1
103 expect.B = "hello"
104
110:11add-constantstring literal "read" appears more than twice; define a constant

json_test.go:110:11

109 if err := ReadJSON(rc, &actual); err != nil {
110 t.Fatal("read", err)
111 }

mask.go12

6:1redundant-build-taglegacy +build line is redundant with go:build

mask.go:6:1

5//go:build !appengine
6// +build !appengine
7
8:9package-commentspackage should have a documentation comment

mask.go:8:9

7
8package websocket
9
12:36redundant-conversionconversion from uintptr to the identical type is redundant

mask.go:12:36

11
12const wordSize = int(unsafe.Sizeof(uintptr(0)))
13
14:6cognitive-complexityfunction has cognitive complexity 9; maximum is 7

mask.go:14:6

13
14func maskBytes(key [4]byte, pos int, b []byte) int {
15 // Mask one byte at a time for small buffers.
18:4modifies-parameterassignment modifies parameter b

mask.go:18:4

17 for i := range b {
18 b[i] ^= key[pos&3]
19 pos++
19:4modifies-parameterassignment modifies parameter pos

mask.go:19:4

18 b[i] ^= key[pos&3]
19 pos++
20 }
28:4modifies-parameterassignment modifies parameter b

mask.go:28:4

27 for i := range b[:n] {
28 b[i] ^= key[pos&3]
29 pos++
29:4modifies-parameterassignment modifies parameter pos

mask.go:29:4

28 b[i] ^= key[pos&3]
29 pos++
30 }
31:3modifies-parameterassignment modifies parameter b

mask.go:31:3

30 }
31 b = b[n:]
32 }
48:2modifies-parameterassignment modifies parameter b

mask.go:48:2

47 // Mask one byte at a time for remaining bytes.
48 b = b[n:]
49 for i := range b {
50:3modifies-parameterassignment modifies parameter b

mask.go:50:3

49 for i := range b {
50 b[i] ^= key[pos&3]
51 pos++
51:3modifies-parameterassignment modifies parameter pos

mask.go:51:3

50 b[i] ^= key[pos&3]
51 pos++
52 }

mask_safe.go4

6:1redundant-build-taglegacy +build line is redundant with go:build

mask_safe.go:6:1

5//go:build appengine
6// +build appengine
7
8:9package-commentspackage should have a documentation comment

mask_safe.go:8:9

7
8package websocket
9
12:3modifies-parameterassignment modifies parameter b

mask_safe.go:12:3

11 for i := range b {
12 b[i] ^= key[pos&3]
13 pos++
13:3modifies-parameterassignment modifies parameter pos

mask_safe.go:13:3

12 b[i] ^= key[pos&3]
13 pos++
14 }

mask_test.go10

1:1formatfile is not formatted

mask_test.go:1:1

1// Copyright 2016 The Gorilla WebSocket Authors. All rights reserved. Use of
2// this source code is governed by a BSD-style license that can be found in the
  • Fix (safe): run `strider fmt mask_test.go`
16:3modifies-parameterassignment modifies parameter b

mask_test.go:16:3

15 for i := range b {
16 b[i] ^= key[pos&3]
17 pos++
17:3modifies-parameterassignment modifies parameter pos

mask_test.go:17:3

16 b[i] ^= key[pos&3]
17 pos++
18 }
31:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

mask_test.go:31:6

30
31func TestMaskBytes(t *testing.T) {
32 key := [4]byte{1, 2, 3, 4}
31:6test-parallelismconsider calling t.Parallel() when this test begins

mask_test.go:31:6

30
31func TestMaskBytes(t *testing.T) {
32 key := [4]byte{1, 2, 3, 4}
47:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

mask_test.go:47:6

46
47func BenchmarkMaskBytes(b *testing.B) {
48 for _, size := range []int{2, 4, 8, 16, 32, 512, 1024} {
52:27nested-structsmove nested anonymous struct types to named declarations

mask_test.go:52:27

51 b.Run(fmt.Sprintf("align-%d", align), func(b *testing.B) {
52 for _, fn := range []struct {
53 name string
59:22range-value-captureclosure captures reused range variable align

mask_test.go:59:22

58 } {
59 b.Run(fn.name, func(b *testing.B) {
60 key := newMaskKey()
59:22range-value-captureclosure captures reused range variable fn

mask_test.go:59:22

58 } {
59 b.Run(fn.name, func(b *testing.B) {
60 key := newMaskKey()
59:22range-value-captureclosure captures reused range variable size

mask_test.go:59:22

58 } {
59 b.Run(fn.name, func(b *testing.B) {
60 key := newMaskKey()

prepared.go11

1:1formatfile is not formatted

prepared.go:1:1

1// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt prepared.go`
5:9package-commentspackage should have a documentation comment

prepared.go:5:9

4
5package websocket
6
19:6exported-declaration-commentexported type should have a comment beginning with its name

prepared.go:19:6

18// once for a given set of compression options.
19type PreparedMessage struct {
20 messageType int
43:6exported-declaration-commentexported function or method should have a comment beginning with its name

prepared.go:43:6

42// connection options.
43func NewPreparedMessage(messageType int, data []byte) (*PreparedMessage, error) {
44 pm := &PreparedMessage{
74:3task-commentTODO comment should be resolved or linked to an owned work item

prepared.go:74:3

73 // Prepare a frame using a 'fake' connection.
74 // TODO: Refactor code in conn.go to allow more direct construction of
75 // the frame.
76:19nested-structsmove nested anonymous struct types to named declarations

prepared.go:76:19

75 // the frame.
76 mu := make(chan struct{}, 1)
77 mu <- struct{}{}
77:9nested-structsmove nested anonymous struct types to named declarations

prepared.go:77:9

76 mu := make(chan struct{}, 1)
77 mu <- struct{}{}
78 var nc prepareConn
96:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

prepared.go:96:1

95
96type prepareConn struct {
97 buf bytes.Buffer
102:7unused-receiverreceiver pc is unused

prepared.go:102:7

101func (pc *prepareConn) Write(p []byte) (int, error) { return pc.buf.Write(p) }
102func (pc *prepareConn) SetWriteDeadline(t time.Time) error { return nil }
103
102:24exported-declaration-commentexported function or method should have a comment beginning with its name

prepared.go:102:24

101func (pc *prepareConn) Write(p []byte) (int, error) { return pc.buf.Write(p) }
102func (pc *prepareConn) SetWriteDeadline(t time.Time) error { return nil }
103
102:41unused-parameterparameter t is unused

prepared.go:102:41

101func (pc *prepareConn) Write(p []byte) (int, error) { return pc.buf.Write(p) }
102func (pc *prepareConn) SetWriteDeadline(t time.Time) error { return nil }
103

prepared_test.go4

1:1formatfile is not formatted

prepared_test.go:1:1

1// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt prepared_test.go`
14:5no-package-varpackage variables introduce mutable global state

prepared_test.go:14:5

13
14var preparedMessageTests = []struct {
15 messageType int
14:30nested-structsmove nested anonymous struct types to named declarations

prepared_test.go:14:30

13
14var preparedMessageTests = []struct {
15 messageType int
35:6cognitive-complexityfunction has cognitive complexity 13; maximum is 7

prepared_test.go:35:6

34
35func TestPreparedMessage(t *testing.T) {
36 testRand := rand.New(rand.NewSource(99))

proxy.go11

1:1formatfile is not formatted

proxy.go:1:1

1// Copyright 2017 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt proxy.go`
5:9package-commentspackage should have a documentation comment

proxy.go:5:9

4
5package websocket
6
23:25exported-declaration-commentexported function or method should have a comment beginning with its name

proxy.go:23:25

22
23func (fn netDialerFunc) Dial(network, addr string) (net.Conn, error) {
24 return fn(context.Background(), network, addr)
27:25exported-declaration-commentexported function or method should have a comment beginning with its name

proxy.go:27:25

26
27func (fn netDialerFunc) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
28 return fn(ctx, network, addr)
42:35import-shadowingidentifier net shadows an imported package

proxy.go:42:35

41 }
42 return func(ctx context.Context, net, addr string) (net.Conn, error) {
43 return dialer.Dial(net, addr)
47:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

proxy.go:47:1

46
47type httpProxyDialer struct {
48 proxyURL *url.URL
52:29exported-declaration-commentexported function or method should have a comment beginning with its name

proxy.go:52:29

51
52func (hpd *httpProxyDialer) DialContext(ctx context.Context, network string, addr string) (net.Conn, error) {
53 hostPort, _ := hostPortNoPort(hpd.proxyURL)
75:3discarded-error-resulterror result returned by conn.Close is discarded

proxy.go:75:3

74 if err := connectReq.Write(conn); err != nil {
75 conn.Close()
76 return nil, err
84:3discarded-error-resulterror result returned by conn.Close is discarded

proxy.go:84:3

83 if err != nil {
84 conn.Close()
85 return nil, err
96:6discarded-error-resulterror result returned by resp.Body.Close is discarded

proxy.go:96:6

95 br.Reset(bytes.NewReader(nil))
96 _ = resp.Body.Close()
97
99:7discarded-error-resulterror result returned by conn.Close is discarded

proxy.go:99:7

98 if resp.StatusCode != http.StatusOK {
99 _ = conn.Close()
100 f := strings.SplitN(resp.Status, " ", 2)

server.go18

1:1formatfile is not formatted

server.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt server.go`
5:9package-commentspackage should have a documentation comment

server.go:5:9

4
5package websocket
6
27:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

server.go:27:1

26// It is safe to call Upgrader's methods concurrently.
27type Upgrader struct {
28 // HandshakeTimeout specifies the duration for the handshake to complete.
27:6exported-declaration-commentexported type should have a comment beginning with its name

server.go:27:6

26// It is safe to call Upgrader's methods concurrently.
27type Upgrader struct {
28 // HandshakeTimeout specifies the duration for the handshake to complete.
100:20cognitive-complexityfunction has cognitive complexity 12; maximum is 7

server.go:100:20

99
100func (u *Upgrader) selectSubprotocol(r *http.Request, responseHeader http.Header) string {
101 if u.Subprotocols != nil {
124:20cognitive-complexityfunction has cognitive complexity 48; maximum is 7

server.go:124:20

123// response.
124func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) {
125 const badHandshake = "websocket: the client is not using the websocket protocol: "
124:20cyclomatic-complexityfunction complexity is 35; maximum is 10

server.go:124:20

123// response.
124func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) {
125 const badHandshake = "websocket: the client is not using the websocket protocol: "
124:20exported-declaration-commentexported function or method should have a comment beginning with its name

server.go:124:20

123// response.
124func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) {
125 const badHandshake = "websocket: the client is not using the websocket protocol: "
124:20function-lengthfunction has 85 statements and 161 lines; maximum is 50 statements or 75 lines

server.go:124:20

123// response.
124func (u *Upgrader) Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header) (*Conn, error) {
125 const badHandshake = "websocket: the client is not using the websocket protocol: "
189:8discarded-error-resulterror result returned by netConn.Close is discarded

server.go:189:8

188 // application.
189 _ = netConn.Close()
190 }
254:18add-constantstring literal "\r\n" appears more than twice; define a constant

server.go:254:18

253 }
254 p = append(p, "\r\n"...)
255 }
316:6exported-declaration-commentexported function or method should have a comment beginning with its name

server.go:316:6

315// replying to the client with an HTTP error response.
316func Upgrade(w http.ResponseWriter, r *http.Request, responseHeader http.Header, readBufSize, writeBufSize int) (*Conn, error) {
317 u := Upgrader{ReadBufferSize: readBufSize, WriteBufferSize: writeBufSize}
330:6exported-declaration-commentexported function or method should have a comment beginning with its name

server.go:330:6

329// Sec-Websocket-Protocol header.
330func Subprotocols(r *http.Request) []string {
331 h := strings.TrimSpace(r.Header.Get("Sec-Websocket-Protocol"))
331:38add-constantstring literal "Sec-Websocket-Protocol" appears more than twice; define a constant

server.go:331:38

330func Subprotocols(r *http.Request) []string {
331 h := strings.TrimSpace(r.Header.Get("Sec-Websocket-Protocol"))
332 if h == "" {
344:6exported-declaration-commentexported function or method should have a comment beginning with its name

server.go:344:6

343// WebSocket protocol.
344func IsWebSocketUpgrade(r *http.Request) bool {
345 return tokenListContainsValue(r.Header, "Connection", "upgrade") &&
346:36add-constantstring literal "Upgrade" appears more than twice; define a constant

server.go:346:36

345 return tokenListContainsValue(r.Header, "Connection", "upgrade") &&
346 tokenListContainsValue(r.Header, "Upgrade", "websocket")
347}
346:47add-constantstring literal "websocket" appears more than twice; define a constant

server.go:346:47

345 return tokenListContainsValue(r.Header, "Connection", "upgrade") &&
346 tokenListContainsValue(r.Header, "Upgrade", "websocket")
347}
358:4modifies-parameterassignment modifies parameter p

server.go:358:4

357 if n := b.br.Buffered(); len(p) > n {
358 p = p[:n]
359 }

server_test.go29

1:1formatfile is not formatted

server_test.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt server_test.go`
19:5no-package-varpackage variables introduce mutable global state

server_test.go:19:5

18
19var subprotocolTests = []struct {
20 h string
19:26nested-structsmove nested anonymous struct types to named declarations

server_test.go:19:26

18
19var subprotocolTests = []struct {
20 h string
31:6test-parallelismconsider calling t.Parallel() when this test begins

server_test.go:31:6

30
31func TestSubprotocols(t *testing.T) {
32 for _, st := range subprotocolTests {
36:13error-stringserror string should not be capitalized or end with punctuation

server_test.go:36:13

35 if !reflect.DeepEqual(st.protocols, protocols) {
36 t.Errorf("SubProtocols(%q) returned %#v, want %#v", st.h, protocols, st.protocols)
37 }
41:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

server_test.go:41:1

40
41var isWebSocketUpgradeTests = []struct {
42 ok bool
41:5no-package-varpackage variables introduce mutable global state

server_test.go:41:5

40
41var isWebSocketUpgradeTests = []struct {
42 ok bool
41:33nested-structsmove nested anonymous struct types to named declarations

server_test.go:41:33

40
41var isWebSocketUpgradeTests = []struct {
42 ok bool
50:6test-parallelismconsider calling t.Parallel() when this test begins

server_test.go:50:6

49
50func TestIsWebSocketUpgrade(t *testing.T) {
51 for _, tt := range isWebSocketUpgradeTests {
52:28range-value-addresstaking the address of range value tt can be misleading

server_test.go:52:28

51 for _, tt := range isWebSocketUpgradeTests {
52 ok := IsWebSocketUpgrade(&http.Request{Header: tt.h})
53 if tt.ok != ok {
54:13error-stringserror string should not be capitalized or end with punctuation

server_test.go:54:13

53 if tt.ok != ok {
54 t.Errorf("IsWebSocketUpgrade(%v) returned %v, want %v", tt.h, ok, tt.ok)
55 }
59:6test-parallelismconsider calling t.Parallel() when this test begins

server_test.go:59:6

58
59func TestSubProtocolSelection(t *testing.T) {
60 upgrader := Upgrader{
66:10add-constantstring literal "foo" appears more than twice; define a constant

server_test.go:66:10

65 s := upgrader.selectSubprotocol(&r, nil)
66 if s != "foo" {
67 t.Errorf("Upgrader.selectSubprotocol returned %v, want %v", s, "foo")
67:12error-stringserror string should not be capitalized or end with punctuation

server_test.go:67:12

66 if s != "foo" {
67 t.Errorf("Upgrader.selectSubprotocol returned %v, want %v", s, "foo")
68 }
70:39add-constantstring literal "Sec-Websocket-Protocol" appears more than twice; define a constant

server_test.go:70:39

69
70 r = http.Request{Header: http.Header{"Sec-Websocket-Protocol": {"bar", "foo"}}}
71 s = upgrader.selectSubprotocol(&r, nil)
70:66add-constantstring literal "bar" appears more than twice; define a constant

server_test.go:70:66

69
70 r = http.Request{Header: http.Header{"Sec-Websocket-Protocol": {"bar", "foo"}}}
71 s = upgrader.selectSubprotocol(&r, nil)
73:12error-stringserror string should not be capitalized or end with punctuation

server_test.go:73:12

72 if s != "bar" {
73 t.Errorf("Upgrader.selectSubprotocol returned %v, want %v", s, "bar")
74 }
78:10add-constantstring literal "baz" appears more than twice; define a constant

server_test.go:78:10

77 s = upgrader.selectSubprotocol(&r, nil)
78 if s != "baz" {
79 t.Errorf("Upgrader.selectSubprotocol returned %v, want %v", s, "baz")
79:12add-constantstring literal "Upgrader.selectSubprotocol returned %v, want %v" appears more than twice; define a constant

server_test.go:79:12

78 if s != "baz" {
79 t.Errorf("Upgrader.selectSubprotocol returned %v, want %v", s, "baz")
80 }
79:12error-stringserror string should not be capitalized or end with punctuation

server_test.go:79:12

78 if s != "baz" {
79 t.Errorf("Upgrader.selectSubprotocol returned %v, want %v", s, "baz")
80 }
85:12error-stringserror string should not be capitalized or end with punctuation

server_test.go:85:12

84 if s != "" {
85 t.Errorf("Upgrader.selectSubprotocol returned %v, want %v", s, "empty string")
86 }
89:5no-package-varpackage variables introduce mutable global state

server_test.go:89:5

88
89var checkSameOriginTests = []struct {
90 ok bool
89:30nested-structsmove nested anonymous struct types to named declarations

server_test.go:89:30

88
89var checkSameOriginTests = []struct {
90 ok bool
98:6test-parallelismconsider calling t.Parallel() when this test begins

server_test.go:98:6

97
98func TestCheckSameOrigin(t *testing.T) {
99 for _, tt := range checkSameOriginTests {
112:38exported-declaration-commentexported function or method should have a comment beginning with its name

server_test.go:112:38

111
112func (resp *reuseTestResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
113 return fakeNetConn{strings.NewReader(""), &bytes.Buffer{}}, resp.brw, nil
116:5no-package-varpackage variables introduce mutable global state

server_test.go:116:5

115
116var bufioReuseTests = []struct {
117 n int
116:25nested-structsmove nested anonymous struct types to named declarations

server_test.go:116:25

115
116var bufioReuseTests = []struct {
117 n int
156:45insecure-url-schemeURL uses insecure http scheme

server_test.go:156:45

155
156 req := httptest.NewRequest(http.MethodGet, "http://example.com", nil)
157 req.Header.Set("Upgrade", "websocket")
167:33optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

server_test.go:167:33

166
167 if want := (HandshakeError{}); !errors.As(err, &want) || recorder.Code != http.StatusInternalServerError {
168 t.Errorf("want %T and status_code=%d", want, http.StatusInternalServerError)

util.go18

1:1formatfile is not formatted

util.go:1:1

1// Copyright 2013 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt util.go`
5:9package-commentspackage should have a documentation comment

util.go:5:9

4
5package websocket
6
17:5no-package-varpackage variables introduce mutable global state

util.go:17:5

16
17var keyGUID = []byte("258EAFA5-E914-47DA-95CA-C5AB0DC85B11")
18
20:7weak-cryptographydeprecated cryptographic primitive crypto/sha1.New should not protect new data

util.go:20:7

19func computeAcceptKey(challengeKey string) string {
20 h := sha1.New()
21 h.Write([]byte(challengeKey))
35:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

util.go:35:1

34// Token octets per RFC 2616.
35var isTokenOctet = [256]bool{
36 '!': true,
35:5no-package-varpackage variables introduce mutable global state

util.go:35:5

34// Token octets per RFC 2616.
35var isTokenOctet = [256]bool{
36 '!': true,
141:6cognitive-complexityfunction has cognitive complexity 11; maximum is 7

util.go:141:6

140// and the string following the token or quoted string.
141func nextTokenOrQuoted(s string) (value string, rest string) {
142 if !strings.HasPrefix(s, "\"") {
145:2modifies-parameterassignment modifies parameter s

util.go:145:2

144 }
145 s = s[1:]
146 for i := 0; i < len(s); i++ {
147:3single-case-switchswitch with one case can be replaced by an if statement

util.go:147:3

146 for i := 0; i < len(s); i++ {
147 switch s[i] {
148 case '"':
154:8increment-decrementuse ++ or -- instead of assigning an addition or subtraction of one

util.go:154:8

153 escape := true
154 for i = i + 1; i < len(s); i++ {
155 b := s[i]
156:5single-case-switchswitch with one case can be replaced by an if statement

util.go:156:5

155 b := s[i]
156 switch {
157 case escape:
178:6cognitive-complexityfunction has cognitive complexity 10; maximum is 7

util.go:178:6

177// defined in RFC 4790.
178func equalASCIIFold(s, t string) bool {
179 for s != "" && t != "" {
181:3modifies-parameterassignment modifies parameter s

util.go:181:3

180 sr, size := utf8.DecodeRuneInString(s)
181 s = s[size:]
182 tr, size := utf8.DecodeRuneInString(t)
183:3modifies-parameterassignment modifies parameter t

util.go:183:3

182 tr, size := utf8.DecodeRuneInString(t)
183 t = t[size:]
184 if sr == tr {
202:6cognitive-complexityfunction has cognitive complexity 18; maximum is 7

util.go:202:6

201// name contains a token equal to value with ASCII case folding.
202func tokenListContainsValue(header http.Header, name string, value string) bool {
203headers:
228:6cognitive-complexityfunction has cognitive complexity 37; maximum is 7

util.go:228:6

227// parseExtensions parses WebSocket extensions from a header.
228func parseExtensions(header http.Header) []map[string]string {
229 // From RFC 6455:
228:6cyclomatic-complexityfunction complexity is 14; maximum is 10

util.go:228:6

227// parseExtensions parses WebSocket extensions from a header.
228func parseExtensions(header http.Header) []map[string]string {
229 // From RFC 6455:
267:8optimize-operands-orderplace the cheaper logical operand first to improve short-circuiting

util.go:267:8

266 }
267 if s != "" && s[0] != ',' && s[0] != ';' {
268 continue headers

util_test.go14

1:1formatfile is not formatted

util_test.go:1:1

1// Copyright 2014 The Gorilla WebSocket Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style
  • Fix (safe): run `strider fmt util_test.go`
13:5no-package-varpackage variables introduce mutable global state

util_test.go:13:5

12
13var equalASCIIFoldTests = []struct {
14 t, s string
13:29nested-structsmove nested anonymous struct types to named declarations

util_test.go:13:29

12
13var equalASCIIFoldTests = []struct {
14 t, s string
23:6test-parallelismconsider calling t.Parallel() when this test begins

util_test.go:23:6

22
23func TestEqualASCIIFold(t *testing.T) {
24 for _, tt := range equalASCIIFoldTests {
32:1top-level-declaration-ordertop-level declarations should be ordered as const, var, type, then func

util_test.go:32:1

31
32var tokenListContainsValueTests = []struct {
33 value string
32:5no-package-varpackage variables introduce mutable global state

util_test.go:32:5

31
32var tokenListContainsValueTests = []struct {
33 value string
32:37nested-structsmove nested anonymous struct types to named declarations

util_test.go:32:37

31
32var tokenListContainsValueTests = []struct {
33 value string
46:6test-parallelismconsider calling t.Parallel() when this test begins

util_test.go:46:6

45
46func TestTokenListContainsValue(t *testing.T) {
47 for _, tt := range tokenListContainsValueTests {
56:5no-package-varpackage variables introduce mutable global state

util_test.go:56:5

55
56var isValidChallengeKeyTests = []struct {
57 key string
56:34nested-structsmove nested anonymous struct types to named declarations

util_test.go:56:34

55
56var isValidChallengeKeyTests = []struct {
57 key string
66:6test-parallelismconsider calling t.Parallel() when this test begins

util_test.go:66:6

65
66func TestIsValidChallengeKey(t *testing.T) {
67 for _, tt := range isValidChallengeKeyTests {
75:5no-package-varpackage variables introduce mutable global state

util_test.go:75:5

74
75var parseExtensionTests = []struct {
76 value string
75:29nested-structsmove nested anonymous struct types to named declarations

util_test.go:75:29

74
75var parseExtensionTests = []struct {
76 value string
107:6test-parallelismconsider calling t.Parallel() when this test begins

util_test.go:107:6

106
107func TestParseExtensions(t *testing.T) {
108 for _, tt := range parseExtensionTests {