[GRASS-dev] Proposal for using ClangFormat, replacing GNU indent, for C/C++ code formatting

Vaclav Petras wenzeslaus at gmail.com
Tue Dec 6 17:51:22 PST 2022


On Mon, 5 Dec 2022 at 08:07, Nicklas Larsson via grass-dev <
grass-dev at lists.osgeo.org> wrote:

>
> 1. We adapt the formatting policy using ClangFormat.
>

+1

I would prefer if formatting changes from GNU indent which can be done
separately are done separately. For Python & Black, I did that together but
1) in multiple PRs and 2) we lacked any formatting, so it was a little
different. Things like ReflowComments seem like a good second round.
(Sorry, I'm a little confused about your intention with unused
.clang-format and what will be in there.)


> 2. We implement "BreakBeforeBraces" rules according the "Stroustrup" style.
>

Given the lack of unified standard in C and C++, I'm for making choices
which bring the formatting closer to Python and Black which Stroustrup
seems to do.

Related to that, the in-line comments in the PR are modified to have one
space after the code while Black, i.e., our Python code, has two.


> 3. If there are no objections raised within a two weeks period, say until
> December 18, either to points 1 and/or 2 or even to this proposed deadline,
> the PR [1] will be merged and work can start on source code formatting.
>

My approach with Black was to do config+formatting+CI at once which has the
disadvantage of adding the commit with config+CI into
.git-blame-ignore-revs, but a comment in that file warns about that and it
is exactly what will happen when we change the formatting later on with
active CI (the formatting will have to go in together with config and CI
changes).


> 4. Any changes decided upon ought to be added to
> https://trac.osgeo.org/grass/wiki/Submitting/C
>

Yes. FYI, although details are unclear, the long-term plan for these
documents is to move them to code (based on a discussion at a PSC meeting).

Best,
Vaclav


>
>
> Cheers,
> Nicklas
>
>
>
>
>
> [1] https://github.com/OSGeo/grass/pull/2272
> [2] https://www.gnu.org/software/indent/
> [3] https://clang.llvm.org/docs/ClangFormat.html
> [4] https://github.com/OSGeo/grass/blob/main/utils/grass_indent.sh
> [5] https://clang.llvm.org/docs/ClangFormatStyleOptions.html
> [6] https://github.com/OSGeo/grass/pull/2272/files
>
> _______________________________________________
> grass-dev mailing list
> grass-dev at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/grass-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20221206/c1fe6cd9/attachment.htm>


More information about the grass-dev mailing list