Skip to content

Commit d5244a2

Browse files
committed
ci: add workflow for running clang-format checks
Refs: #3 Signed-off-by: Natalia Pluta <pluta.natalia.m@gmail.com>
1 parent 3fe1fd9 commit d5244a2

2 files changed

Lines changed: 153 additions & 0 deletions

File tree

.clang-format

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
#
3+
# Note: The list of ForEachMacros can be obtained using:
4+
#
5+
# git grep -h '^#define [^[:space:]]*FOR_EACH[^[:space:]]*(' include/ \
6+
# | sed "s,^#define \([^[:space:]]*FOR_EACH[^[:space:]]*\)(.*$, - '\1'," \
7+
# | sort | uniq
8+
#
9+
# References:
10+
# - https://clang.llvm.org/docs/ClangFormatStyleOptions.html
11+
12+
---
13+
BasedOnStyle: LLVM
14+
AlignConsecutiveMacros: AcrossComments
15+
AllowShortBlocksOnASingleLine: Never
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortEnumsOnASingleLine: false
18+
AllowShortFunctionsOnASingleLine: None
19+
AllowShortIfStatementsOnASingleLine: false
20+
AllowShortLoopsOnASingleLine: false
21+
AttributeMacros:
22+
- __aligned
23+
- __deprecated
24+
- __packed
25+
- __printf_like
26+
- __syscall
27+
- __syscall_always_inline
28+
- __subsystem
29+
BitFieldColonSpacing: After
30+
BreakBeforeBraces: Linux
31+
ColumnLimit: 100
32+
ConstructorInitializerIndentWidth: 8
33+
ContinuationIndentWidth: 8
34+
ForEachMacros:
35+
- 'ARRAY_FOR_EACH'
36+
- 'ARRAY_FOR_EACH_PTR'
37+
- 'FOR_EACH'
38+
- 'FOR_EACH_FIXED_ARG'
39+
- 'FOR_EACH_IDX'
40+
- 'FOR_EACH_IDX_FIXED_ARG'
41+
- 'FOR_EACH_NONEMPTY_TERM'
42+
- 'FOR_EACH_FIXED_ARG_NONEMPTY_TERM'
43+
- 'RB_FOR_EACH'
44+
- 'RB_FOR_EACH_CONTAINER'
45+
- 'SYS_DLIST_FOR_EACH_CONTAINER'
46+
- 'SYS_DLIST_FOR_EACH_CONTAINER_SAFE'
47+
- 'SYS_DLIST_FOR_EACH_NODE'
48+
- 'SYS_DLIST_FOR_EACH_NODE_SAFE'
49+
- 'SYS_SEM_LOCK'
50+
- 'SYS_SFLIST_FOR_EACH_CONTAINER'
51+
- 'SYS_SFLIST_FOR_EACH_CONTAINER_SAFE'
52+
- 'SYS_SFLIST_FOR_EACH_NODE'
53+
- 'SYS_SFLIST_FOR_EACH_NODE_SAFE'
54+
- 'SYS_SLIST_FOR_EACH_CONTAINER'
55+
- 'SYS_SLIST_FOR_EACH_CONTAINER_SAFE'
56+
- 'SYS_SLIST_FOR_EACH_NODE'
57+
- 'SYS_SLIST_FOR_EACH_NODE_SAFE'
58+
- '_WAIT_Q_FOR_EACH'
59+
- 'Z_FOR_EACH'
60+
- 'Z_FOR_EACH_ENGINE'
61+
- 'Z_FOR_EACH_EXEC'
62+
- 'Z_FOR_EACH_FIXED_ARG'
63+
- 'Z_FOR_EACH_FIXED_ARG_EXEC'
64+
- 'Z_FOR_EACH_IDX'
65+
- 'Z_FOR_EACH_IDX_EXEC'
66+
- 'Z_FOR_EACH_IDX_FIXED_ARG'
67+
- 'Z_FOR_EACH_IDX_FIXED_ARG_EXEC'
68+
- 'Z_GENLIST_FOR_EACH_CONTAINER'
69+
- 'Z_GENLIST_FOR_EACH_CONTAINER_SAFE'
70+
- 'Z_GENLIST_FOR_EACH_NODE'
71+
- 'Z_GENLIST_FOR_EACH_NODE_SAFE'
72+
- 'STRUCT_SECTION_FOREACH'
73+
- 'STRUCT_SECTION_FOREACH_ALTERNATE'
74+
- 'TYPE_SECTION_FOREACH'
75+
- 'K_SPINLOCK'
76+
- 'COAP_RESOURCE_FOREACH'
77+
- 'COAP_SERVICE_FOREACH'
78+
- 'COAP_SERVICE_FOREACH_RESOURCE'
79+
- 'HTTP_RESOURCE_FOREACH'
80+
- 'HTTP_SERVER_CONTENT_TYPE_FOREACH'
81+
- 'HTTP_SERVICE_FOREACH'
82+
- 'HTTP_SERVICE_FOREACH_RESOURCE'
83+
- 'I3C_BUS_FOR_EACH_I3CDEV'
84+
- 'I3C_BUS_FOR_EACH_I2CDEV'
85+
IfMacros:
86+
- 'CHECKIF'
87+
# Disabled for now, see bug https://github.com/zephyrproject-rtos/zephyr/issues/48520
88+
#IncludeBlocks: Regroup
89+
IncludeCategories:
90+
- Regex: '^".*\.h"$'
91+
Priority: 0
92+
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$'
93+
Priority: 1
94+
- Regex: '^\<zephyr/.*\.h\>$'
95+
Priority: 2
96+
- Regex: '.*'
97+
Priority: 3
98+
IndentCaseLabels: false
99+
IndentGotoLabels: false
100+
IndentWidth: 8
101+
InsertBraces: true
102+
InsertNewlineAtEOF: true
103+
SpaceBeforeInheritanceColon: False
104+
SpaceBeforeParens: ControlStatementsExceptControlMacros
105+
SortIncludes: Never
106+
UseTab: ForContinuationAndIndentation
107+
WhitespaceSensitiveMacros:
108+
- COND_CODE_0
109+
- COND_CODE_1
110+
- IF_DISABLED
111+
- IF_ENABLED
112+
- LISTIFY
113+
- STRINGIFY
114+
- Z_STRINGIFY
115+
- DT_FOREACH_PROP_ELEM_SEP

.github/workflows/clang-format.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: clang-format
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.c'
7+
- '**/*.cpp'
8+
- '**/*.h'
9+
- '**/*.hpp'
10+
11+
jobs:
12+
clang-format:
13+
runs-on: ubuntu-24.04
14+
name: Run clang-format
15+
16+
steps:
17+
- name: Checkout repository with fire detection system
18+
uses: actions/checkout@v4
19+
20+
- name: Install clang-format
21+
run: |
22+
sudo apt-get update
23+
sudo apt-get install -y clang-format-18
24+
25+
- name: Run clang-format on changed files
26+
run: |
27+
git diff --name-only --diff-filter=ACMRTUXB ${{ github.base_ref }} | \
28+
grep -E '\.(c|cpp|h|hpp)$' | \
29+
xargs -r clang-format-18 -i -style=file
30+
31+
- name: Check for unformatted files
32+
run: |
33+
if git diff --exit-code; then
34+
echo "All files are properly formatted."
35+
else
36+
echo "Code is not formatted correctly. Please run clang-format."
37+
exit 1
38+
fi

0 commit comments

Comments
 (0)