Skip to content

Commit ca4eb0f

Browse files
committed
Clang format in the CI
Signed-off-by: Mateusz Mazur <mateusz.mazur@e.email>
1 parent 96661a0 commit ca4eb0f

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

.clang-format

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ AccessModifierOffset: -2
55
AlignAfterOpenBracket: Align
66
AlignArrayOfStructures: None
77
AlignConsecutiveAssignments:
8-
Enabled: true
8+
Enabled: true
99
AcrossEmptyLines: false
1010
AcrossComments: false
1111
AlignCompound: false
@@ -26,7 +26,7 @@ AlignConsecutiveDeclarations:
2626
AlignFunctionPointers: false
2727
PadOperators: false
2828
AlignConsecutiveMacros:
29-
Enabled: false
29+
Enabled: false
3030
AcrossEmptyLines: false
3131
AcrossComments: false
3232
AlignCompound: false

.github/workflows/clang-format.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Clang formatting checker
2+
3+
on:
4+
push:
5+
branches: ["master"]
6+
pull_request:
7+
branches: ["master"]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
container:
13+
image: silkeh/clang # https://hub.docker.com/r/silkeh/clang
14+
env:
15+
DRY: "TRUE"
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
with:
20+
fetch-depth: 1
21+
22+
- name: Checking formatting
23+
run: DRY=TRUE bash reformat-all.sh

reformat-all.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
#!/bin/sh
1+
#!/usr/bin/env bash
22

3-
find . -name '*.cpp' -o -name '*.hpp' | xargs clang-format -i -style=file
3+
ALL_FORMATABLE_FILES=$(find src include tests example -name '*.cpp' -o -name '*.hpp')
4+
CLANG_FORMAT_ARGS="-style=file"
5+
6+
echo "*** Modbus Clang Format Wrapper **"
7+
clang-format --version
8+
9+
if [[ "$DRY" = "TRUE" ]]; then
10+
diff_count=`clang-format --dry-run $CLANG_FORMAT_ARGS $ALL_FORMATABLE_FILES 2>&1 | wc -l`
11+
exit $(($diff_count > 0))
12+
else
13+
clang-format -i --verbose $CLANG_FORMAT_ARGS $ALL_FORMATABLE_FILES
14+
fi

0 commit comments

Comments
 (0)