Update .clang-format
Summary
Consistent code formatting is important! clang-format is the best tool for automatic C++ formatting. We already have a .clang-format
configuration file at the root of the project. But it was copy-pasted from ITK and is poorly suited to current OTB code. I think our .clang-format
configuration should be such that it produces the minimum diff to current source files and still looks good and familiar to new developers. In this MR I do two things:
- Simplify and update
.clang-format
. The most significant changes are:
BreakBeforeBraces: Allman
ColumnLimit: 160
I like Allman style because it's close to the current GNU/Whitesmiths style used in ITK, but is more self-consistent (all brace pairs follow the same indentation logic) and I believe it is much more familiar with new developers and other C++ projects (I have never seen GNU style elsewhere than OTB or ITK...). The 160 column limit seems like a good compromise after a few trial and errors on the whole code base.
The other elements should be trivial (but feel free to bikeshed of course!).
- Run it on three files as an example:
M Examples/Registration/ImageRegistration1.cxx
M Modules/Applications/AppEdge/app/otbEdgeExtraction.cxx
M Modules/Core/ImageBase/include/otbVectorImage.hxx
If you don't have clang-format installed, you can use this to see if you agree with the proposed configuration.
Should we run clang-format everywhere?
That's up for debate but personally I would not. I would run it on new files and some files where the indentation is very wrong (otbEdgeExtraction.cxx is one example). We can do it gradually.
Copyright
The copyright owner is CNES and has signed the ORFEO ToolBox Contributor License Agreement.
Check before merging:
- All discussions are resolved
- At least 2
👍 votes from core developers, no👎 vote. - The feature branch is (reasonably) up-to-date with the base branch
- Dashboard is green
- Copyright owner has signed the ORFEO ToolBox Contributor License Agreement