Skip to content

Commit 6bbac7d

Browse files
franzpoeschelax3l
authored andcommitted
Add pre-commit hook for clang-format
1 parent 342cd68 commit 6bbac7d

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
if (( $# > 0 )); then
4+
# received arguments, format those files
5+
clang-format-12 -i "$@"
6+
else
7+
# received no arguments, find files on our own
8+
find include/ src/ test/ examples/ \
9+
-regextype egrep \
10+
-type f -regex '.*\.(hpp|cpp|hpp\.in)$' \
11+
| xargs clang-format-12 -i
12+
fi

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ repos:
6262

6363
# C++ formatting
6464
# clang-format
65+
- repo: local
66+
hooks:
67+
- id: clang-format
68+
name: clang-format
69+
description: Clang-format our code base
70+
files: '^(include|src|test|examples)/.*\.(hpp|cpp|hpp\.in)$'
71+
language: conda
72+
entry: bash .github/workflows/clang-format/clang-format.sh
73+
additional_dependencies: [-c, conda-forge, clang-format-12]
6574

6675
# Autoremoves unused Python imports
6776
- repo: https://github.com/hadialqattan/pycln

environment.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# I am a conda environment, used for our pre-commit hooks
2+
name: openPMD-api-dev
3+
channels:
4+
- conda-forge
5+
dependencies:
6+
- clang-format-12=12.0.1
7+
- bash=5

0 commit comments

Comments
 (0)