Naming, layout and comments: descriptive full-word names, one item per line in wrapped calls and literals, and doc comments on exported names

Short and single-letter names in application code become full words (tests
keep theirs). Wrapped calls, signatures and composite literals put one item
per line, and one-line function bodies are expanded. Exported names and
groups of constants get doc comments, and comments refer to the renamed
identifiers.
This commit is contained in:
bwilliams committed 2026-10-15 16:12:56 +01:00
1 parent 043e307663
commit 465358609a
78 files changed
+2374 -1402

No files matched your search

+31 -8
View File
@@ -35,7 +35,9 @@ func dialWS(t *testing.T, ctx context.Context, url string) *ws.Conn {
if err != nil {
t.Fatalf("dial: %v", err)
}
t.Cleanup(func() { conn.CloseNow() })
t.Cleanup(func() {
conn.CloseNow()
})
var e Envelope
if err := wsjson.Read(ctx, conn, &e); err != nil || e.Type != TypeWelcome {
t.Fatalf("want welcome, got %+v, %v", e, err)
@@ -46,13 +48,21 @@ func dialWS(t *testing.T, ctx context.Context, url string) *ws.Conn {
// A client upgraded over HTTP gets replies. A max_message_size of 0 uses the
// default limit rather than refusing every message.
func TestHTTPMessages(t *testing.T) {
h := NewHub(config.JSCServerWebSocket{WriteTimeout: time.Second}, WithLogger(discardLog))
h := NewHub(
config.JSCServerWebSocket{
WriteTimeout: time.Second,
},
WithLogger(discardLog),
)
url := wsHub(t, h)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
conn := dialWS(t, ctx, url)
if err := wsjson.Write(ctx, conn, Envelope{Type: TypePing, ID: "1"}); err != nil {
if err := wsjson.Write(ctx, conn, Envelope{
Type: TypePing,
ID: "1",
}); err != nil {
t.Fatal(err)
}
var e Envelope
@@ -89,7 +99,8 @@ func TestPushBadPayload(t *testing.T) {
c.read() // welcome
waitCount(t, h, 1)
h.Push("bad", func() {})
h.Push("bad", func() {
})
h.Push("good", nil)
if e := c.read(); e.Type != "good" || e.Payload != nil {
t.Fatalf("want good with no payload, got %+v", e)
@@ -98,7 +109,12 @@ func TestPushBadPayload(t *testing.T) {
// A binary frame closes the connection with 1003 (unsupported data).
func TestHTTPBinaryFrame(t *testing.T) {
h := NewHub(config.JSCServerWebSocket{WriteTimeout: time.Second}, WithLogger(discardLog))
h := NewHub(
config.JSCServerWebSocket{
WriteTimeout: time.Second,
},
WithLogger(discardLog),
)
url := wsHub(t, h)
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
defer cancel()
@@ -117,8 +133,12 @@ func TestHTTPBinaryFrame(t *testing.T) {
// handled; the connection stays open.
func TestHTTPMessageRateLimit(t *testing.T) {
conf := config.JSCServerWebSocket{
WriteTimeout: time.Second,
MessageRateLimit: config.JSCRateLimitRule{Enabled: true, PerSecond: 1, Burst: 1},
WriteTimeout: time.Second,
MessageRateLimit: config.JSCRateLimitRule{
Enabled: true,
PerSecond: 1,
Burst: 1,
},
}
h := NewHub(conf, WithLogger(discardLog))
url := wsHub(t, h)
@@ -127,7 +147,10 @@ func TestHTTPMessageRateLimit(t *testing.T) {
conn := dialWS(t, ctx, url)
for _, id := range []string{"1", "2"} {
if err := wsjson.Write(ctx, conn, Envelope{Type: TypePing, ID: id}); err != nil {
if err := wsjson.Write(ctx, conn, Envelope{
Type: TypePing,
ID: id,
}); err != nil {
t.Fatal(err)
}
}