clang-tidy - readability-identifier-length — Extra Clang Tools 16.0.6 documentation

# Extra Clang Tools 16.0.6 documentation

## clang-tidy - readability-identifier-length

# readability-identifier-length

This check finds variables and function parameters whose length are too short. The desired name length is configurable.

Special cases are supported for loop counters and for exception variable names.

## Options

The following options are described below:

> - `MinimumVariableNameLength`, `IgnoredVariableNames`

> - `MinimumParameterNameLength`, `IgnoredParameterNames`

> - `MinimumLoopCounterNameLength`, `IgnoredLoopCounterNames`

> - `MinimumExceptionNameLength`, `IgnoredExceptionVariableNames`

MinimumVariableNameLength

  All variables (other than loop counter, exception names and function parameters) are expected to have at least a length of MinimumVariableNameLength (default is 3). Setting it to 0 or 1 disables the check entirely.

      int doubler(int x)   // warns that x is too short
      {
         return 2 * x;
      }

  This check does not have any fix suggestions in the general case since variable names have semantic value.

IgnoredVariableNames

  Specifies a regular expression for variable names that are to be ignored. The default value is empty, thus no names are ignored.

MinimumParameterNameLength

  All function parameter names are expected to have a length of at least MinimumParameterNameLength (default is 3). Setting it to 0 or 1 disables the check entirely.

      int i = 42;    // warns that 'i' is too short

  This check does not have any fix suggestions in the general case since variable names have semantic value.

IgnoredParameterNames

  Specifies a regular expression for parameters that are to be ignored. The default value is ^[n]$ for historical reasons.

MinimumLoopCounterNameLength

  Loop counter variables are expected to have a length of at least MinimumLoopCounterNameLength characters (default is 2). Setting it to 0 or 1 disables the check entirely.

      // 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. The default value is ^[ijk_]$; the first three symbols 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 (default is 2). Setting it to 0 or 1 disables the check entirely.

      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. The default value is ^[e]$ mainly for historical reasons.

      try {
          // ...
      }
      // This does not warn by default, for historical reasons.
      catch (const std::exception& e) {
          // ...
      }