Code style and formatting
We aim for a consistent and readable coding style. You do not need to worry about styling if you use the right tools we present in the following. Please also enable pre-commit in your repository to have these check run automatically for you on every commit!
C++
Use clang-format
. It can be added to be automatically run on save in your editor / IDE:
- Vim
- Visual Studio
- Visual Studio Code
(part of the C++ extension)
- Important: Set the setting
editor.formatOnSaveModetomodificationsIfAvailableto only format modified lines.
- Important: Set the setting
The current style is defined in .clang-format .
Runs also automatically (no installation necessary) on git commit using pre-commit
which needs to be enabled once with pre-commit install.
Python
Use black
. It can be added to be automatically run on save in your editor / IDE:
black is also run by our pre-commit-hooks. To run manually:
pre-commit run black --all-filesCMake
Use cmake-format . It can be added to be automatically run on save in your editor / IDE:
The current style is defined in .cmake-format.yaml
.
On installation make sure to install with the YAML option:
pip install cmakelang[YAML]Runs also automatically (no installation necessary) on git commit using pre-commit
which needs to be enabled once with pre-commit install.
Build targets
You can run clang-format and cmake-format on the full OGS code base by building the following targets:
| Language | Shows formatting | Applies formatting |
|---|---|---|
| C++ | clang-format |
fix-clang-format |
| CMake | cmake-format |
fix-cmake-format |
This article was written by Lars Bilke. If you are missing something or you find an error please reach out
to us on our forum.
Generated with Hugo 0.164.0
in CI job 825193
|
Last revision: April 20, 2026
Commit: refactor(MeshLib): remove PropertyVector::push_back 870422dde
| Edit this page on