Skip to content

Commit d21f0c1

Browse files
committed
Add .clang-format file for consistent code formatting
This also adds a CI job to impose the rules on new code.
1 parent 9bd618f commit d21f0c1

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

.clang-format

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
---
2+
BasedOnStyle: LLVM
3+
Language: Cpp
4+
5+
AlignAfterOpenBracket: BlockIndent
6+
AllowShortFunctionsOnASingleLine: Inline
7+
ColumnLimit: 120
8+
Cpp11BracedListStyle: false
9+
IncludeBlocks: Regroup
10+
IncludeCategories:
11+
- Regex: '^".*"$'
12+
Priority: 1
13+
- Regex: '^<.*\..*>$'
14+
Priority: 2
15+
- Regex: '^<.*>$'
16+
Priority: 3
17+
IndentPPDirectives: AfterHash
18+
NamespaceIndentation: All
19+
QualifierAlignment: Left
20+
PointerAlignment: Left
21+
SpaceBeforeCpp11BracedList: true
22+
TabWidth: 2
23+
UseTab: Always
24+
...

.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 Format
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'src/**pp'
7+
8+
jobs:
9+
check:
10+
name: Check style
11+
runs-on: ubuntu-24.04
12+
container: alpine:edge
13+
concurrency:
14+
group: ${{ github.workflow }}-${{ github.pull_request.number || github.ref }}
15+
cancel-in-progress: true
16+
steps:
17+
- name: Install clang-format
18+
run: apk add --no-cache clang-extra-tools git python3
19+
- uses: actions/checkout@v4
20+
- name: Add git repository to safe directory
21+
run: git config --global --add safe.directory $GITHUB_WORKSPACE
22+
- name: Check code style
23+
run: git clang-format --diff --extensions cpp,hpp ${{ github.event.pull_request.base.sha | github.}})

0 commit comments

Comments
 (0)