curl / Mailing Lists / curl-library / Single Mail

curl-library

clang-format, close but no cigarr

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Fri, 17 Feb 2017 09:15:16 +0100 (CET)

Hey

tldr: clang-format can almost reformat our code for us.

Longer:

I'm quite fond of the idea of a tool that can reformat source code to follow
our style. That way people could just run that and avoid picky reviewer
comments, and we could use that to detect code style deviations etc.

There's the old GNU indent tool for that, but it was never flexible enough for
me. The new kid on the block for this purpose is clang-format. This tool is
used for code reformatting in several projects these days.

I grabbed it by the horns and made an attempt to create a clang-format config
file that would format our source code the way we like it. (Which in most
cases right now would leave the code unmodified.)

It almost works.

I mean, a complete success would be to be able to run it on all our code, then
run checksrc without complaints *and* the code should be what us humans like
and prefer. For me personally, I could even agree to adjusting our code style
slightly to accomodate for a tool like this.

The real show-stoppers right now I think is that A) it sometimes moves
comments to column 0 instead of keeping them aligned with the code which is
quite disruptive (possibly confused by #ifdefs?) and B) it actually indents
code *wrongly* in url.c, which is easily spotted by humans and checksrc. I
haven't found any config items to change those behaviors!

If you want to experiment further and help me tweak the clang-format configs
to perfection, here's what I have done this far:

   https://github.com/curl/curl/wiki/clang-format-style

And here's the documentation for the config items:

   http://clang.llvm.org/docs/ClangFormatStyleOptions.html

I'm considering taking these issues to the clang-format team to see what I can
do to get this working - if they remain.

--
  / daniel.haxx.se
-------------------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2017-02-17