Skip to content

Code style checking

Yossi Itigin edited this page Jul 4, 2021 · 19 revisions

We use clang-format for automatic check of commit compliance with our code style.

The tool tokenizes the source code and re-formats it according to the defined style Unlike checkstyle.pl, it doesn't just find issues - it formats the whole code - or the code changes in the commit - and it differs from the actual code, it's considered an issue.

Since upstream clang does not support all UCX style guidelines, we forked clang in https://github.com/openucx/llvm-project and added specific tweaks to it. The fork is based on clang 11.

git-clang-format must be run in the root directory of the repository - the style rules are defined in .clang-format file which is located there.

Invoking git-clang-format will check and fix files that were changed between HEAD and the working directory (only the modified lines are affected by formatting - git-clang-format doesn't check pre-existing code).

It is also possible to run the check on a particular commits diff, see git-clang-format -h for options.

Currently, the code style check is experimental and is recommended to be performed locally by each contributor when opening a PR. Some of the formatting changes by clang are not 100% aligned with UCX code style, so in any case UCX code style guidelines are taking precedence.

Example usage:

module load dev/gcc-latest
module load dev/clang-latest
git-clang-format --diff HEAD^^ HEAD
Clone this wiki locally