加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
.clang-format 6.71 KB
一键复制 编辑 原始数据 按行查看 历史
# SPDX-License-Identifier: Apache-2.0
#
# clang-format version is 20.0.0
#
# For more information, see:
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
#
---
# 应用于c、c++文件。目前的配置前都是针对C语言的
Language: Cpp
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
# 连续赋值时对齐等号
AlignConsecutiveAssignments: true
# 连续声明时对齐变量名
AlignConsecutiveDeclarations: true
# 行尾'\'符左对齐
AlignEscapedNewlines: Left
# 换行时操作数垂直对齐
AlignOperands: true
# 多行连续代码存在行尾注释时(//),注释对齐
AlignTrailingComments:
Kind: Always
OverEmptyLines: 2
# 函数参数列表过长时,不允许从第一个参数开始换行
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
# 'case xxx:'条件后必须换行
AllowShortCaseLabelsOnASingleLine: false
# 除了空函数外,函数名、函数体不允许写在同一行
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakBeforeMultilineStrings: false
# 如果设成false,调用函数时如果参数列表需要换行,必须一行一个
BinPackArguments: true
# 函数定义、声明时,允许参数列表换行,不需要一行一个
BinPackParameters: BinPack
# 采用BraceWrapping定义的括号换行方式
BreakBeforeBraces: Custom
BraceWrapping:
# 条件分支(if-else、do-while、switch-case、for,花括号不换行)
AfterControlStatement: Never
# 定义枚举类型,花括号不换行
AfterEnum: false
# 定义函数,花括号换行
AfterFunction: true
# 定义结构体,花括号不换行
AfterStruct: false
# 定义Union类型,花括号不换行
AfterUnion: false
# extern "C"之后花括号不换行
AfterExternBlock: false
# else分支花括号不换行
BeforeElse: false
# 花括号换行后不增加缩进
IndentBraces: false
# 空函数体的花括号不用换行
SplitEmptyFunction: false
# 空的结构体、Union等定义,花括号不用换行
SplitEmptyRecord: false
# 根据PenaltyReturnTypeOnItsOwnLine决定函数声明返回类型后是否换行
BreakAfterReturnType: Automatic
# 语句超过一行时,在操作符之后换行。即操作符保留在上一行
BreakBeforeBinaryOperators: None
# 使用三目操作符的语句换行时,在三目操作符之后换行(?和:后)
BreakBeforeTernaryOperators: false
# 字符串常量不能拆分,例如,下边这种是不允许的:
# const char* x = "veryVeryVeryVeryVeryVe"
# "ryVeryVeryVeryVeryVery"
# "VeryLongString";
BreakStringLiterals: false
# 每行不超过80字符
ColumnLimit: 80
# 正则匹配到的注释不能换行断开。
# iwyu是一个include依赖管理工具,后续可能引入,暂时保留配置
# https://github.com/include-what-you-use/include-what-you-use/blob/master/README.md
CommentPragmas: '^ IWYU pragma:'
ContinuationIndentWidth: 4
# 花括号包围的字段列表,与花括号之前插一个空格,比如:new int[3]{ 1, 2, 3 };
Cpp11BracedListStyle: false
# 用PointerAlignment决定指针怎么对齐
DerivePointerAlignment: false
DisableFormat: false
ExperimentalAutoDetectBinPacking: false
# Taken from:
# git grep -h -E '^#define [^[:space:]]*for(_)?each[^[:space:]]*\(' include/ arch/ drivers/ lib/ plat/ \
# | sed "s,^#define \([^[:space:]]*for\(_\)\?each[^[:space:]]*\)(.*$, - '\1'," \
# | LC_ALL=C sort -u
ForEachMacros:
- '_runq_foreach_safe'
- '_waitq_foreach_safe'
- 'fdt_for_each_property_offset'
- 'fdt_for_each_subnode'
- 'for_each_fs'
- 'lcpu_lcpuid_list_foreach'
- 'nf_excpttab_foreach'
- 'tn_entrytab_foreach'
- 'uk_alloc_foreach'
- 'uk_alloc_foreach_libstats'
- 'uk_ctortab_foreach'
- 'uk_event_handler_foreach'
- 'uk_for_each_set_bit'
- 'uk_inittab_foreach'
- 'uk_inittab_foreach_reverse'
- 'uk_inittab_foreach_reverse2'
- 'uk_libinfo_hdr_foreach'
- 'uk_libinfo_rec_foreach'
- 'uk_list_for_each_entry'
- 'uk_list_for_each_entry_safe'
- 'uk_posix_clonetab_foreach'
- 'uk_posix_clonetab_foreach_reverse'
- 'uk_posix_clonetab_foreach_reverse2'
- 'uk_sched_foreach_thread'
- 'uk_sched_foreach_thread_safe'
- 'uk_test_assert_foreach'
- 'uk_testsuite_case_foreach'
- 'uk_thread_inittab_foreach'
- 'uk_thread_inittab_foreach_reverse'
- 'uk_thread_inittab_foreach_reverse2'
- 'ukplat_memregion_foreach'
# include自动排序,配合IncludeCategories使用,保证<>形式和""形式的头文件分别排序,两部分用空行隔开。
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '<[[:alnum:]_]+\.h>'
Priority: 1
SortPriority: 1
- Regex: '<(uk|tn)/[[:alnum:]_/]+\.h>'
Priority: 2
SortPriority: 2
- Regex: '"[[:alnum:]_]+\.h"'
Priority: 3
SortPriority: 3
# case语句不缩进
IndentCaseLabels: false
# goto语句不缩进
IndentGotoLabels: false
# 预编译指令不缩进。如果缩进的话,会导致预处理后的文件缩进奇怪,比如下边的例子:
# #if FOO
# #if BAR
# #include <foo>
# #endif
# #endif
IndentPPDirectives: None
# 缩进字符数
IndentWidth: 4
# 函数声明、定义在return type后换行,函数名不缩进
IndentWrappedFunctionNames: false
# 文件结尾追加空行
KeepEmptyLines:
AtEndOfFile: true
AtStartOfBlock: false
AtStartOfFile: false
LineEnding: LF
MacroBlockBegin: ''
MacroBlockEnd: ''
# 不允许连续空行,最多一行
MaxEmptyLinesToKeep: 1
# Taken from git's rules
PenaltyBreakAssignment: 10
PenaltyBreakBeforeFirstCallParameter: 30
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyExcessCharacter: 100
# 超过60字符后在函数声明return type之后换行
PenaltyReturnTypeOnItsOwnLine: 60
# 指针的*挨着变量名
PointerAlignment: Right
# 暂时配成注释自动换行,如果对API注释等影响较大,改回false
ReflowComments: true
# 删除多余不必要的花括号
RemoveBracesLLVM: true
# include排序时不区分大小写
SortIncludes: CaseInsensitive
# 类型强转时,类型和变量名之间不加空格
SpaceAfterCStyleCast: false
# =、+=等赋值符前边加空格
SpaceBeforeAssignmentOperators: true
# 除了ForEachMacros外,其他场景需要在括号前加空格。也就是说把foreach宏当成函数调用,不加空格
# 而if等逻辑判断,keyword和括号之间加空格
SpaceBeforeParens: ControlStatementsExceptForEachMacros
SpacesInParens: Custom
# 括号里不加空格
SpacesInParensOptions:
InEmptyParentheses: false
InCStyleCasts: false
InConditionalStatements: false
Other: false
# 行尾注释//后加1个空格
SpacesBeforeTrailingComments: 1
# 方括号里不加空格
SpacesInSquareBrackets: false
TabWidth: 4
# 用tab缩进,需要对齐时补空格
UseTab: Always
...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化