Skip to content

Commit 81bb9d8

Browse files
mrbean-bremenusiems
authored andcommitted
Add pre-commit hook for clang-format
- exclude unwanted directories by adding disabling .clang-format files - also add a hooks for line endings, trailing spaces and case/merge conflicts
1 parent 89fe8d2 commit 81bb9d8

File tree

4 files changed

+19
-16
lines changed

4 files changed

+19
-16
lines changed

.pre-commit-config.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/mirrors-clang-format
3+
rev: "v21.1.5"
4+
hooks:
5+
- id: clang-format
6+
7+
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v6.0.0
10+
hooks:
11+
- id: check-case-conflict
12+
- id: check-merge-conflict
13+
- id: trailing-whitespace
14+
- id: mixed-line-ending

generated_cpp_515/.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DisableFormat: true
2+
SortIncludes: Never

generator/simplecpp/.clang-format

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
DisableFormat: true
2+
SortIncludes: Never

run-clang-format.sh

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,4 @@ which -a clang-format-20 > /dev/null \
44
|| (echo -e "20.0.0\n$(clang-format${1+-$1} --version | grep -Eo '([0-9]+\.[0-9]+\.[0-9]+)')" | sort -CV ) \
55
|| { echo "use '${0} <clang-format-version-not-less-than-20>' to call exact proper version" ; exit 1 ; }
66

7-
IGNORED_DIRS=(
8-
"./generated_cpp_515"
9-
"./examples"
10-
"./generator/simplecpp"
11-
"./build"
12-
)
13-
14-
IGNORE_CMD=""
15-
16-
for DIR in "${IGNORED_DIRS[@]}"; do
17-
IGNORE_CMD+=" -path $DIR -o"
18-
done
19-
20-
IGNORE_CMD=${IGNORE_CMD% -o}
21-
22-
find . \( $IGNORE_CMD \) -prune -o -name '*.cpp' -print0 -o -name '*.h' -print0 | xargs -0 clang-format-20 --style=file -i
7+
find . -prune -o -name '*.cpp' -print0 -o -name '*.h' -print0 | xargs -0 clang-format-20 --style=file -i

0 commit comments

Comments
 (0)