Skip to content

Clang-format to fix code layout#

We use clang-format with a Fast Downward configuration file (.clang-format in the repository root) to enforce some of our formatting conventions. If a source file is properly formatted, applying clang-format should be an idempotent operation (i.e., result in an identical file). This is important so that we can verify our style rules automatically, at least for those rules which clang-format can handle.

Not all aspects of source layout are handled by clang-format, so please still pay attention to our whitespace rules and other coding conventions.

Installing clang-format#

sudo apt install clang-format-18

Running clang-format#

To check the formatting of all C++ files, use ./misc/style/run-clang-format.py. To actually edit the files that need to be clang-formatted, use ./misc/style/run-clang-format.py \--modify. Optionally, you can use the flag -f to fix the style on uncommitted changes. This script is also part of our tox tests:

pip3 install tox
sudo apt-get install clang-tidy-16
sudo apt-get install clang-format-18
cd misc/
tox -e style,clang-tidy

To check the style of Python and C++ files, you can use tox -e style. To automatically fix the style, you can use tox -e fix-style.