taskwarrior
taskwarrior copied to clipboard
Start using clang-format to format C++ code
The C++ style and formatting in Taskwarrior is unusual, and difficult to keep up with by hand or in reviews. Let's let computers do the work for us! Ideally clangd-format can be configured to enforce roughly the style used in Taskwarrior, then run once over the codebase and enforced in CI thereafter.
This should make it easy for contributors to bang together some C++, run clangd-format
on it, and then make a PR, so we don't need to make review comments about the formatting and also maintain a consistent formatting for the project.
Nitpick: isn't it clang-format?
Perhaps a separate issue but what would we think about checking in a compile_commands.json file so clangd works out of the box?
Oh, good point regarding the spelling!
CMake can actually create compile_commands.json
with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
- it's working for me! Maybe documenting that somewhere would be good?
I looked into it already a little bit.
As far as my search suggested we can setup clang-format
quite simple with providing the necessary file in the repository.
However, in order to have it useful one would need to automate the process of running clang-format, as not every developer is using an IDE, or we do not even know which IDE's are used.
Searching a bit deeper into this direction Stack Overflow Question, I stumpled over the pre-commit framework, which also provides a pre-commit.ci service which would allow us to use e.g. clang-format
for the C, C++ code, black for Python files as well as maybe some other linter for the Rust code.
Is this a way we would like to go here?
Yes, I think we will want to enforce this on PRs.
Two important considerations: can the tool be configured to the particular style of Taskwarrior, and do we need to make a huge PR to bring the whole codebase into compliance?
Yes and yes.
As far as I know one can configure clang-format
to be as one likes, however I assume as described in #1987 already pointed out we are quite close to Google Coding Style.
I assume that one big PR with one "format" Commit makes sense. To not lose the git blame
options in GitHub I think we can setup this which can also be used for locally using the functionality.
Oh, that ignore functionality is pretty cool! I suppose the next step is just to do it, then?
Yes, I will do over the next few days.