keepassxreboot / keepassxc

KeePassXC is a cross-platform community-driven port of the Windows application “Keepass Password Safe”.
https://keepassxc.org/
Other
21.39k stars 1.48k forks source link

Add clang-tidy support #7719

Open mame98 opened 2 years ago

mame98 commented 2 years ago

Summary

This project does not have a clang-tidy configuration. I ran clang tidy locally with all checks enabled and it reported a number of suggestions. To use clang-tidy with CMake, you can do

cmake <otherArgs> -DCMAKE_CXX_CLANG_TIDY=clang-tidy

Examples

A .clang-tidy configuration file could be placed on the toplevel directory of this project

Context

clang-tidy is a static analysis tool for C/C++ that provides a lot of suggestions. Some of them are quite helpful for avoiding bugs (for example bugprone-*) or for avoiding performance issues (performance-*). Others help with writing readable code.

I could try to create a basic configuration file that enables only the most important checks. I would create a PR with the config file and the required fixes for those checks. More advanced checks could be added later if desired. Furthermore the checks could be tested in the CI.

Is this something that is welcomed?

droidmonkey commented 2 years ago

What would you put in the config file? My IDE handles this for me.

mame98 commented 2 years ago

Rules that should be checked could be placed in the config file. This allows checking those rules with clang-tidy without any IDE (for example in a CI). This could also help new contributors (like myself) to check if my new code matches the requirements of this project.

My IDE recognises the .clang-tidy file and will only show the enabled checks.

For example, a basic config file could look like

---
Checks:              '-*,
                      bugprone-*'
WarningsAsErrors:    '*'
FormatStyle:         file
...
droidmonkey commented 2 years ago

I'm open to your proposed settings.