Skip to content

Commit a51a03e

Browse files
committed
Add a clang-format and format the code accordingly
This is fairly close to what we have and at least enforces a consistent coding style. The only true change in style is no indentation for case in switch statements, the rest is a combination of styles we already used in one place or another, just not consistently.
1 parent ff0c5a6 commit a51a03e

20 files changed

+2419
-1332
lines changed

.clang-format

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
AlignAfterOpenBracket: Align
2+
# This option we want but it's frequently broken and causes bad
3+
# misalignment. The canary is wheel_click_count_parser, if that works
4+
# we can actually enable it.
5+
# AlignArrayOfStructures: Left
6+
AlignConsecutiveShortCaseStatements:
7+
Enabled: true
8+
AcrossEmptyLines: false
9+
AcrossComments: true
10+
AlignCaseColons: false
11+
AllowAllParametersOfDeclarationOnNextLine: false
12+
AllowAllArgumentsOnNextLine: false
13+
BinPackArguments: false
14+
BinPackParameters: AlwaysOnePerLine
15+
BraceWrapping:
16+
AfterFunction: true
17+
BreakAfterReturnType: All
18+
BreakBeforeBraces: Custom
19+
BreakStringLiterals: false
20+
ColumnLimit: 88
21+
ContinuationIndentWidth: 8
22+
Cpp11BracedListStyle: false
23+
IncludeBlocks: Regroup
24+
IncludeCategories:
25+
- Regex: '^(<|")config\.h(>|")'
26+
Priority: 0
27+
SortPriority: 0
28+
- Regex: '^<.*'
29+
Priority: 1
30+
SortPriority: 0
31+
- Regex: '^"util-.*'
32+
Priority: 2
33+
SortPriority: 0
34+
- Regex: '.*'
35+
Priority: 3
36+
SortPriority: 0
37+
IndentCaseLabels: false
38+
IndentWidth: 8
39+
PointerAlignment: Right
40+
RemoveEmptyLinesInUnwrappedLines: true
41+
RemoveParentheses: MultipleParentheses
42+
RemoveSemicolon: true
43+
SkipMacroDefinitionBody: true
44+
SortIncludes: true
45+
SpaceAfterCStyleCast: false
46+
SpaceAfterLogicalNot: false
47+
SpaceBeforeAssignmentOperators: true
48+
SpaceBeforeCaseColon: false
49+
SpaceBeforeParens: ControlStatementsExceptControlMacros
50+
SpacesInContainerLiterals: true
51+
SpacesInParens: Custom
52+
TabWidth: 8
53+
UseTab: ForContinuationAndIndentation

.clang-format-ignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include/**/*

.github/workflows/style.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: "Coding style"
2+
3+
on: [ push, pull_request ]
4+
5+
permissions:
6+
contents: read
7+
8+
# see https://github.com/ssciwr/clang-format-wheel
9+
env:
10+
PIP_PACKAGES: clang-format
11+
12+
jobs:
13+
clang-format:
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-python@v5
18+
with:
19+
python-version: '3.12'
20+
- uses: ./.github/actions/pkginstall
21+
with:
22+
pip: $PIP_PACKAGES
23+
- run: clang-format -i -- **/*.c **/*.h
24+
- run: git diff --exit-code
25+
- if: failure()
26+
run: echo "Please run clang-format (or via pre-commit) against the modified sources"

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ repos:
1212
- id: ruff
1313
args: ['--ignore=E741,E501']
1414
- id: ruff-format
15+
- repo: https://github.com/pre-commit/mirrors-clang-format
16+
rev: v20.1.6
17+
hooks:
18+
- id: clang-format
19+
types_or: [c]

0 commit comments

Comments
 (0)