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

+50 -14
View File
@@ -17,12 +17,16 @@ func quietLog(t *testing.T) {
t.Helper()
w := log.Writer()
log.SetOutput(io.Discard)
t.Cleanup(func() { log.SetOutput(w) })
t.Cleanup(func() {
log.SetOutput(w)
})
}
func TestGap(t *testing.T) {
//nolint:gosec // G404: seeded math/rand keeps the test deterministic
g := &Generator{rnd: rand.New(rand.NewSource(1))}
g := &Generator{
rnd: rand.New(rand.NewSource(1)),
}
if d := g.gap(time.Second, time.Second); d != time.Second {
t.Errorf("min == max: %s", d)
}
@@ -39,7 +43,10 @@ func TestGap(t *testing.T) {
func TestScaleValue(t *testing.T) {
scaleValue(nil, 2) // must not panic
v := &ocds.Value{Amount: ptr(12345.0), Currency: "GBP"}
v := &ocds.Value{
Amount: ptr(12345.0),
Currency: "GBP",
}
scaleValue(v, 1.5)
if *v.Amount != 18500 { // 18517.5 rounded to the nearest 100
t.Errorf("amount = %v, want 18500", *v.Amount)
@@ -48,7 +55,10 @@ func TestScaleValue(t *testing.T) {
t.Error("nil gross amount was set")
}
v = &ocds.Value{Amount: ptr(1000.0), AmountGross: ptr(1200.0)}
v = &ocds.Value{
Amount: ptr(1000.0),
AmountGross: ptr(1200.0),
}
scaleValue(v, 0.5)
if *v.Amount != 500 || *v.AmountGross != 600 {
t.Errorf("amounts = %v / %v, want 500 / 600", *v.Amount, *v.AmountGross)
@@ -56,15 +66,24 @@ func TestScaleValue(t *testing.T) {
}
func TestEnsurePartyID(t *testing.T) {
p := ocds.Organization{ID: "GB-EXISTING", Name: "Council"}
p := ocds.Organization{
ID: "GB-EXISTING",
Name: "Council",
}
ensurePartyID(&p)
if p.ID != "GB-EXISTING" {
t.Errorf("existing id replaced: %s", p.ID)
}
a := ocds.Organization{Name: "Somewhere Council"}
b := ocds.Organization{Name: "Somewhere Council"}
c := ocds.Organization{Name: "Elsewhere Council"}
a := ocds.Organization{
Name: "Somewhere Council",
}
b := ocds.Organization{
Name: "Somewhere Council",
}
c := ocds.Organization{
Name: "Elsewhere Council",
}
ensurePartyID(&a)
ensurePartyID(&b)
ensurePartyID(&c)
@@ -90,7 +109,13 @@ func TestAdvance(t *testing.T) {
at := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC)
// A planning notice without a tender becomes an active tender.
r := g.advance(ocds.Release{OCID: "ocds-x", Tag: []string{"planning"}}, at)
r := g.advance(
ocds.Release{
OCID: "ocds-x",
Tag: []string{"planning"},
},
at,
)
if r.Tag[0] != "tender" || r.Tender == nil || r.Tender.Status != "active" ||
r.Tender.TenderPeriod == nil || r.Tender.TenderPeriod.EndDate == nil {
t.Fatalf("planning -> %v, tender %+v", r.Tag, r.Tender)
@@ -105,10 +130,15 @@ func TestAdvance(t *testing.T) {
OCID: "ocds-y",
Tag: []string{"tender"},
Tender: &ocds.Tender{
ID: "ocds-y",
Value: &ocds.Value{Amount: ptr(10000.0), Currency: "GBP"},
Lots: []ocds.Lot{{ID: "1"}, {ID: ""}},
TenderPeriod: &ocds.Period{EndDate: &end},
ID: "ocds-y",
Value: &ocds.Value{
Amount: ptr(10000.0),
Currency: "GBP",
},
Lots: []ocds.Lot{{ID: "1"}, {ID: ""}},
TenderPeriod: &ocds.Period{
EndDate: &end,
},
},
}
seen := map[string]bool{}
@@ -147,7 +177,13 @@ func TestAdvance(t *testing.T) {
// An update without a deadline gets 30 + 14 days; a tender with no value
// is awarded with no value.
prev = ocds.Release{OCID: "ocds-z", Tag: []string{"tender"}, Tender: &ocds.Tender{ID: "ocds-z"}}
prev = ocds.Release{
OCID: "ocds-z",
Tag: []string{"tender"},
Tender: &ocds.Tender{
ID: "ocds-z",
},
}
for i := 0; i < 50; i++ {
r := g.advance(prev, at)
switch r.Tag[0] {