Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.

This page documents how source code static analysis and autoformatting tools can be used to enforce the Zubax C++ coding conventions.

Table of Contents


Unlike AStyle or Uncrustify, clang-format doesn't tend to break your code or introduce nonsensical changes, so it is the recommended option. The configuration file below requires clang-format version 8 or newer. Note that clang-format can't enforce brace placement and some other things; consider using clang-tidy for that.


Code Block
titleInvoking clang-format
clang-format -i -fallback-style=none -style=file src/*.[ch]pp

CI integration

Enforce a consistent coding style using CI by running clang-format against a fresh working copy, and then ask git if there were any changes introduced. If there are no changes, the codebase is conforming, otherwise it's not and the build should be failed.

Code Block
# Clone the repository and cd into its directory; don't forget git submodule update --init --recursive
all_source_files=$(find $SOURCE_DIRECTORY -name '*.[ch]pp')
clang-format -i -fallback-style=none -style=file $all_source_files || exit 1
modified="$(git status --porcelain --untracked-files=no)"
if [ -n "$modified" ]; then echo "Run to reformat the code."; exit 2; fi


This section is missing. Please, come back later.


Eclipse IDE autoformatter

Configuration file for the Eclipse autoformatter is attached below. Eclipse's embedded autoformatter is quite limited in its capabilities and tends to break complex C++ code, so one should not rely on it too much. New projects are recommended to use JetBrains CLion instead.

View file