Add .clang-format file with Unit ruleset
This adds a .clang-format file that can be used with the clang-format tool to either reformat code locally, or automatically flag up code styling issues during a github action.
This PR's only aim right now is to have a conversation about the rulesets and come to a standard (ie ruleset in the clang-format file) that the entire team agrees on, so we can get to a point where we're not having conversations about code styling in future PRs.
This PR does not aim to wire it up to github actions yet.
Diffs of the codebase:
- custom style (this .clang-format): https://github.com/nginx/unit/pull/1471
- Chromium: https://github.com/nginx/unit/pull/1470
- Microsoft: https://github.com/nginx/unit/pull/1472
- LLVM: https://github.com/nginx/unit/pull/1473
- GNU: https://github.com/nginx/unit/pull/1474
@javorszky What's the current diff if you apply these rules to Unit?
How was this file generated and where do all the comments come from?
How was this file generated and where do all the comments come from?
Originally with clang-format --dump-config --style=llvm > .clang-format, and then I went over every single rule there, looked up what they do on the documentation site, compared existing codebase to the values where I needed to make a decision.
Every comment is written by hand by me.
Hmm
$ clang-format --dry-run src/nxt_php_sapi.c
/home/andrew/src/unit/.clang-format:51:3: error: unknown key 'AlignFunctionDeclarations'
AlignFunctionDeclarations: true
^~~~~~~~~~~~~~~~~~~~~~~~~
Error reading /home/andrew/src/unit/.clang-format: Invalid argument
need clang-format v20.0.0 sadly
That's way too new!, it's not even released yet, probably in March next year...
I'll put up a new version with the v20 rules removed, and a diff for this, and all the other prebuilt styles as well
This has been updated so clang-format 19 will take it. I've also updated the main comment to point to a bunch of different draft PRs for the reformats. (if you don't see it, I'm still pushing / opening them)