At the hackathon this week, there was discussion of using
clang-format on VTK to enforce coding style guidelines. This allows formatting of a merge request using
Do: reformat so that local formatting isn’t necessary (and that various versions of
clang-format don’t keep disagreeing on minor details in the formatting). ParaView, CMake, VTK-m, and the SMTK projects have been doing this for quite a while with great success.
However, to do this effectively, a sweep of the entire codebase to normalize the formatting is required (otherwise any edit to a file is going to force a reformat of the entire file leading to very confounding MR reviews). It is best to do this before the 9.0 release so that backports can actually be applied between the
master branches with the same code.
For those wanting a way to easily rebase your branches across the reformat, a procedure will be provided (I know how it should work, but need to write down the steps and test them out for robustness). Any incremental (e.g., directory-at-a-time) reformatting would require this process for each formatting “sweep” your merge requests touch. Due to this reason, a single reformatting sweep is preferred.
By using whatstyle (thanks @seanm!) on ParaView (which has consistent style), it has determined that ParaView’s
clang-format-8 configuration file based on the contents of
ParaViewCore/ClientServerCore/Core with some hand-tuning for parameters that
whatstyle can’t figure out on its own (namely
BasedOnStyle: Mozilla AlignAfterOpenBracket: DontAlign AlignOperands: false BinPackArguments: true BinPackParameters: true BreakBeforeBraces: Allman ColumnLimit: 100 Standard: Cpp03
Which is very similar to what is used today.
An initial MR to sort include directives is here. This is done separately because it is highly likely to change behavior compared to the rest of the formatting configuration parameters. I’ll work through its failures until the dashboards are happy, though I suspect the nightly builders may have some followup thoughts on the sorting as well.