xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-length.rst (revision 0aacef3abc41cfc8efb5f1b9483bc37599352a59)
1.. title:: clang-tidy - readability-identifier-length
2
3readability-identifier-length
4=============================
5
6This check finds variables and function parameters whose length are too short.
7The desired name length is configurable.
8
9Special cases are supported for loop counters and for exception variable names.
10
11Options
12-------
13
14The following options are described below:
15
16 - :option:`MinimumVariableNameLength`, :option:`IgnoredVariableNames`
17 - :option:`MinimumParameterNameLength`, :option:`IgnoredParameterNames`
18 - :option:`MinimumLoopCounterNameLength`, :option:`IgnoredLoopCounterNames`
19 - :option:`MinimumExceptionNameLength`, :option:`IgnoredExceptionVariableNames`
20
21.. option:: MinimumVariableNameLength
22
23    All variables (other than loop counter, exception names and function
24    parameters) are expected to have at least a length of
25    `MinimumVariableNameLength` (default is `3`). Setting it to `0` or `1`
26    disables the check entirely.
27
28
29    .. code-block:: c++
30
31      int i = 42;    // warns that 'i' is too short
32
33    This check does not have any fix suggestions in the general case since
34    variable names have semantic value.
35
36.. option:: IgnoredVariableNames
37
38    Specifies a regular expression for variable names that are
39    to be ignored. The default value is empty, thus no names are ignored.
40
41.. option:: MinimumParameterNameLength
42
43    All function parameter names are expected to have a length of at least
44    `MinimumParameterNameLength` (default is `3`). Setting it to `0` or `1`
45    disables the check entirely.
46
47
48    .. code-block:: c++
49
50         int doubler(int x)   // warns that x is too short
51         {
52            return 2 * x;
53         }
54
55    This check does not have any fix suggestions in the general case since
56    variable names have semantic value.
57
58.. option:: IgnoredParameterNames
59
60    Specifies a regular expression for parameters that are to be ignored.
61    The default value is `^[n]$` for historical reasons.
62
63.. option:: MinimumLoopCounterNameLength
64
65    Loop counter variables are expected to have a length of at least
66    `MinimumLoopCounterNameLength` characters (default is `2`). Setting it to
67    `0` or `1` disables the check entirely.
68
69
70    .. code-block:: c++
71
72      // This warns that 'q' is too short.
73      for (int q = 0; q < size; ++ q) {
74         // ...
75      }
76
77.. option:: IgnoredLoopCounterNames
78
79    Specifies a regular expression for counter names that are to be ignored.
80    The default value is `^[ijk_]$`; the first three symbols for historical
81    reasons and the last one since it is frequently used as a "don't care"
82    value, specifically in tools such as Google Benchmark.
83
84
85    .. code-block:: c++
86
87      // This does not warn by default, for historical reasons.
88      for (int i = 0; i < size; ++ i) {
89          // ...
90      }
91
92.. option:: MinimumExceptionNameLength
93
94    Exception clause variables are expected to have a length of at least
95    `MinimumExceptionNameLength` (default is `2`). Setting it to `0` or `1`
96    disables the check entirely.
97
98
99    .. code-block:: c++
100
101      try {
102          // ...
103      }
104      // This warns that 'e' is too short.
105      catch (const std::exception& x) {
106          // ...
107      }
108
109.. option:: IgnoredExceptionVariableNames
110
111    Specifies a regular expression for exception variable names that are to
112    be ignored. The default value is `^[e]$` mainly for historical reasons.
113
114    .. code-block:: c++
115
116      try {
117          // ...
118      }
119      // This does not warn by default, for historical reasons.
120      catch (const std::exception& e) {
121          // ...
122      }
123