commaai / panda

code powering the comma.ai panda
MIT License
1.52k stars 757 forks source link

Setup clang-format #1919

Closed adeebshihadeh closed 3 months ago

adeebshihadeh commented 5 months ago

The default configuration seems pretty aggressive, but we only want this for very basic checks.

Bounty is to finish up #1918 by getting it to only check our two space indentation style. We need to disable all checks by default and only whitelist the ones we care about.

JhennerTigreros commented 3 months ago

Hello @adeebshihadeh. I'm looking for this bounty. Try to configure a general .clang-format file. I started with safety_toyota.h (my goal is to format this single file and start generalization for the whole project), but encounter this case.

toyota_lta ? SET_RX_CHECKS(toyota_lta_rx_checks, ret) : \
               SET_RX_CHECKS(toyota_lka_rx_checks, ret);

As far as I know there isn't a flag on the clang format tool, that can avoid the use of \ in ternary operator and pass straightforward. The only solution that I can think is using // clang-format off-on, but maybe you want to avoid this kind of stuff. (My current .clang-format file downsize the errors from 7.063 -> 6.853 far to the solution)

I'm thinking about made the clang format on 4 step process, using a intermediate representations of the clang format:

I don't know if that is the right solution and maybe overengineering, also try to explore using the output as XML, but clang-format doesn't expose the reason of the change on the output so is useless. I will start looking on clang-format project to check if is easy to implement that changes on the XML format and use them as input to apply changes where required for the whitelist checks.