Skip to content

Commit 272c74b

Browse files
committed
[RFC] global/clang-format: Add .clang-format configuration for consistent formatting
This is an attempt to create and establish a common definition for code formatting. Besides .clang-format, there don't seem to be many good candidates for C when looking for non-proprietary open-source solutions, so there's wasn't really much choice. I have tried to configure everything according to the current guidelines, to which it should come pretty close. There are a few things for which I couldn't find any FFmpeg rules, or where it wasn't clear and I made choices that seemed reasonable. This is in no way intended to prescribe any formatting detail rules, it's rather meant as an invitation to collaborate on this and ideally end up with something "official" that allows to check and fix formatting in CI flows or Patchwork and locally for everybody using editors with clang-format support or using clang-format from the command line. Signed-off-by: softworkz <[email protected]>
1 parent b6c2498 commit 272c74b

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed

.clang-format

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
BasedOnStyle: GNU
3+
4+
# Alignment & indentation rules
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: Consecutive
7+
AlignConsecutiveDeclarations: AcrossEmptyLinesAndComments
8+
AlignArrayOfStructures: Left
9+
AlignOperands: false
10+
AlignTrailingComments: Always
11+
AlignEscapedNewlines: LeftWithLastLine
12+
IndentWidth: 4
13+
ContinuationIndentWidth: 4
14+
UseTab: Never
15+
TabWidth: 4
16+
IndentPPDirectives: None
17+
IndentCaseBlocks: true
18+
IndentCaseLabels: false
19+
IndentGotoLabels: true
20+
PointerAlignment: Right
21+
22+
AlignConsecutiveShortCaseStatements:
23+
Enabled: true
24+
AcrossEmptyLines: true
25+
AcrossComments: true
26+
AlignCaseColons: false
27+
28+
# Bracing style
29+
BreakBeforeBraces: Custom
30+
BraceWrapping:
31+
AfterCaseLabel: true
32+
AfterControlStatement: Never
33+
AfterEnum: true
34+
AfterFunction: true
35+
AfterClass: false
36+
AfterStruct: false
37+
AfterUnion: false
38+
AfterExternBlock: false
39+
BeforeElse: false
40+
SplitEmptyFunction: true
41+
SplitEmptyRecord: true
42+
BreakAfterReturnType: None
43+
44+
# Keep lines from becoming too long (adjust to your preference)
45+
ColumnLimit: 0
46+
47+
# Misc formatting
48+
AlwaysBreakAfterReturnType: None
49+
BinPackArguments: false
50+
BinPackParameters: false
51+
# BinPackLongBracedList: false
52+
BreakBeforeTernaryOperators: true
53+
InsertNewlineAtEOF: true
54+
MaxEmptyLinesToKeep: 2
55+
AlwaysBreakAfterDefinitionReturnType: None
56+
57+
# Include style
58+
SortIncludes: Never
59+
IncludeBlocks: Preserve
60+
IncludeCategories:
61+
- Regex: '^<.*'
62+
Priority: 1
63+
- Regex: '^".*'
64+
Priority: 2
65+
- Regex: '.*'
66+
Priority: 3
67+
68+
# Spacing
69+
SpaceAfterCStyleCast: false
70+
SpaceAfterLogicalNot: false
71+
SpaceBeforeAssignmentOperators: true
72+
SpaceBeforeParens: ControlStatements
73+
SpaceBeforeSquareBrackets: false
74+
SpaceInEmptyParentheses: false
75+
SpacesBeforeTrailingComments: 1
76+
SpacesInAngles: false
77+
SpacesInConditionalStatement: false
78+
SpacesInCStyleCastParentheses: false
79+
SpacesInParentheses: false
80+
SpacesInSquareBrackets: false
81+
...

0 commit comments

Comments
 (0)