Naming Placeholder Identifier
ID |
csharp.naming_placeholder_identifier |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
medium |
Remediation Effort |
low |
Resource |
Naming Convention |
Language |
CSharp |
Tags |
naming |
Description
Reports local variables, parameters and fields whose name is a placeholder such as
foo, bar, baz, tmp, temp, myVar or obj. The match is
case-insensitive but exact, so dataSource is not flagged. The placeholder list is
configurable via the placeholderNames property.
A binding whose name equals the unqualified name of its declared type (for example
Data data) is not flagged — naming a value after its type is descriptive, not a
placeholder.
Rationale
Placeholder names survive from quick prototyping and never communicate intent. A reader
seeing tmp or foo cannot tell what the value represents and has to reconstruct it from
the surrounding code. Replacing the placeholder with a name that states the value’s role
makes the code self-documenting.
var bar = LoadConfig(); // FLAW — placeholder name
var tmp = 2; // FLAW — placeholder name
var total = 3; // OK — descriptive
var dataSource = "db"; // OK — not an exact match
void Use(Data data) { } // OK — name matches its type
Remediation
Rename the identifier to a descriptive name that communicates what the value represents,
for example configuration, subtotal or currentUser.