.clang-format 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. ---
  2. # 语言: None, Cpp, Java, JavaScript, ObjC, Proto, TableGen, TextProto
  3. Language: Cpp
  4. BasedOnStyle: Google
  5. # 访问说明符(public、private等)的偏移
  6. AccessModifierOffset: -4
  7. # 开括号(开圆括号、开尖括号、开方括号)后的对齐: Align, DontAlign, AlwaysBreak(总是在开括号后换行)
  8. AlignAfterOpenBracket: Align
  9. # 对齐数组列
  10. AlignArrayOfStructures: None
  11. # 对齐连续宏定义
  12. AlignConsecutiveMacros: #AcrossEmptyLinesAndComments
  13. Enabled: true
  14. AcrossEmptyLines: true
  15. AcrossComments: false
  16. AlignCompound: false
  17. PadOperators: false
  18. # 连续赋值时,对齐所有等号
  19. AlignConsecutiveAssignments:
  20. Enabled: true
  21. AcrossEmptyLines: false
  22. AcrossComments: false
  23. AlignCompound: false
  24. PadOperators: false
  25. # 对齐连续位字段
  26. AlignConsecutiveBitFields:
  27. Enabled: true
  28. AcrossEmptyLines: false
  29. AcrossComments: false
  30. AlignCompound: false
  31. PadOperators: false
  32. # 连续声明时,对齐所有声明的变量名
  33. AlignConsecutiveDeclarations:
  34. Enabled: true
  35. AcrossEmptyLines: false
  36. AcrossComments: false
  37. AlignCompound: false
  38. PadOperators: false
  39. # 左对齐逃脱换行(使用反斜杠换行)的反斜杠
  40. AlignEscapedNewlines: Left
  41. # 水平对齐二元和三元表达式的操作数
  42. AllowAllArgumentsOnNextLine: true
  43. AllowAllConstructorInitializersOnNextLine: true
  44. AlwaysBreakAfterDefinitionReturnType: None
  45. AlignOperands: true #Align
  46. # 对齐连续的尾随的注释
  47. AlignTrailingComments: true
  48. # 允许函数声明的所有参数在放在下一行
  49. AllowAllParametersOfDeclarationOnNextLine: false
  50. # 允许短的枚举放在同一行
  51. AllowShortEnumsOnASingleLine: true
  52. # 允许短的块放在同一行
  53. AllowShortBlocksOnASingleLine: Never
  54. # 允许短的case标签放在同一行
  55. AllowShortCaseLabelsOnASingleLine: false
  56. # 允许短的函数放在同一行
  57. AllowShortFunctionsOnASingleLine: false #All
  58. # 允许短的匿名函数放在同一行
  59. AllowShortLambdasOnASingleLine: All
  60. # 允许短的if语句保持在同一行
  61. AllowShortIfStatementsOnASingleLine: Never
  62. # 允许短的循环保持在同一行
  63. AllowShortLoopsOnASingleLine: false
  64. # 总是在返回类型后换行
  65. AlwaysBreakAfterReturnType: None
  66. # 总是在多行string字面量前换行
  67. AlwaysBreakBeforeMultilineStrings: false
  68. # 总是在template声明后换行
  69. AlwaysBreakTemplateDeclarations: MultiLine
  70. # 属性声明相关配置
  71. AttributeMacros:
  72. - __capability
  73. # false表示函数实参要么都在同一行,要么都各自一行
  74. BinPackArguments: true
  75. # false表示所有形参要么都在同一行,要么都各自一行
  76. BinPackParameters: true
  77. # 是否允许短方法单行,只有一行的函数将不会分行,直接写在函数名后
  78. # 括号是分行,还是不分行,只有当 BreakBeforeBraces 设置为 Custom 时才有效
  79. BraceWrapping:
  80. AfterCaseLabel: true
  81. # class 定义后面
  82. AfterClass: true
  83. # 控制语句后面
  84. AfterControlStatement: true
  85. AfterEnum: true
  86. AfterFunction: true
  87. AfterNamespace: true
  88. AfterObjCDeclaration: true
  89. AfterStruct: true
  90. AfterUnion: true
  91. AfterExternBlock: false
  92. BeforeCatch: true
  93. BeforeElse: true
  94. # 缩进大括号
  95. IndentBraces: false
  96. SplitEmptyFunction: true
  97. SplitEmptyRecord: true
  98. SplitEmptyNamespace: true
  99. BreakBeforeBinaryOperators: None
  100. # BreakAfterAttributes: Never
  101. # BreakArrays: true
  102. # BreakBeforeConceptDeclarations: Always
  103. BreakBeforeBraces: Custom
  104. BreakBeforeInheritanceComma: false
  105. BreakInheritanceList: BeforeColon
  106. # 三元运算符换行后在前
  107. BreakBeforeTernaryOperators: true
  108. BreakConstructorInitializersBeforeComma: false
  109. # 构造函数初始化列表换行规则
  110. BreakConstructorInitializers: BeforeColon
  111. BreakAfterJavaFieldAnnotations: false
  112. BreakStringLiterals: true
  113. # 代码最大列数
  114. ColumnLimit: 0
  115. CommentPragmas: "^ IWYU pragma:"
  116. CompactNamespaces: false
  117. ConstructorInitializerAllOnOneLineOrOnePerLine: false
  118. # 构造函数初始化列表和继承列表换行后缩进的字符数,无符号整数。
  119. ConstructorInitializerIndentWidth: 4
  120. # 当一行代码放不下,自动换行后的缩进
  121. ContinuationIndentWidth: 4
  122. # 大括号列表附近是否有空格{ 1, 2 }/{1, 2}
  123. Cpp11BracedListStyle: true
  124. DeriveLineEnding: true
  125. DerivePointerAlignment: false
  126. # 设置位false后可以使用// clang-format off .. // clang-format on注释禁用某段代码格式化
  127. DisableFormat: false
  128. # 类中访问修饰符后放置空行
  129. EmptyLineAfterAccessModifier: Never
  130. # 类中访问修饰符之前放置空行
  131. EmptyLineBeforeAccessModifier: LogicalBlock
  132. ExperimentalAutoDetectBinPacking: false
  133. # 自动修复命名空间注释名称
  134. FixNamespaceComments: true
  135. ForEachMacros:
  136. - forever
  137. - foreach
  138. - Q_FOREACH
  139. - BOOST_FOREACH
  140. IfMacros:
  141. - KJ_IF_MAYBE
  142. # 头文件分类排序
  143. IncludeBlocks: Preserve
  144. IncludeCategories:
  145. - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
  146. Priority: 2
  147. SortPriority: 0
  148. - Regex: '^(<|"(gtest|gmock|isl|json)/)'
  149. Priority: 3
  150. SortPriority: 0
  151. - Regex: ".*"
  152. Priority: 1
  153. SortPriority: 0
  154. IncludeIsMainRegex: "(Test)?$"
  155. IncludeIsMainSourceRegex: ""
  156. # 指定访问修饰符是否应具有自己的缩进级别
  157. IndentAccessModifiers: false
  158. # case的{}缩进
  159. IndentCaseBlocks: true
  160. # case的标签是否缩进
  161. IndentCaseLabels: true
  162. IndentExternBlock: AfterExternBlock
  163. IndentGotoLabels: true
  164. # 预处理器指令缩进样式
  165. IndentPPDirectives: None
  166. IndentRequiresClause: true
  167. # 换行缩进字符数
  168. IndentWidth: 4
  169. IndentWrappedFunctionNames: false
  170. # 控制语句(if、else、for、do和while)后面自动插入大括号(危险,可能导致代码错误)
  171. InsertBraces: false
  172. # InsertNewlineAtEOF: false
  173. # 仅适用于 JavaScript
  174. # InsertTrailingCommas: None
  175. # IntegerLiteralSeparator: # 格式化整数文字分隔符
  176. # Binary: 4 # 二进制文本中的分隔符格式,按4位分割
  177. # BinaryMinDigits: 0 # 达到多少位二进制文本才进行分割
  178. # Decimal: 3 # 以十进制文字格式设置分隔符的格式。
  179. # DecimalMinDigits: 0 # 十进制最小分割位数
  180. # Hex: 2 # 十六进制文字格式分割个数
  181. # HexMinDigits: 0
  182. JavaScriptQuotes: Leave
  183. JavaScriptWrapImports: true
  184. KeepEmptyLinesAtTheStartOfBlocks: true
  185. # lambda表达式换行、缩进样式样式
  186. LambdaBodyIndentation: Signature
  187. # 换行符样式
  188. # LineEnding: DeriveLF
  189. MacroBlockBegin: ""
  190. MacroBlockEnd: ""
  191. # 要保留的最大连续空行数
  192. MaxEmptyLinesToKeep: 1
  193. # 命名空间缩进
  194. NamespaceIndentation: None
  195. ObjCBinPackProtocolList: Auto
  196. ObjCBlockIndentWidth: 0
  197. ObjCBreakBeforeNestedBlockParam: true
  198. ObjCSpaceAfterProperty: false
  199. ObjCSpaceBeforeProtocolList: true
  200. # 设置初始化列表,和BreakConstructorInitializers 有一定冲突
  201. PackConstructorInitializers: BinPack
  202. PenaltyBreakAssignment: 2
  203. PenaltyBreakBeforeFirstCallParameter: 19
  204. PenaltyBreakComment: 300
  205. PenaltyBreakFirstLessLess: 120
  206. PenaltyBreakString: 1000
  207. PenaltyBreakTemplateDeclaration: 10
  208. PenaltyExcessCharacter: 1000000
  209. PenaltyReturnTypeOnItsOwnLine: 60
  210. # 指针对齐风格
  211. PointerAlignment: Right
  212. ReflowComments: true
  213. PPIndentWidth: -1
  214. # 不同的排列说明符和限定符的方法(危险,可能改变代码含义)
  215. QualifierAlignment: Leave
  216. # 引用对齐风格
  217. # ReferenceAlignment: Pointer
  218. # RemoveBracesLLVM: false
  219. # RemoveSemicolon: false
  220. # RequiresClausePosition: OwnLine
  221. # RequiresExpressionIndentation: OuterScope
  222. # 指定使用空行分隔定义块,包括 类、结构、枚举和函数。
  223. SeparateDefinitionBlocks: Always
  224. ShortNamespaceLines: 1
  225. # 头文件排序规则
  226. SortIncludes: CaseSensitive
  227. SortJavaStaticImport: Before
  228. # using声明排序 Lexicographic
  229. SortUsingDeclarations: true
  230. # 定义在哪些情况下在左括号之前放置空格
  231. SpaceBeforeParens: Custom
  232. # 在C语言风格的强制类型转换后插入空格
  233. SpaceAfterCStyleCast: true
  234. # 不在逻辑运算符 !后插入控制
  235. SpaceAfterLogicalNot: false
  236. SpaceAfterTemplateKeyword: true
  237. SpaceAroundPointerQualifiers: Default
  238. # 赋值运算符前是否有空格
  239. SpaceBeforeAssignmentOperators: true
  240. # case的:前是否有空格
  241. SpaceBeforeCaseColon: false
  242. # 调用构造函数时初始化列表的大括号前面是否有空格
  243. SpaceBeforeCpp11BracedList: false
  244. # 构造函数的:前面是否有空格
  245. SpaceBeforeCtorInitializerColon: true
  246. # 继承的:前面是否有空格
  247. SpaceBeforeInheritanceColon: true
  248. # 函数调用时括号前添加空格
  249. # SpaceBeforeParentheses: true
  250. # 括号内部添加空格
  251. SpacesInParentheses: false
  252. # 范围的for循环冒号之前删除空格
  253. SpaceBeforeRangeBasedForLoopColon: true
  254. SpaceInEmptyBlock: false
  255. SpaceInEmptyParentheses: false
  256. # 尾部//注释之前的空格
  257. SpacesBeforeTrailingComments: 1
  258. SpacesInAngles: false
  259. SpacesInConditionalStatement: false
  260. SpacesInContainerLiterals: true
  261. SpacesInCStyleCastParentheses: false
  262. SpacesInSquareBrackets: false
  263. # 不在[前添加空格
  264. SpaceBeforeSquareBrackets: false
  265. # 单独控制不同情况下括号前面的空格,在SpaceBeforeParens==Custom时生效
  266. SpaceBeforeParensOptions:
  267. AfterControlStatements: true
  268. AfterForeachMacros: true
  269. AfterFunctionDefinitionName: false
  270. AfterFunctionDeclarationName: false
  271. AfterIfMacros: true
  272. AfterOverloadedOperator: true
  273. AfterRequiresInClause: true
  274. AfterRequiresInExpression: true
  275. BeforeNonEmptyParentheses: true
  276. # 位域:每边都添加空格
  277. BitFieldColonSpacing: Both
  278. # 标准 解析和格式化与此标准兼容的c++结构
  279. Standard: Latest
  280. # 在语句前面被忽略的宏定义,就好像它们是一个属性一样
  281. StatementAttributeLikeMacros:
  282. - Q_EMIT
  283. # 应该被解释为完整语句的宏定义
  284. StatementMacros:
  285. - Q_UNUSED
  286. - QT_REQUIRE_VERSION
  287. - Q_CLASSINFO
  288. - Q_ENUM
  289. - Q_ENUM_NS
  290. - Q_FLAG
  291. - Q_FLAG_NS
  292. - Q_GADGET
  293. - Q_GADGET_EXPORT
  294. - Q_INTERFACES
  295. - Q_MOC_INCLUDE
  296. - Q_NAMESPACE
  297. - Q_NAMESPACE_EXPORT
  298. - Q_OBJECT
  299. - Q_PROPERTY
  300. - Q_REVISION
  301. - Q_DISABLE_COPY
  302. - Q_SET_OBJECT_NAME
  303. - QT_BEGIN_NAMESPACE
  304. - QT_END_NAMESPACE
  305. - QML_ADDED_IN_MINOR_VERSION
  306. - QML_ANONYMOUS
  307. - QML_ATTACHED
  308. - QML_DECLARE_TYPE
  309. - QML_DECLARE_TYPEINFO
  310. - QML_ELEMENT
  311. - QML_EXTENDED
  312. - QML_EXTENDED_NAMESPACE
  313. - QML_EXTRA_VERSION
  314. - QML_FOREIGN
  315. - QML_FOREIGN_NAMESPACE
  316. - QML_IMPLEMENTS_INTERFACES
  317. - QML_INTERFACE
  318. - QML_NAMED_ELEMENT
  319. - QML_REMOVED_IN_MINOR_VERSION
  320. - QML_SINGLETON
  321. - QML_UNAVAILABLE
  322. - QML_UNCREATABLE
  323. - QML_VALUE_TYPE
  324. # tab宽度
  325. TabWidth: 4
  326. # 使用\n换行
  327. UseCRLF: false
  328. # 使用tab字符:ForIndentation——仅将制表符用于缩进
  329. UseTab: Never
  330. # 对空格敏感的宏定义
  331. WhitespaceSensitiveMacros:
  332. - STRINGIZE
  333. - PP_STRINGIZE
  334. - BOOST_PP_STRINGIZE
  335. - NS_SWIFT_NAME
  336. - CF_SWIFT_NAME
  337. ---