readability-identifier-length¶
This check finds variables and function parameters whose length are too short. The desired name length is configurable. Special short names which should be ignored can be specified. Local variables with short names can also be ignored if they are short-lived.
Options¶
The following options are described below:
- MinimumVariableNameLength¶
All variables (other than loop counter, exception names and function parameters) are expected to have at least a length of
MinimumVariableNameLength. Setting it to0or1disables the check entirely. Default is3.int i = 42; // warns that 'i' is too short
- IgnoredVariableNames¶
Specifies a regular expression for variable names that are to be ignored. Default is empty string, so no names are ignored.
- MinimumBindingNameLength¶
All variables introduced by structured bindings are expected to have at least a length of
MinimumBindingNameLength. Setting it to0or1disables the check entirely. Default is2.auto [a] = get_result(); // warns that 'a' is too short
- IgnoredBindingNames¶
Specifies a regular expression for variable names introduced by structured bindings that are to be ignored. The
^[_]$value allows the_idiom to specify that the value is discarded on purpose. Default is^[_]$.
- MinimumParameterNameLength¶
All function parameter names are expected to have a length of at least
MinimumParameterNameLength. Setting it to0or1disables the check entirely. Default is3.int doubler(int x) // warns that x is too short { return 2 * x; }
- IgnoredParameterNames¶
Specifies a regular expression for parameters that are to be ignored. Default is
^[n]$for historical reasons.
- MinimumLoopCounterNameLength¶
Loop counter variables are expected to have a length of at least
MinimumLoopCounterNameLengthcharacters. Setting it to0or1disables the check entirely. Default is2.// This warns that 'q' is too short. for (int q = 0; q < size; ++ q) { // ... }
- IgnoredLoopCounterNames¶
Specifies a regular expression for counter names that are to be ignored. Default is
^[ijk_]$; the first three symbols are included for historical reasons and the last one since it is frequently used as a “don’t care” value, specifically in tools such as Google Benchmark.// This does not warn by default, for historical reasons. for (int i = 0; i < size; ++ i) { // ... }
- MinimumExceptionNameLength¶
Exception clause variables are expected to have a length of at least
MinimumExceptionNameLength. Setting it to0or1disables the check entirely. Default is2.try { // ... } // This warns that 'e' is too short. catch (const std::exception& x) { // ... }
- IgnoredExceptionVariableNames¶
Specifies a regular expression for exception variable names that are to be ignored. Default is
^[e]$mainly for historical reasons.try { // ... } // This does not warn by default, for historical reasons. catch (const std::exception& e) { // ... }
- LineCountThreshold¶
Defines the minimum number of lines required between declaration and last use for a diagnostic to be issued. This option only affects the behavior regarding local variables: a warning is always issued when a global variable has a short name, because globals can potentially be used across multiple files. Default is
0, which corresponds to all variables being flagged.// In this example, a warning will be issued if LineCountThreshold < N int a = 0; // First line (declaration line) a = 1; // Second line // ... last_use_of(a); // N-th line