| Issue |
175430
|
| Summary |
clang-tidy/readability-identifier-length: allow different minimum variable name length for local vs global/static variables
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
dashofast
|
The readability-identifier-length check currently applies a single minimum length to all variables, regardless of scope.
In practice, this causes excessive noise for short local variables (e.g. loop temporaries, small-scope helpers), while still failing to adequately enforce descriptive names for global and static variables, which form part of the program’s long-lived API and state.
Many coding guidelines explicitly allow short local variable names while requiring descriptive names for non-local variables.
### Current behavior
With the current configuration:
```
CheckOptions:
- key: readability-identifier-length.MinimumVariableNameLength
value: '3'
```
All of the following trigger warnings:
```
static int i;
int g;
void f(void) {
static int k=3 ;
int i;
}
```
### Requested enhancement
Add scope-aware minimum length options, for example:
```
CheckOptions:
- key: readability-identifier-length.MinimumLocalVariableNameLength
value: '1'
- key: readability-identifier-length.MinimumGlobalVariableNameLength
value: '3'
- key: readability-identifier-length.MinimumStaticVariableNameLength
value: '3'
```
With the above setting in `.clang-tidy`, expecting to get errors on the static 'i', global 'g' and function 'f', and the static 'k'. Expecting no warning on the local 'i' in 'f'.
```
static int i ; // fail
static int iii; // Pass
int g; // fail
int ggg ; // pass
static foo(void) { // pass
static int done = 1 ; // pass
}
void f(void) { // fail
static int k=3 ; // fail
int i; // pass
}
```
### Motivation / rationale
* Reduces false positives and warning fatigue for local variables
* Improves enforcement where it matters most (globals, file statics)
* Aligns with common coding standards (MISRA, internal style guides, large C/C++ codebases)
* Similar scope distinctions already exist in readability-identifier-naming
### Small letters
In theory, separate limit should be provided for static variable inside functions - but that seems to be excessive fine tuning at this time. Single policy for all static seems reasonable for first steps. So the following should be accepted:
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs