unit icon indicating copy to clipboard operation
unit copied to clipboard

Add .clang-format file with Unit ruleset

Open javorszky opened this issue 1 year ago • 8 comments

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 avatar Oct 23 '24 19:10 javorszky

@javorszky What's the current diff if you apply these rules to Unit?

callahad avatar Oct 23 '24 20:10 callahad

How was this file generated and where do all the comments come from?

ac000 avatar Oct 23 '24 20:10 ac000

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.

javorszky avatar Oct 23 '24 20:10 javorszky

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

ac000 avatar Oct 23 '24 21:10 ac000

need clang-format v20.0.0 sadly

javorszky avatar Oct 23 '24 21:10 javorszky

That's way too new!, it's not even released yet, probably in March next year...

ac000 avatar Oct 23 '24 21:10 ac000

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

javorszky avatar Oct 23 '24 21:10 javorszky

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)

javorszky avatar Oct 24 '24 08:10 javorszky