Single-Character Identifier
ID |
swift.naming_single_char_var |
Severity |
info |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Swift |
Tags |
naming |
Description
Reports local variables and function parameters whose name is a single character that is not on a conventional allow-list. Single-character names hide the value’s purpose at every use site.
Rationale
A name’s primary job is to communicate intent. Aside from a handful of
conventional cases (loop counters i, j, k; mathematical coordinates
x, y, z), single-character identifiers force the reader to scroll back
to the declaration to recover meaning.
// Bad
func work(a: Int) {
let q = a * 2
}
// Good
func work(amount: Int) {
let doubled = amount * 2
}
Exceptions
-
the wildcard
_; -
names on the configured allow-list;
-
type properties (a struct designer may legitimately pick
x,y, etc.).
Parameters
allowedNames-
List of single-character names that are not flagged. Defaults to
[i, j, k, l, m, n, x, y, z].