---
# clang-format 代码格式化配置
# 基于 Google 风格,针对项目约定进行定制
# 修改此文件后,建议对项目代码运行 clang-format 验证格式化结果
BasedOnStyle: Google
# --- 缩进与行宽 ---
IndentWidth: 4 # 缩进4空格(Google默认2)
TabWidth: 4
UseTab: Never
ColumnLimit: 120 # 行宽上限120字符(Google默认80)
ContinuationIndentWidth: 4
ConstructorInitializerIndentWidth: 4
AccessModifierOffset: -4 # public/private等相对类体缩进-4,使其与class关键字对齐
# --- 大括号风格 ---
# 混合风格:函数定义大括号另起一行(Allman),其余大括号不换行(K&R)
BreakBeforeBraces: Custom
BraceWrapping:
AfterFunction: true # 函数定义大括号另起一行
AfterClass: false # 类定义大括号不换行
AfterControlStatement: Never # 控制语句大括号不换行
AfterEnum: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
AfterExternBlock: false
AfterObjCDeclaration: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
# --- 短语句风格 ---
AllowShortBlocksOnASingleLine: Empty # 仅空块可放在同一行
AllowShortFunctionsOnASingleLine: Empty # 仅空函数体可放在同一行
AllowShortLambdasOnASingleLine: Inline # 仅内联lambda可放在同一行
AllowShortCaseLabelsOnASingleLine: false
AllowShortIfStatementsOnASingleLine: Never # 不允许短if单行
AllowShortLoopsOnASingleLine: false
AllowShortEnumsOnASingleLine: false
# --- 对齐 ---
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true
# --- 换行策略 ---
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: Yes
BinPackArguments: true # 函数实参可以混合换行
BinPackParameters: true # 函数形参可以混合换行
BreakBeforeBinaryOperators: None
BreakBeforeInheritanceComma: false
BreakInheritanceList: BeforeComma # 继承列表在逗号前换行
BreakBeforeTernaryOperators: false # 三元运算符在操作符后换行
BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
# --- 指针与引用对齐 ---
PointerAlignment: Right # 指针*靠近变量名: Type *name
DerivePointerAlignment: false # 不自动推导对齐方式
# --- Include 管理 ---
IncludeBlocks: Preserve # 保持include块原样,不自动重排
SortIncludes: true # 不自动排序include,避免破坏依赖顺序
SortUsingDeclarations: true # 不自动排序using声明
IncludeCategories:
- Regex: '<.*\.h>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '^"rack_def\.h"'
Priority: 3
- Regex: '^"rack_.*\.h"'
Priority: 4
- Regex: '.*'
Priority: 5
IncludeIsMainRegex: '([-_](test|benchmark))?$'
# --- 空格风格 ---
Cpp11BracedListStyle: true # 花括号列表内不加多余空格
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements # 控制语句括号前加空格
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
# --- 注释与命名空间 ---
CommentPragmas: '^ NOLINT'
ReflowComments: false # 不重排注释
FixNamespaceComments: true # 自动修复命名空间结束注释
NamespaceIndentation: None # 命名空间内不额外缩进
CompactNamespaces: false
# --- C++标准 ---
Standard: c++17
# --- 其他 ---
ConstructorInitializerAllOnOneLineOrOnePerLine: true
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
KeepEmptyLinesAtTheStartOfBlocks: false
MaxEmptyLinesToKeep: 1
IndentCaseLabels: true
IndentPPDirectives: None
IndentWrappedFunctionNames: false
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
MacroBlockBegin: '[A-Z_]+_BEGIN\(.*\)$'
MacroBlockEnd: '.[A-Z_]+_END\(.*\)$'
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 2
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyBreakTemplateDeclaration: 10
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 120
RawStringFormats:
- Language: Cpp
Delimiters:
- cc
- CC
- cpp
- Cpp
- CPP
- 'c++'
- 'C++'
CanonicalDelimiter: ''
BasedOnStyle: google
- Language: TextProto
Delimiters:
- pb
- PB
- proto
- PROTO
EnclosingFunctions:
- EqualsProto
- EquivToProto
- PARSE_PARTIAL_TEXT_PROTO
- PARSE_TEST_PROTO
- PARSE_TEXT_PROTO
- ParseTextOrDie
- ParseTextProtoOrDie
CanonicalDelimiter: ''
BasedOnStyle: google
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION