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

+58 -16
View File
@@ -24,33 +24,75 @@ var byteUnits = []struct {
name string
size int64
}{
{"EiB", humanize.EiByte}, {"EB", humanize.EByte},
{"PiB", humanize.PiByte}, {"PB", humanize.PByte},
{"TiB", humanize.TiByte}, {"TB", humanize.TByte},
{"GiB", humanize.GiByte}, {"GB", humanize.GByte},
{"MiB", humanize.MiByte}, {"MB", humanize.MByte},
{"KiB", humanize.KiByte}, {"KB", humanize.KByte},
{
name: "EiB",
size: humanize.EiByte,
},
{
name: "EB",
size: humanize.EByte,
},
{
name: "PiB",
size: humanize.PiByte,
},
{
name: "PB",
size: humanize.PByte,
},
{
name: "TiB",
size: humanize.TiByte,
},
{
name: "TB",
size: humanize.TByte,
},
{
name: "GiB",
size: humanize.GiByte,
},
{
name: "GB",
size: humanize.GByte,
},
{
name: "MiB",
size: humanize.MiByte,
},
{
name: "MB",
size: humanize.MByte,
},
{
name: "KiB",
size: humanize.KiByte,
},
{
name: "KB",
size: humanize.KByte,
},
}
// ParseByteSize parses a size such as "32KiB", "1 MB" or "4096". Unit names
// are case-insensitive. "-1" (or "-1B") is ByteSizeNoLimit; any other
// negative size is an error.
func ParseByteSize(s string) (ByteSize, error) {
trimmed := strings.TrimSpace(s)
func ParseByteSize(text string) (ByteSize, error) {
trimmed := strings.TrimSpace(text)
if trimmed == "-1" || strings.EqualFold(trimmed, "-1B") {
return ByteSizeNoLimit, nil
}
if strings.HasPrefix(trimmed, "-") {
return 0, fmt.Errorf("byte size %q is negative; only -1 (no limit) is allowed", s)
return 0, fmt.Errorf("byte size %q is negative; only -1 (no limit) is allowed", text)
}
n, err := humanize.ParseBytes(s)
parsed, err := humanize.ParseBytes(text)
if err != nil {
return 0, err
}
if n > math.MaxInt64 {
return 0, fmt.Errorf("byte size %q is too large", s)
if parsed > math.MaxInt64 {
return 0, fmt.Errorf("byte size %q is too large", text)
}
return ByteSize(n), nil
return ByteSize(parsed), nil
}
// String formats b exactly, in the largest unit that divides it (e.g. "32KiB",
@@ -61,9 +103,9 @@ func (b ByteSize) String() string {
return "-1"
}
if b != 0 {
for _, u := range byteUnits {
if int64(b)%u.size == 0 {
return strconv.FormatInt(int64(b)/u.size, 10) + u.name
for _, unit := range byteUnits {
if int64(b)%unit.size == 0 {
return strconv.FormatInt(int64(b)/unit.size, 10) + unit.name
}
}
}