Placeholder Identifier
ID |
swift.naming_placeholder_identifier |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
Swift |
Tags |
naming |
Description
Reports identifiers — local variables, function parameters and function
names — whose name matches a configurable placeholder list (foo, bar,
baz, tmp, temp, obj, …). Placeholder names survive from
quick prototyping and communicate nothing about the value’s role.
Rationale
A good identifier name documents intent at every use site. Placeholders force the reader to scroll back to the declaration or — worse — to infer the meaning from context, with the risk of mis-reading.
// Bad
let foo = 1
var tmp: String = ""
func doStuff() {}
// Good
let amount = 1
var greeting: String = ""
func renderInvoice() {}
Exceptions
-
type properties — domain models may legitimately use words like
data; -
type names — there are too many real types called
Data(e.g.Foundation.Data). -
operator overloads.
The match is case-insensitive but exact, so dataSource and
temperature are not flagged.
Parameters
placeholderNames-
List of names treated as placeholders. Defaults to
[foo, bar, baz, qux, tmp, temp, xyz, myVar, obj, stuff, thing].