[Development] clang-format config file.

Olivier Goffart olivier at woboq.com
Thu Jun 30 12:52:19 CEST 2016


I have made a clang-format config file. I believe it should go into the 
qtrepotools repository, so I made this pull request:

You can download this file from there and put it in the parent directory of 
your qt repositories.  (clang-format search all the parent folders for a 
.clang-format file)

We don't want to reformat existing files, but this help to format only the 
lines that are touched in a given commit.  The git-clang-format tool can be 
used for that.

The git-clang-format tool is part of the clang. So it is probably packaged in 
your distribution as part of clang.

To use it, simply commit as before, but before pushing, run:

  git-clang-format HEAD^
  git diff  
  # look at the changes made by clang-format, possibly retify some of it
  git commit -a --amend

Then you can push.

If you want to run git-clang-format on several commit separately, the --exec 
feature of git rebase comes handy:

  git rebase -i --exec "git-clang-format HEAD^"

The rebase will stop if clang-format does changes so you can apply the changes 
to that last commit and continue with git rebase --continue


The conf file is based on the WebKit style which is the closest builtin style 
to Qt. Then it was adjusted to fit better to the existing Qt style.

It follows the style closely, but there are some cases that might not be 
following existing practices. The question is if we want to try to fix clang-
format to be able to cope with them, or simply adapt the coding style to fit 
clang-format config.

Some of the things that are not possible with clang-format if to have all the 
function in one line like we sometimes have in our headers:

  inline const QString operator+(const QString &s1, const QString &s2)
  { QString t(s1); t += s2; return t; }

The style disabled any re-wraping of the comments, because the qdoc rules are 
not encoded in clang-format. So comments will not be touched.

But in general, I have been trying it on a few commits and it works quite 
well. You should try it as well and report the problems so they can be 


Woboq - Qt services and support - https://woboq.com - https://code.woboq.org

More information about the Development mailing list