Skip to content

Commit 91c8103

Browse files
authored
Add precommit hooks for clang-format (#227)
1 parent 1eba873 commit 91c8103

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed

.clang-format

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
AccessModifierOffset: -1
3+
AlignAfterOpenBracket: AlwaysBreak
4+
AlignConsecutiveMacros: false
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveBitFields: false
7+
AlignConsecutiveDeclarations: false
8+
AlignEscapedNewlines: Left
9+
AlignOperands: DontAlign
10+
AlignTrailingComments: false
11+
AllowAllArgumentsOnNextLine: true
12+
AllowAllConstructorInitializersOnNextLine: true
13+
AllowAllParametersOfDeclarationOnNextLine: false
14+
AllowShortEnumsOnASingleLine: true
15+
AllowShortBlocksOnASingleLine: Never
16+
AllowShortCaseLabelsOnASingleLine: false
17+
AllowShortFunctionsOnASingleLine: Empty
18+
AllowShortLambdasOnASingleLine: All
19+
AllowShortIfStatementsOnASingleLine: Never
20+
AllowShortLoopsOnASingleLine: false
21+
AlwaysBreakAfterReturnType: None
22+
AlwaysBreakBeforeMultilineStrings: true
23+
AlwaysBreakTemplateDeclarations: Yes
24+
BinPackArguments: false
25+
BinPackParameters: false
26+
BreakBeforeBinaryOperators: None
27+
BreakBeforeBraces: Attach
28+
BreakInheritanceList: BeforeColon
29+
BreakBeforeTernaryOperators: true
30+
BreakConstructorInitializers: BeforeColon
31+
BreakAfterJavaFieldAnnotations: false
32+
BreakStringLiterals: false
33+
ColumnLimit: 80
34+
CommentPragmas: '^ IWYU pragma:'
35+
CompactNamespaces: false
36+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
37+
ConstructorInitializerIndentWidth: 4
38+
ContinuationIndentWidth: 4
39+
Cpp11BracedListStyle: true
40+
DeriveLineEnding: true
41+
DerivePointerAlignment: false
42+
DisableFormat: false
43+
FixNamespaceComments: true
44+
ForEachMacros:
45+
- FOR_EACH
46+
- FOR_EACH_R
47+
- FOR_EACH_RANGE
48+
IncludeBlocks: Preserve
49+
IncludeCategories:
50+
- Regex: '^<.*\.h(pp)?>'
51+
Priority: 1
52+
- Regex: '^<.*'
53+
Priority: 2
54+
- Regex: '.*'
55+
Priority: 3
56+
IndentCaseLabels: true
57+
IndentCaseBlocks: false
58+
IndentGotoLabels: true
59+
IndentPPDirectives: None
60+
IndentExternBlock: AfterExternBlock
61+
IndentWidth: 2
62+
IndentWrappedFunctionNames: false
63+
InsertTrailingCommas: None
64+
JavaScriptQuotes: Leave
65+
JavaScriptWrapImports: true
66+
KeepEmptyLinesAtTheStartOfBlocks: false
67+
MacroBlockBegin: ''
68+
MacroBlockEnd: ''
69+
MaxEmptyLinesToKeep: 1
70+
NamespaceIndentation: None
71+
ObjCBinPackProtocolList: Auto
72+
ObjCBlockIndentWidth: 2
73+
ObjCBreakBeforeNestedBlockParam: true
74+
ObjCSpaceAfterProperty: false
75+
ObjCSpaceBeforeProtocolList: false
76+
PenaltyBreakAssignment: 2
77+
PenaltyBreakBeforeFirstCallParameter: 1
78+
PenaltyBreakComment: 300
79+
PenaltyBreakFirstLessLess: 120
80+
PenaltyBreakString: 1000
81+
PenaltyBreakTemplateDeclaration: 10
82+
PenaltyExcessCharacter: 1000000
83+
PenaltyReturnTypeOnItsOwnLine: 200
84+
PointerAlignment: Left
85+
ReflowComments: true
86+
SortIncludes: true
87+
SortUsingDeclarations: true
88+
SpaceAfterCStyleCast: false
89+
SpaceAfterLogicalNot: false
90+
SpaceAfterTemplateKeyword: true
91+
SpaceBeforeAssignmentOperators: true
92+
SpaceBeforeCpp11BracedList: false
93+
SpaceBeforeCtorInitializerColon: true
94+
SpaceBeforeInheritanceColon: true
95+
SpaceBeforeParens: ControlStatements
96+
SpaceBeforeRangeBasedForLoopColon: true
97+
SpaceInEmptyBlock: false
98+
SpaceInEmptyParentheses: false
99+
SpacesBeforeTrailingComments: 1
100+
SpacesInAngles: false
101+
SpacesInConditionalStatement: false
102+
SpacesInContainerLiterals: true
103+
SpacesInCStyleCastParentheses: false
104+
SpacesInParentheses: false
105+
SpacesInSquareBrackets: false
106+
SpaceBeforeSquareBrackets: false
107+
Standard: Latest
108+
TabWidth: 8
109+
UseCRLF: false
110+
UseTab: Never
111+
...

.github/workflows/lint.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ jobs:
3636
run: |
3737
python -m pip install pre-commit
3838
- name: Run pre-commit checks
39+
# Continue on error to display the formatting diff in case lint fails.
40+
continue-on-error: true
3941
run: |
4042
pre-commit run --all-files
43+
- name: Check to see what files pre-commit modified
44+
run: |
45+
git diff
4146
4247
mypy:
4348
runs-on: ubuntu-latest

.pre-commit-config.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ repos:
2727
hooks:
2828
- id: flake8
2929
args: [--config=.flake8]
30+
31+
- repo: https://github.com/pre-commit/mirrors-clang-format
32+
rev: v18.1.3
33+
hooks:
34+
- id: clang-format
35+
name: clang-format
36+
files: \.(cpp|hpp|c|h)$
37+
types: [file]

0 commit comments

Comments
 (0)