llvm / llvm/llvm-project

[Enhancement] clang-tidy rulesets per directory

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

Description

Hello,
In our company we organize our code as follows:
```
├── libA
│   ├── include
│   ├── src
│   └── test
└── libB
├── include
├── src
└── test
```

For our productive code we have aligned on specific clang-tidy checks.
Unfortunately, our tests are not compliant with these checks. For example we enable `cppcoreguidelines-avoid-magic-numbers` for productive code, but we cannot enable the same rules for our tests.

As a result in each test folder we now have a `.clang-tidy` file as follows:
```
├── .clang-tidy
├── libA
│   ├── include
│   ├── src
│   └── test
│   └── .clang-tidy
└── libB
├── include
├── src
└── test
└── .clang-tidy
```

The `test/.clang-tidy` looks as follows:
```
---
InheritParentConfig: true
Checks: >
-cppcoreguidelines-avoid-magic-numbers,
```

What could be some other mechanism so that we do not need to duplicate/symlink this file at that many places?

Maybe supporting "rulesets" could be an option, which can be applied per directory?
e.g. (simplified, in JSON format)
```
{
"Checks": ["*"],
"Rulesets": {
"our-tests" : {
"InheritParentConfig": "true",
"Checks": ["-cppcoreguidelines-avoid-magic-numbers"],
"Patterns": [".*/test/.*"]
},
"external-code" : {
"Checks": ["google*"],
"Patterns": [".*/external/.*"]
}
}
}
```

Maybe there is already some other solution existing, or you can think of any better?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.