forked from endee-io/endee
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.clang-format
More file actions
143 lines (124 loc) · 6.98 KB
/
.clang-format
File metadata and controls
143 lines (124 loc) · 6.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# .clang-format
# Goal: readable, diff-friendly C++ formatting with safer control-flow.
---
# ============================================================
# Language & base preset
# ============================================================
Language: Cpp # Apply rules for C++ (also works fine for C/ObjC/CUDA)
BasedOnStyle: LLVM # Start from LLVM defaults, then override below
# ============================================================
# Indentation & line length
# ============================================================
IndentWidth: 4 # 4 spaces per indent level
TabWidth: 4 # Visual width of a tab (even though tabs are disabled)
UseTab: Never # Never emit tabs; always spaces
ContinuationIndentWidth: 8 # Indent wrapped lines by 8 spaces
ColumnLimit: 100 # Wrap long lines at 100 columns
# Prefer readable wrapping over "one-line everything"
AllowShortBlocksOnASingleLine: Never # Never format `{ ... }` blocks on one line
AllowShortFunctionsOnASingleLine: InlineOnly # Only allow one-line functions if marked inline
AllowShortIfStatementsOnASingleLine: Never # Never allow: `if (x) y;`
AllowShortLoopsOnASingleLine: false # Never allow: `for(...) x;` / `while(...) x;`
AllowShortCaseLabelsOnASingleLine: false # Never allow: `case 1: foo();`
# ============================================================
# Braces & control-flow
# ============================================================
BreakBeforeBraces: Attach # Attach brace for control statements: `if (x) {`
BraceWrapping:
# For declarations, use brace-on-next-line (Allman-ish)
AfterClass: true # class Foo\n{
AfterEnum: true # enum E\n{
AfterFunction: true # void f()\n{
AfterNamespace: true # namespace n\n{
AfterStruct: true # struct S\n{
AfterUnion: true # union U\n{
# For control statements, keep brace attached (K&R-ish)
AfterControlStatement: false # if (x) {
# Other brace behaviors
BeforeCatch: true # }\ncatch (...) {
BeforeElse: true # }\nelse {
IndentBraces: false # Don't indent the braces themselves
SplitEmptyFunction: true # Format empty function braces on separate lines
SplitEmptyRecord: true # Same for empty class/struct/union
SplitEmptyNamespace: true # Same for empty namespace
InsertBraces: true # Always add braces where optional (safer, avoids bugs)
IncludeBlocks: Preserve
SortIncludes: Never
# ============================================================
# Pointers/references, spaces, and operators
# ============================================================
PointerAlignment: Left # `int* p` (star sticks to type)
ReferenceAlignment: Pointer # Align `&` similar to `*`: `Foo& x`
SpaceBeforeParens: Never # `if (x)` but `f(x)` (no space for calls)
SpacesInParentheses: false # `( x )` -> `(x)`
SpacesInSquareBrackets: false # `[ x ]` -> `[x]`
SpaceInEmptyParentheses: false # `f( )` -> `f()`
SpaceAfterCStyleCast: false # `(int)x` (no space after cast)
SpaceBeforeAssignmentOperators: true # `a = b`, `x += y`
SpacesBeforeTrailingComments: 2 # Ensure 2 spaces before `// comment`
SpacesInAngles: false # `std::vector<int>` (no spaces in templates)
# ============================================================
# Alignment preferences
# ============================================================
AlignAfterOpenBracket: Align # Align parameters/args under first after '(' or '['
AlignConsecutiveAssignments:
Enabled: false # Don't align `=` across multiple lines (avoids big diffs)
AlignConsecutiveDeclarations:
Enabled: false # Don't align declarations columns (avoids churn)
AlignOperands: true # Align operands when breaking long expressions
AlignTrailingComments: true # Align `//` comments vertically where reasonable
# ============================================================
# Function calls & declarations
# ============================================================
BinPackArguments: false # Don't cram args on one line; break vertically
BinPackParameters: false # Same for function parameters
AllowAllArgumentsOnNextLine: true # Allow moving all args to next line when wrapping
AllowAllParametersOfDeclarationOnNextLine: true # Same for declarations
# Break long expressions predictably
BreakBeforeBinaryOperators: NonAssignment # Break before +, &&, etc. (not before '=')
BreakBeforeTernaryOperators: true # Break ternaries consistently
BreakStringLiterals: true # Allow breaking long string literals
# ============================================================
# Constructor initializer lists
# ============================================================
BreakConstructorInitializers: AfterColon # Break after `:`
ConstructorInitializerIndentWidth: 4 # Indent initializer list by 4
PackConstructorInitializers: Never # One initializer per line (diff-friendly)
# ============================================================
# Switch / case formatting
# ============================================================
IndentCaseLabels: true # Indent `case` labels under switch
IndentCaseBlocks: false # Don't add extra indent for the case block body
# ============================================================
# Preprocessor / macros
# ============================================================
IndentPPDirectives: AfterHash # Indent preprocessor directives after '#'
MacroBlockBegin: '' # No special macro block markers
MacroBlockEnd: '' # No special macro block markers
# ============================================================
# Namespaces & access modifiers
# ============================================================
NamespaceIndentation: All # Indent code inside namespaces
AccessModifierOffset: -4 # `public:` aligns with class body start (not indented)
# ============================================================
# Comments
# ============================================================
ReflowComments: true # Wrap/reflow comment text to fit ColumnLimit
SpacesInLineCommentPrefix:
Minimum: 0
Maximum: -1 # Preserve original spacing after //
# ============================================================
# Misc / consistency helpers
# ============================================================
DerivePointerAlignment: false # Don't infer pointer alignment from existing code; enforce Left
FixNamespaceComments: true # Add/fix `} // namespace ...` comments
# Treat these as "foreach-like" macros (so formatting behaves like loops)
ForEachMacros:
- FOREACH
- FOREACH_CONST
# Treat these as statement-like macros (indent/splitting behaves like statements)
StatementMacros:
- Q_UNUSED
- DCHECK
- CHECK
...