llvm / llvm/llvm-project

Document fallbacks for clang-tidy readability-identifier-naming options

Open
#170,008 3 comments 0 reactions 0 assignees View on GitHub
clang-tidy documentation
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

[`readability-identifier-naming`](https://clang.llvm.org/extra/clang-tidy/checks/readability/identifier-naming.html) contains a total of 56 sets of options for each of the types of symbols. Documentation seems to suggest every single one needs to be set in order for that symbol to be checked at all. But reading the code we see many of those more specific options actually have fallbacks:

```cpp
if (isa(D)) {
if (NamingStyles[SK_TypeTemplateParameter])
return SK_TypeTemplateParameter;

if (NamingStyles[SK_TemplateParameter])
return SK_TemplateParameter;

return SK_Invalid;
}

if (isa(D)) {
if (NamingStyles[SK_ValueTemplateParameter])
return SK_ValueTemplateParameter;

if (NamingStyles[SK_TemplateParameter])
return SK_TemplateParameter;

return SK_Invalid;
}

if (isa(D)) {
if (NamingStyles[SK_TemplateTemplateParameter])
return SK_TemplateTemplateParameter;

if (NamingStyles[SK_TemplateParameter])
return SK_TemplateParameter;

return SK_Invalid;
}
```

This shows that all of `TypeTemplate*`, `ValueTemplate*` and `TemplateTemplate*` options actually can be skipped and combined into the common `Template*`. This makes intuitive sens, but without it being documented, it is hard to make sure, especially for cases with multiple fallbacks of unknown precedence. For example, a `public static constexpr` method will use the order `ConstexprMethod`, `ConstexprFunction`, `ClassMethod`, `PublicMethod`, `Method`, `Function`, even though the user can reasonably expect that the method being `public` is more important than it being `constexpr` or `static`.

Contributor guide

Open the contributing guide

Research direction

Start with the linked readability-identifier-naming documentation and the NamingStyles lookup shown in the issue. Trace the fallback order for the template-parameter and function or method options, then document which options may be omitted and how precedence works, including the constexpr example.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, documentation, tooling
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.