[GRASS-dev] Replace GNU Indent with ClangFormat?

Vaclav Petras wenzeslaus at gmail.com
Mon Mar 21 14:34:27 PDT 2022


On Mon, 21 Mar 2022 at 10:01, Nicklas Larsson via grass-dev <
grass-dev at lists.osgeo.org> wrote:

> ...There were attempts to do this [2, 3], but numerous problem
> arose...which are based on GNU Indent [4]. These problem are probably
> originate in the comparatively limited functionality and lack of active
> development on GNU Indent.
>

Additionally, the C++ support in GNU Indent is limited:

While an attempt was made to get indent working for C++, it will not do a
good job on any C++ source except the very simplest.
https://www.gnu.org/software/indent/manual/indent/Bugs.html

I think the note in the docs was there even before C++11.


> I have created a `.clang-format` file with the settings as close as
> possible to the ones in `grass_indent.sh` (somewhat outdated described in
> [7]).
>

I don't think the style is set in stone. This is perhaps for a next phase,
but unless a strong standard emerges for C/C++, we may consider switching
to something which is close to Black given our mixed code base. Function
signatures and calls would be the big change there. However, the closing
parenthesis on a separate line typical to Black is available only in the
upcoming ClangFormat 14.

On the other hand, yielding to some 3rd party standard seems like a good
idea especially for all the C++ syntax.


> Now the question is first of all: is using ClangFormat something the GRASS
> dev community (you) would want or could live with for this project?
>

+1. Being tool-independent is not possible here and ClangFormat seems to do
the job.


> And if so, what version of ClangFormat should then be the starting point
> (what do you have reasonably easy available for your dev platform)? The
> present settings in the PR are derived from ClangFormat 13, but could
> possibly be back ported if really needed.
>

You can run a specific version locally using Docker thanks to a related
GitHub Action:

https://github.com/DoozyX/clang-format-lint-action#run-locally

Harder to integrate in your editor, but at least something. (Yes, your
favorite editor may already have support for ClangFormat.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/grass-dev/attachments/20220321/7372f70f/attachment.html>


More information about the grass-dev mailing list