Skip to content

Commit f192c25

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 f192c25

2 files changed

Lines changed: 54 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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Clang Format
2+
3+
on:
4+
pull_request:
5+
branches: main
6+
paths:
7+
- 'src/**pp'
8+
push:
9+
branches: main
10+
paths:
11+
- 'src/**pp'
12+
13+
jobs:
14+
check:
15+
name: Check style
16+
runs-on: ubuntu-24.04
17+
container: alpine:edge
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.pull_request.number || github.ref }}
20+
cancel-in-progress: true
21+
steps:
22+
- name: Install clang-format
23+
run: apk add --no-cache clang-extra-tools git python3
24+
- uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
- name: Add safe directory
28+
run: git config --global --add safe.directory $GITHUB_WORKSPACE
29+
- name: Check code style
30+
run: git clang-format --diff --extensions cpp,hpp ${{ github.event.pull_request.base.sha || github.event.before }}

0 commit comments

Comments
 (0)