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

+30 -10
View File
@@ -23,10 +23,14 @@ var discardLog = slog.New(slog.NewTextHandler(io.Discard, nil))
// not nil.
func testConf(mutate func(*config.JSCServer)) *config.JSCServer {
c := &config.JSCServer{
Host: "127.0.0.1",
Port: 0,
WebSocket: config.JSCServerWebSocket{WriteTimeout: time.Second},
Timeouts: config.JSCServerTimeouts{ShutdownTimeout: time.Second},
Host: "127.0.0.1",
Port: 0,
WebSocket: config.JSCServerWebSocket{
WriteTimeout: time.Second,
},
Timeouts: config.JSCServerTimeouts{
ShutdownTimeout: time.Second,
},
}
if mutate != nil {
mutate(c)
@@ -54,7 +58,9 @@ func startServer(
ctx, cancel := context.WithCancel(context.Background())
t.Cleanup(cancel)
done := make(chan error, 1)
go func() { done <- s.serve(ctx, ln) }()
go func() {
done <- s.serve(ctx, ln)
}()
return h, ln.Addr().String(), cancel, done
}
@@ -71,8 +77,14 @@ func dial(t *testing.T, addr string) *tcpClient {
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { conn.Close() })
return &tcpClient{t: t, conn: conn, r: bufio.NewReader(conn)}
t.Cleanup(func() {
conn.Close()
})
return &tcpClient{
t: t,
conn: conn,
r: bufio.NewReader(conn),
}
}
// read returns the next envelope, failing the test after a second.
@@ -188,7 +200,9 @@ func TestServerRun(t *testing.T) {
}
func TestServerRunListenError(t *testing.T) {
s, _ := newServer(testConf(func(c *config.JSCServer) { c.Port = -1 }))
s, _ := newServer(testConf(func(c *config.JSCServer) {
c.Port = -1
}))
if err := s.Run(context.Background()); err == nil || !strings.Contains(err.Error(), "listen") {
t.Fatalf("Run = %v; want a listen error", err)
}
@@ -217,7 +231,10 @@ func TestServerAcceptRetries(t *testing.T) {
t.Fatal(err)
}
defer ln.Close()
fl := &flakyListener{Listener: ln, fails: 3}
fl := &flakyListener{
Listener: ln,
fails: 3,
}
err = s.accept(context.Background(), context.Background(), fl)
if !errors.Is(err, net.ErrClosed) || fl.fails != 0 {
t.Fatalf("accept = %v with %d failures left; want net.ErrClosed", err, fl.fails)
@@ -233,7 +250,10 @@ func TestServerAcceptCancelledInBackOff(t *testing.T) {
}
defer ln.Close()
ctx, cancel := context.WithCancel(context.Background())
fl := &flakyListener{Listener: ln, fails: 1 << 30}
fl := &flakyListener{
Listener: ln,
fails: 1 << 30,
}
time.AfterFunc(20*time.Millisecond, cancel)
if err := s.accept(ctx, ctx, fl); !errors.Is(err, context.Canceled) {
t.Fatalf("accept = %v; want context.Canceled", err)