Code style checking - openucx/ucx GitHub Wiki

Intro

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 whatever changed by the commit/PR). Any difference from actual code is 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 on the branch 'ucx-clang-format'. The fork is based on clang 11.


CI

The clang fork is being run in Azure pipelines and reporting issues without failing the pipeline, but marking it with "Succeeded with issues" status. Some of the formatting changes by clang are not 100% aligned with UCX code style, so in any case of discrepancy - UCX code style guidelines are taking precedence.


Running locally

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

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.

It is recommended to add the following git config option in order to add *.inl files to git-clang-format check:

git config clangFormat.extensions c,cc,inl,h

Example usage:

# load binary module for forked clang
module load dev/llvm-ucx
# check style errors on 2 last commits
git-clang-format --diff HEAD^^ HEAD