Duration Variable Naming
ID |
go.duration_variable_names |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Go |
Tags |
naming |
Description
Reports a variable, parameter or struct field of time.Duration type whose name carries a
time-unit suffix such as Ms, Seconds or Min.
Rationale
A time.Duration already encodes its own unit — it is a count of nanoseconds. A unit-bearing
name is redundant and, worse, misleading: timeoutMs reads like a millisecond integer, but a
Duration valued timeoutMs = 5 is five nanoseconds. Naming the duration without a unit
makes the type the single source of truth.
// Bad — unit suffix contradicts the Duration type
var timeoutMs time.Duration // FLAW
var pollSeconds time.Duration // FLAW
// Good — let the type carry the unit
var timeout time.Duration // OK
var pollInterval time.Duration // OK
Parameters
unitSuffixes-
Capitalised time-unit segments flagged as a suffix. Defaults to
[Ms, Ns, Sec, Seconds, Min, Minutes, Hours].
Remediation
Drop the unit from the name and rely on the time.Duration type, or — if you genuinely need a
raw integer in a specific unit — use an integer type and keep the unit in the name.