-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.clang-format
More file actions
191 lines (139 loc) · 4.42 KB
/
.clang-format
File metadata and controls
191 lines (139 loc) · 4.42 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# SPDX-License-Identifier: Apache-2.0
#
# RyanJson clang-format 基线配置
# 说明:
# - 注释尽量覆盖每个配置项,便于长期维护
# - 以 LLVM 为基线,只覆盖项目明确约束
# - 参考:https://clang.llvm.org/docs/ClangFormatStyleOptions.html
---
# 基础风格模板:以 LLVM 为起点
BasedOnStyle: LLVM
# 单行最大宽度:超过后自动换行
ColumnLimit: 140
# 基础缩进宽度(单位:列)
IndentWidth: 8
# Tab 显示宽度(单位:列)
TabWidth: 8
# 续行缩进宽度(函数参数折行、表达式折行等)
ContinuationIndentWidth: 8
# 构造函数初始化列表缩进宽度(主要影响 C++,保留统一)
ConstructorInitializerIndentWidth: 8
# Tab 使用策略:缩进和续行使用 Tab
UseTab: ForContinuationAndIndentation
# 注释重排:false 表示不自动重排注释文本
ReflowComments: false
# 是否允许短代码块单行(如 { return; })
AllowShortBlocksOnASingleLine: Always
# 是否允许短函数单行
AllowShortFunctionsOnASingleLine: false
# 是否允许短 if 单行
AllowShortIfStatementsOnASingleLine: WithoutElse
# 是否允许短循环单行
AllowShortLoopsOnASingleLine: false
# 是否允许短 case 标签单行
AllowShortCaseLabelsOnASingleLine: true
# 是否允许短 case 表达式单行
AllowShortCaseExpressionOnASingleLine: true
# 是否允许短枚举单行
AllowShortEnumsOnASingleLine: false
# 花括号总策略:自定义
BreakBeforeBraces: Custom
# case 标签后的大括号是否换行
BraceWrapping:
AfterCaseLabel: false
# class 后的大括号是否换行
AfterClass: true
# 控制语句(if/for/while)后的大括号换行策略
AfterControlStatement: Always
# enum 后的大括号是否换行
AfterEnum: true
# extern block 后的大括号是否换行
AfterExternBlock: false
# 函数定义后的大括号是否换行
AfterFunction: true
# namespace 后的大括号是否换行
AfterNamespace: true
# ObjC 声明后的大括号是否换行
AfterObjCDeclaration: true
# struct 后的大括号是否换行
AfterStruct: true
# union 后的大括号是否换行
AfterUnion: false
# catch 前是否换行
BeforeCatch: true
# else 前是否换行
BeforeElse: true
# lambda 体前是否换行
BeforeLambdaBody: false
# do...while 中 while 前是否换行
BeforeWhile: false
# 大括号行本身是否额外缩进
IndentBraces: false
# 空函数是否分裂成多行
SplitEmptyFunction: true
# 空记录(如空 struct)是否分裂成多行
SplitEmptyRecord: true
# 空命名空间是否分裂成多行
SplitEmptyNamespace: true
# switch 内 case 标签是否额外缩进
IndentCaseLabels: false
# goto 标签是否额外缩进
IndentGotoLabels: false
# 是否强制插入花括号(单语句控制流也加花括号)
InsertBraces: true
# 文件末尾是否补换行
InsertNewlineAtEOF: true
# 位域冒号前后空格策略
BitFieldColonSpacing: After
# 控制语句括号前空格策略(if (x))
SpaceBeforeParens: ControlStatementsExceptControlMacros
# 继承冒号前空格策略(主要影响 C++)
SpaceBeforeInheritanceColon: false
# 连续宏定义对齐策略
AlignConsecutiveMacros:
# 是否启用连续宏对齐
Enabled: true
# 是否跨注释继续对齐
AcrossComments: true
# include 是否自动排序(Never 表示保持人工顺序)
SortIncludes: Never
# include 分类规则(数值越小优先级越高)
IncludeCategories:
# 项目内双引号头文件
- Regex: '^".*\.h"$'
Priority: 0
# C 标准库头文件
- Regex: '^<(assert|complex|ctype|errno|fenv|float|inttypes|limits|locale|math|setjmp|signal|stdarg|stdbool|stddef|stdint|stdio|stdlib|string|tgmath|time|wchar|wctype)\.h>$'
Priority: 1
# Ryan 体系头文件
- Regex: '^<Ryan/.*\.h>$'
Priority: 2
# 兜底分类
- Regex: ".*"
Priority: 3
# 视为 foreach 语义的宏列表(用于正确缩进与换行)
ForEachMacros:
- RyanJsonArrayForEach
- RyanJsonObjectForEach
# 视为 if 语义的宏列表
IfMacros:
- CHECKIF
# 视为属性的宏列表(影响断行与对齐)
AttributeMacros:
- __aligned
- __deprecated
- __packed
- __printf_like
- __syscall
- __syscall_always_inline
- __subsystem
# 空白敏感宏:保持参数空格布局,避免被格式化破坏
WhitespaceSensitiveMacros:
- COND_CODE_0
- COND_CODE_1
- IF_DISABLED
- IF_ENABLED
- LISTIFY
- STRINGIFY
- Z_STRINGIFY
- DT_FOREACH_PROP_ELEM_SEP