Clang-Format Style Options¶
Clang 格式样式选项 ¶
Clang-Format Style Options describes configurable formatting style options
supported by LibFormat and ClangFormat.
Clang-Format Style Options 描述了 LibFormat 和 ClangFormat 支持的可配置格式化样式选项。
When using clang-format command line utility or
clang::format::reformat(...)
functions from code, one can either use one of
the predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft) or
create a custom style by configuring specific style options.
当使用 clang-format 命令行实用程序或代码中的 clang::format::reformat(...)
函数时,可以使用预定义样式之一(LLVM、Google、Chromium、Mozilla、WebKit、Microsoft),也可以通过配置特定样式来创建自定义样式风格选项。
Configuring Style with clang-format¶
使用 clang-format 配置样式 ¶
clang-format supports two ways to provide custom style options:
directly specify style configuration in the -style=
command line option or
use -style=file
and put style configuration in the .clang-format
or
_clang-format
file in the project directory.
clang-format 支持两种方式提供自定义样式选项:直接在 -style=
命令行选项中指定样式配置或使用 -style=file
并将样式配置放在 .clang-format
中或项目目录中的 _clang-format
文件。
When using -style=file
, clang-format for each input file will
try to find the .clang-format
file located in the closest parent directory
of the input file. When the standard input is used, the search is started from
the current directory.
使用 -style=file
时,每个输入文件的 clang-format 将尝试查找位于输入文件最近的父目录中的 .clang-format
文件。使用标准输入时,从当前目录开始搜索。
When using -style=file:<format_file_path>
, clang-format for
each input file will use the format file located at <format_file_path>.
The path may be absolute or relative to the working directory.
使用 -style=file:<format_file_path>
时,每个输入文件的 clang-format 将使用位于 的格式文件。该路径可以是绝对路径或相对于工作目录的路径。
The .clang-format
file uses YAML format:
.clang-format
文件使用 YAML 格式:
key1: value1
key2: value2
# A comment.
...
The configuration file can consist of several sections each having different
Language:
parameter denoting the programming language this section of the
configuration is targeted at. See the description of the Language option
below for the list of supported languages. The first section may have no
language set, it will set the default style options for all languages.
Configuration sections for specific language will override options set in the
default section.
配置文件可以由多个部分组成,每个部分具有不同的 Language:
参数,表示该配置部分针对的编程语言。有关支持的语言列表,请参阅下面的语言选项的说明。第一部分可能没有设置语言,它将设置所有语言的默认样式选项。特定语言的配置部分将覆盖默认部分中设置的选项。
When clang-format formats a file, it auto-detects the language using
the file name. When formatting standard input or a file that doesn’t have the
extension corresponding to its language, -assume-filename=
option can be
used to override the file name clang-format uses to detect the
language.
当 clang-format 格式化文件时,它会使用文件名自动检测语言。当格式化标准输入或没有与其语言对应的扩展名的文件时, -assume-filename=
选项可用于覆盖 clang-format 用于检测语言的文件名。
An example of a configuration file for multiple languages:
多种语言的配置文件示例:
---
# We'll use defaults from the LLVM style, but with 4 columns indentation.
BasedOnStyle: LLVM
IndentWidth: 4
---
Language: Cpp
# Force pointers to the type for C++.
DerivePointerAlignment: false
PointerAlignment: Left
---
Language: JavaScript
# Use 100 columns for JS.
ColumnLimit: 100
---
Language: Proto
# Don't format .proto files.
DisableFormat: true
---
Language: CSharp
# Use 100 columns for C#.
ColumnLimit: 100
...
An easy way to get a valid .clang-format
file containing all configuration
options of a certain predefined style is:
获取包含特定预定义样式的所有配置选项的有效 .clang-format
文件的简单方法是:
clang-format -style=llvm -dump-config > .clang-format
When specifying configuration in the -style=
option, the same configuration
is applied for all input files. The format of the configuration is:
在 -style=
选项中指定配置时,相同的配置将应用于所有输入文件。配置的格式为:
-style='{key1: value1, key2: value2, ...}'
Disabling Formatting on a Piece of Code¶
禁用一段代码的格式化 ¶
Clang-format understands also special comments that switch formatting in a
delimited range. The code between a comment // clang-format off
or
/* clang-format off */
up to a comment // clang-format on
or
/* clang-format on */
will not be formatted. The comments themselves will be
formatted (aligned) normally. Also, a colon (:
) and additional text may
follow // clang-format off
or // clang-format on
to explain why
clang-format is turned off or back on.
Clang-format 还理解在分隔范围内切换格式的特殊注释。注释 // clang-format off
或 /* clang-format off */
到注释 // clang-format on
或 /* clang-format on */
之间的代码不会被格式化。注释本身将正常格式化(对齐)。此外,冒号 ( :
) 和附加文本可能会跟在 // clang-format off
或 // clang-format on
后面,以解释关闭或重新打开 clang-format 的原因。
int formatted_code;
// clang-format off
void unformatted_code ;
// clang-format on
void formatted_code_again;
Configuring Style in Code¶
在代码中配置样式 ¶
When using clang::format::reformat(...)
functions, the format is specified
by supplying the clang::format::FormatStyle
structure.
使用 clang::format::reformat(...)
函数时,通过提供 clang::format::FormatStyle 结构来指定格式。
Configurable Format Style Options¶
可配置的格式样式选项 ¶
This section lists the supported style options. Value type is specified for
each option. For enumeration types possible values are specified both as a C++
enumeration member (with a prefix, e.g. LS_Auto
), and as a value usable in
the configuration (without a prefix: Auto
).
本节列出了支持的样式选项。为每个选项指定值类型。对于枚举类型,可能的值既指定为 C++ 枚举成员(带前缀,例如 LS_Auto
),也指定为配置中可用的值(不带前缀: Auto
)。
- BasedOnStyle (
String
) ¶
基于样式 (String
) ¶ The style used for all options not specifically set in the configuration.
用于配置中未专门设置的所有选项的样式。This option is supported only in the clang-format configuration (both within
-style='{...}'
and the.clang-format
file).
此选项仅在 clang-format 配置中受支持(在-style='{...}'
和.clang-format
文件中)。Possible values: 可能的值:
LLVM
A style complying with the LLVM coding standards
LLVM
符合LLVM编码标准的风格Google
A style complying with Google’s C++ style guide
Google
符合 Google C++ 风格指南的风格Chromium
A style complying with Chromium’s style guide
Chromium
符合 Chromium 风格指南的风格Mozilla
A style complying with Mozilla’s style guide
Mozilla
符合 Mozilla 风格指南的风格WebKit
A style complying with WebKit’s style guide
WebKit
符合WebKit风格指南的风格Microsoft
A style complying with Microsoft’s style guide
Microsoft
符合微软风格指南的风格GNU
A style complying with the GNU coding standards
GNU
符合GNU编码标准的风格InheritParentConfig
Not a real style, but allows to use the.clang-format
file from the parent directory (or its parent if there is none). If there is no parent file found it falls back to thefallback
style, and applies the changes to that.
InheritParentConfig
不是真正的样式,但允许使用父目录(或其父目录,如果没有)中的.clang-format
文件。如果没有找到父文件,它将回退到fallback
样式,并将更改应用于该样式。With this option you can overwrite some parts of your main style for your subdirectories. This is also possible through the command line, e.g.:
--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}
使用此选项,您可以覆盖子目录的主要样式的某些部分。这也可以通过命令行实现,例如:--style={BasedOnStyle: InheritParentConfig, ColumnLimit: 20}
- AccessModifierOffset (
Integer
) clang-format 3.3 ¶ The extra indent or outdent of access modifiers, e.g.
public:
.
访问修饰符的额外缩进或减少,例如public:
。
- AlignAfterOpenBracket (
BracketAlignmentStyle
) clang-format 3.8 ¶ If
true
, horizontally aligns arguments after an open bracket.
如果true
,则在左括号后水平对齐参数。This applies to round brackets (parentheses), angle brackets and square brackets.
这适用于圆括号(括号)、尖括号和方括号。Possible values: 可能的值:
BAS_Align
(in configuration:Align
) Align parameters on the open bracket, e.g.:
BAS_Align
(配置中:Align
)在左括号上对齐参数,例如:someLongFunction(argument1, argument2);
BAS_DontAlign
(in configuration:DontAlign
) Don’t align, instead useContinuationIndentWidth
, e.g.:
BAS_DontAlign
(在配置中:DontAlign
)不要对齐,而是使用ContinuationIndentWidth
,例如:someLongFunction(argument1, argument2);
BAS_AlwaysBreak
(in configuration:AlwaysBreak
) Always break after an open bracket, if the parameters don’t fit on a single line, e.g.:
BAS_AlwaysBreak
(在配置中:AlwaysBreak
)如果参数不能放在一行上,则始终在开括号后断开,例如:someLongFunction( argument1, argument2);
BAS_BlockIndent
(in configuration:BlockIndent
) Always break after an open bracket, if the parameters don’t fit on a single line. Closing brackets will be placed on a new line. E.g.:
BAS_BlockIndent
(在配置中:BlockIndent
)如果参数不能放在一行中,则始终在左括号后断开。右括号将放置在新行上。例如。:someLongFunction( argument1, argument2 )
Note 笔记
This currently only applies to braced initializer lists (when
Cpp11BracedListStyle
istrue
) and parentheses.
目前,这仅适用于花括号初始化列表(当Cpp11BracedListStyle
为true
时)和括号。
- AlignArrayOfStructures (
ArrayInitializerAlignmentStyle
) clang-format 13 ¶ if not
None
, when using initialization for an array of structs aligns the fields into columns.
如果不是None
,则在对结构数组使用初始化时会将字段对齐到列中。Note 笔记
As of clang-format 15 this option only applied to arrays with equal number of columns per row.
从 clang-format 15 开始,此选项仅适用于每行列数相同的数组。Possible values: 可能的值:
AIAS_Left
(in configuration:Left
) Align array column and left justify the columns e.g.:
AIAS_Left
(在配置中:Left
)对齐数组列并将列左对齐,例如:struct test demo[] = { {56, 23, "hello"}, {-1, 93463, "world"}, {7, 5, "!!" } };
AIAS_Right
(in configuration:Right
) Align array column and right justify the columns e.g.:
AIAS_Right
(在配置中:Right
)对齐数组列并将列右对齐,例如:struct test demo[] = { {56, 23, "hello"}, {-1, 93463, "world"}, { 7, 5, "!!"} };
AIAS_None
(in configuration:None
) Don’t align array initializer columns.
AIAS_None
(在配置中:None
)不要对齐数组初始值设定项列。
- AlignConsecutiveAssignments (
AlignConsecutiveStyle
) clang-format 3.8 ¶ Style of aligning consecutive assignments.
对齐连续作业的风格。Consecutive
will result in formattings like:
Consecutive
将导致如下格式:int a = 1; int somelongname = 2; double c = 3;
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
They can also be read as a whole for compatibility. The choices are: - None - Consecutive - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndComments
为了兼容性,它们也可以作为一个整体来阅读。选项包括: - 无 - 连续 - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndCommentsFor example, to align across empty lines and not across comments, either of these work.
例如,要跨空行对齐而不是跨注释对齐,这两种方法都可以。AlignConsecutiveAssignments: AcrossEmptyLines AlignConsecutiveAssignments: Enabled: true AcrossEmptyLines: true AcrossComments: false
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z) int a = 1; int somelongname = 2; double c = 3; int aaaa : 1; int b : 12; int ccc : 8; int aaaa = 12; float b = 23; std::string ccc;
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: int a = 1; int somelongname = 2; double c = 3; int d = 3; false: int a = 1; int somelongname = 2; double c = 3; int d = 3;
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: int d = 3; /* A comment. */ double e = 4; false: int d = 3; /* A comment. */ double e = 4;
bool AlignCompound
Only forAlignConsecutiveAssignments
. Whether compound assignments like+=
are aligned along with=
.
bool AlignCompound
仅适用于AlignConsecutiveAssignments
。像+=
这样的复合赋值是否与=
对齐。true: a &= 2; bbb = 2; false: a &= 2; bbb = 2;
bool AlignFunctionPointers
Only forAlignConsecutiveDeclarations
. Whether function pointers are aligned.
bool AlignFunctionPointers
仅适用于AlignConsecutiveDeclarations
。函数指针是否对齐。true: unsigned i; int &r; int *p; int (*f)(); false: unsigned i; int &r; int *p; int (*f)();
bool PadOperators
Only forAlignConsecutiveAssignments
. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side.
bool PadOperators
仅适用于AlignConsecutiveAssignments
。短赋值运算符是否向左填充到与长赋值运算符相同的长度,以便将所有赋值运算符放在左侧的右侧。true: a >>= 2; bbb = 2; a = 2; bbb >>= 2; false: a >>= 2; bbb = 2; a = 2; bbb >>= 2;
- AlignConsecutiveBitFields (
AlignConsecutiveStyle
) clang-format 11 ¶ Style of aligning consecutive bit fields.
对齐连续位字段的样式。Consecutive
will align the bitfield separators of consecutive lines. This will result in formattings like:
Consecutive
将对齐连续行的位域分隔符。这将导致如下格式:int aaaa : 1; int b : 12; int ccc : 8;
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
They can also be read as a whole for compatibility. The choices are: - None - Consecutive - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndComments
为了兼容性,它们也可以作为一个整体来阅读。选项包括: - 无 - 连续 - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndCommentsFor example, to align across empty lines and not across comments, either of these work.
例如,要跨空行对齐而不是跨注释对齐,这两种方法都可以。AlignConsecutiveBitFields: AcrossEmptyLines AlignConsecutiveBitFields: Enabled: true AcrossEmptyLines: true AcrossComments: false
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z) int a = 1; int somelongname = 2; double c = 3; int aaaa : 1; int b : 12; int ccc : 8; int aaaa = 12; float b = 23; std::string ccc;
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: int a = 1; int somelongname = 2; double c = 3; int d = 3; false: int a = 1; int somelongname = 2; double c = 3; int d = 3;
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: int d = 3; /* A comment. */ double e = 4; false: int d = 3; /* A comment. */ double e = 4;
bool AlignCompound
Only forAlignConsecutiveAssignments
. Whether compound assignments like+=
are aligned along with=
.
bool AlignCompound
仅适用于AlignConsecutiveAssignments
。像+=
这样的复合赋值是否与=
对齐。true: a &= 2; bbb = 2; false: a &= 2; bbb = 2;
bool AlignFunctionPointers
Only forAlignConsecutiveDeclarations
. Whether function pointers are aligned.
bool AlignFunctionPointers
仅适用于AlignConsecutiveDeclarations
。函数指针是否对齐。true: unsigned i; int &r; int *p; int (*f)(); false: unsigned i; int &r; int *p; int (*f)();
bool PadOperators
Only forAlignConsecutiveAssignments
. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side.
bool PadOperators
仅适用于AlignConsecutiveAssignments
。短赋值运算符是否向左填充到与长赋值运算符相同的长度,以便将所有赋值运算符放在左侧的右侧。true: a >>= 2; bbb = 2; a = 2; bbb >>= 2; false: a >>= 2; bbb = 2; a = 2; bbb >>= 2;
- AlignConsecutiveDeclarations (
AlignConsecutiveStyle
) clang-format 3.8 ¶ Style of aligning consecutive declarations.
对齐连续声明的样式。Consecutive
will align the declaration names of consecutive lines. This will result in formattings like:
Consecutive
将对齐连续行的声明名称。这将导致如下格式:int aaaa = 12; float b = 23; std::string ccc;
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
They can also be read as a whole for compatibility. The choices are: - None - Consecutive - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndComments
为了兼容性,它们也可以作为一个整体来阅读。选项包括: - 无 - 连续 - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndCommentsFor example, to align across empty lines and not across comments, either of these work.
例如,要跨空行对齐而不是跨注释对齐,这两种方法都可以。AlignConsecutiveDeclarations: AcrossEmptyLines AlignConsecutiveDeclarations: Enabled: true AcrossEmptyLines: true AcrossComments: false
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z) int a = 1; int somelongname = 2; double c = 3; int aaaa : 1; int b : 12; int ccc : 8; int aaaa = 12; float b = 23; std::string ccc;
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: int a = 1; int somelongname = 2; double c = 3; int d = 3; false: int a = 1; int somelongname = 2; double c = 3; int d = 3;
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: int d = 3; /* A comment. */ double e = 4; false: int d = 3; /* A comment. */ double e = 4;
bool AlignCompound
Only forAlignConsecutiveAssignments
. Whether compound assignments like+=
are aligned along with=
.
bool AlignCompound
仅适用于AlignConsecutiveAssignments
。像+=
这样的复合赋值是否与=
对齐。true: a &= 2; bbb = 2; false: a &= 2; bbb = 2;
bool AlignFunctionPointers
Only forAlignConsecutiveDeclarations
. Whether function pointers are aligned.
bool AlignFunctionPointers
仅适用于AlignConsecutiveDeclarations
。函数指针是否对齐。true: unsigned i; int &r; int *p; int (*f)(); false: unsigned i; int &r; int *p; int (*f)();
bool PadOperators
Only forAlignConsecutiveAssignments
. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side.
bool PadOperators
仅适用于AlignConsecutiveAssignments
。短赋值运算符是否向左填充到与长赋值运算符相同的长度,以便将所有赋值运算符放在左侧的右侧。true: a >>= 2; bbb = 2; a = 2; bbb >>= 2; false: a >>= 2; bbb = 2; a = 2; bbb >>= 2;
- AlignConsecutiveMacros (
AlignConsecutiveStyle
) clang-format 9 ¶ Style of aligning consecutive macro definitions.
对齐连续宏定义的样式。Consecutive
will result in formattings like:
Consecutive
将导致如下格式:#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z)
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
They can also be read as a whole for compatibility. The choices are: - None - Consecutive - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndComments
为了兼容性,它们也可以作为一个整体来阅读。选项包括: - 无 - 连续 - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndCommentsFor example, to align across empty lines and not across comments, either of these work.
例如,要跨空行对齐而不是跨注释对齐,这两种方法都可以。AlignConsecutiveMacros: AcrossEmptyLines AlignConsecutiveMacros: Enabled: true AcrossEmptyLines: true AcrossComments: false
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z) int a = 1; int somelongname = 2; double c = 3; int aaaa : 1; int b : 12; int ccc : 8; int aaaa = 12; float b = 23; std::string ccc;
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: int a = 1; int somelongname = 2; double c = 3; int d = 3; false: int a = 1; int somelongname = 2; double c = 3; int d = 3;
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: int d = 3; /* A comment. */ double e = 4; false: int d = 3; /* A comment. */ double e = 4;
bool AlignCompound
Only forAlignConsecutiveAssignments
. Whether compound assignments like+=
are aligned along with=
.
bool AlignCompound
仅适用于AlignConsecutiveAssignments
。像+=
这样的复合赋值是否与=
对齐。true: a &= 2; bbb = 2; false: a &= 2; bbb = 2;
bool AlignFunctionPointers
Only forAlignConsecutiveDeclarations
. Whether function pointers are aligned.
bool AlignFunctionPointers
仅适用于AlignConsecutiveDeclarations
。函数指针是否对齐。true: unsigned i; int &r; int *p; int (*f)(); false: unsigned i; int &r; int *p; int (*f)();
bool PadOperators
Only forAlignConsecutiveAssignments
. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side.
bool PadOperators
仅适用于AlignConsecutiveAssignments
。短赋值运算符是否向左填充到与长赋值运算符相同的长度,以便将所有赋值运算符放在左侧的右侧。true: a >>= 2; bbb = 2; a = 2; bbb >>= 2; false: a >>= 2; bbb = 2; a = 2; bbb >>= 2;
- AlignConsecutiveShortCaseStatements (
ShortCaseStatementsAlignmentStyle
) clang-format 17 ¶ Style of aligning consecutive short case labels. Only applies if
AllowShortCaseExpressionOnASingleLine
orAllowShortCaseLabelsOnASingleLine
istrue
.
对齐连续短大小写标签的样式。仅当AllowShortCaseExpressionOnASingleLine
或AllowShortCaseLabelsOnASingleLine
为true
时适用。# Example of usage: AlignConsecutiveShortCaseStatements: Enabled: true AcrossEmptyLines: true AcrossComments: true AlignCaseColons: false
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。true: switch (level) { case log::info: return "info:"; case log::warning: return "warning:"; default: return ""; } false: switch (level) { case log::info: return "info:"; case log::warning: return "warning:"; default: return ""; }
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: switch (level) { case log::info: return "info:"; case log::warning: return "warning:"; default: return ""; } false: switch (level) { case log::info: return "info:"; case log::warning: return "warning:"; default: return ""; }
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: switch (level) { case log::info: return "info:"; case log::warning: return "warning:"; /* A comment. */ default: return ""; } false: switch (level) { case log::info: return "info:"; case log::warning: return "warning:"; /* A comment. */ default: return ""; }
bool AlignCaseArrows
Whether to align the case arrows when aligning short case expressions.
bool AlignCaseArrows
对齐短 case 表达式时是否对齐 case 箭头。true: i = switch (day) { case THURSDAY, SATURDAY -> 8; case WEDNESDAY -> 9; default -> 0; }; false: i = switch (day) { case THURSDAY, SATURDAY -> 8; case WEDNESDAY -> 9; default -> 0; };
bool AlignCaseColons
Whether aligned case labels are aligned on the colon, or on the tokens after the colon.
bool AlignCaseColons
对齐的大小写标签是在冒号上对齐,还是在冒号后面的标记上对齐。true: switch (level) { case log::info : return "info:"; case log::warning: return "warning:"; default : return ""; } false: switch (level) { case log::info: return "info:"; case log::warning: return "warning:"; default: return ""; }
- AlignConsecutiveTableGenBreakingDAGArgColons (
AlignConsecutiveStyle
) clang-format 19 ¶ Style of aligning consecutive TableGen DAGArg operator colons. If enabled, align the colon inside DAGArg which have line break inside. This works only when TableGenBreakInsideDAGArg is BreakElements or BreakAll and the DAGArg is not excepted by TableGenBreakingDAGArgOperators’s effect.
对齐连续 TableGen DAGArg 运算符冒号的样式。如果启用,请对齐 DAGArg 内的冒号,其中有换行符。仅当 TableGenBreakInsideDAGArg 为 BreakElements 或 BreakAll 且 DAGArg 不受 TableGenBreakingDAGArgOperators 的影响时才有效。let dagarg = (ins a :$src1, aa :$src2, aaa:$src3 )
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
They can also be read as a whole for compatibility. The choices are: - None - Consecutive - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndComments
为了兼容性,它们也可以作为一个整体来阅读。选项包括: - 无 - 连续 - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndCommentsFor example, to align across empty lines and not across comments, either of these work.
例如,要跨空行对齐而不是跨注释对齐,这两种方法都可以。AlignConsecutiveTableGenBreakingDAGArgColons: AcrossEmptyLines AlignConsecutiveTableGenBreakingDAGArgColons: Enabled: true AcrossEmptyLines: true AcrossComments: false
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z) int a = 1; int somelongname = 2; double c = 3; int aaaa : 1; int b : 12; int ccc : 8; int aaaa = 12; float b = 23; std::string ccc;
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: int a = 1; int somelongname = 2; double c = 3; int d = 3; false: int a = 1; int somelongname = 2; double c = 3; int d = 3;
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: int d = 3; /* A comment. */ double e = 4; false: int d = 3; /* A comment. */ double e = 4;
bool AlignCompound
Only forAlignConsecutiveAssignments
. Whether compound assignments like+=
are aligned along with=
.
bool AlignCompound
仅适用于AlignConsecutiveAssignments
。像+=
这样的复合赋值是否与=
对齐。true: a &= 2; bbb = 2; false: a &= 2; bbb = 2;
bool AlignFunctionPointers
Only forAlignConsecutiveDeclarations
. Whether function pointers are aligned.
bool AlignFunctionPointers
仅适用于AlignConsecutiveDeclarations
。函数指针是否对齐。true: unsigned i; int &r; int *p; int (*f)(); false: unsigned i; int &r; int *p; int (*f)();
bool PadOperators
Only forAlignConsecutiveAssignments
. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side.
bool PadOperators
仅适用于AlignConsecutiveAssignments
。短赋值运算符是否向左填充到与长赋值运算符相同的长度,以便将所有赋值运算符放在左侧的右侧。true: a >>= 2; bbb = 2; a = 2; bbb >>= 2; false: a >>= 2; bbb = 2; a = 2; bbb >>= 2;
- AlignConsecutiveTableGenCondOperatorColons (
AlignConsecutiveStyle
) clang-format 19 ¶ Style of aligning consecutive TableGen cond operator colons. Align the colons of cases inside !cond operators.
连续 TableGen cond 运算符冒号的对齐方式。对齐 !cond 运算符内 case 的冒号。!cond(!eq(size, 1) : 1, !eq(size, 16): 1, true : 0)
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
They can also be read as a whole for compatibility. The choices are: - None - Consecutive - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndComments
为了兼容性,它们也可以作为一个整体来阅读。选项包括: - 无 - 连续 - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndCommentsFor example, to align across empty lines and not across comments, either of these work.
例如,要跨空行对齐而不是跨注释对齐,这两种方法都可以。AlignConsecutiveTableGenCondOperatorColons: AcrossEmptyLines AlignConsecutiveTableGenCondOperatorColons: Enabled: true AcrossEmptyLines: true AcrossComments: false
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z) int a = 1; int somelongname = 2; double c = 3; int aaaa : 1; int b : 12; int ccc : 8; int aaaa = 12; float b = 23; std::string ccc;
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: int a = 1; int somelongname = 2; double c = 3; int d = 3; false: int a = 1; int somelongname = 2; double c = 3; int d = 3;
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: int d = 3; /* A comment. */ double e = 4; false: int d = 3; /* A comment. */ double e = 4;
bool AlignCompound
Only forAlignConsecutiveAssignments
. Whether compound assignments like+=
are aligned along with=
.
bool AlignCompound
仅适用于AlignConsecutiveAssignments
。像+=
这样的复合赋值是否与=
对齐。true: a &= 2; bbb = 2; false: a &= 2; bbb = 2;
bool AlignFunctionPointers
Only forAlignConsecutiveDeclarations
. Whether function pointers are aligned.
bool AlignFunctionPointers
仅适用于AlignConsecutiveDeclarations
。函数指针是否对齐。true: unsigned i; int &r; int *p; int (*f)(); false: unsigned i; int &r; int *p; int (*f)();
bool PadOperators
Only forAlignConsecutiveAssignments
. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side.
bool PadOperators
仅适用于AlignConsecutiveAssignments
。短赋值运算符是否向左填充到与长赋值运算符相同的长度,以便将所有赋值运算符放在左侧的右侧。true: a >>= 2; bbb = 2; a = 2; bbb >>= 2; false: a >>= 2; bbb = 2; a = 2; bbb >>= 2;
- AlignConsecutiveTableGenDefinitionColons (
AlignConsecutiveStyle
) clang-format 19 ¶ Style of aligning consecutive TableGen definition colons. This aligns the inheritance colons of consecutive definitions.
对齐连续 TableGen 定义冒号的样式。这会对齐连续定义的继承冒号。def Def : Parent {} def DefDef : Parent {} def DefDefDef : Parent {}
Nested configuration flags:
嵌套配置标志:Alignment options. 对齐选项。
They can also be read as a whole for compatibility. The choices are: - None - Consecutive - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndComments
为了兼容性,它们也可以作为一个整体来阅读。选项包括: - 无 - 连续 - AcrossEmptyLines - AcrossComments - AcrossEmptyLinesAndCommentsFor example, to align across empty lines and not across comments, either of these work.
例如,要跨空行对齐而不是跨注释对齐,这两种方法都可以。AlignConsecutiveTableGenDefinitionColons: AcrossEmptyLines AlignConsecutiveTableGenDefinitionColons: Enabled: true AcrossEmptyLines: true AcrossComments: false
bool Enabled
Whether aligning is enabled.
bool Enabled
是否启用对齐。#define SHORT_NAME 42 #define LONGER_NAME 0x007f #define EVEN_LONGER_NAME (2) #define foo(x) (x * x) #define bar(y, z) (y + z) int a = 1; int somelongname = 2; double c = 3; int aaaa : 1; int b : 12; int ccc : 8; int aaaa = 12; float b = 23; std::string ccc;
bool AcrossEmptyLines
Whether to align across empty lines.
bool AcrossEmptyLines
是否跨空行对齐。true: int a = 1; int somelongname = 2; double c = 3; int d = 3; false: int a = 1; int somelongname = 2; double c = 3; int d = 3;
bool AcrossComments
Whether to align across comments.
bool AcrossComments
是否跨注释对齐。true: int d = 3; /* A comment. */ double e = 4; false: int d = 3; /* A comment. */ double e = 4;
bool AlignCompound
Only forAlignConsecutiveAssignments
. Whether compound assignments like+=
are aligned along with=
.
bool AlignCompound
仅适用于AlignConsecutiveAssignments
。像+=
这样的复合赋值是否与=
对齐。true: a &= 2; bbb = 2; false: a &= 2; bbb = 2;
bool AlignFunctionPointers
Only forAlignConsecutiveDeclarations
. Whether function pointers are aligned.
bool AlignFunctionPointers
仅适用于AlignConsecutiveDeclarations
。函数指针是否对齐。true: unsigned i; int &r; int *p; int (*f)(); false: unsigned i; int &r; int *p; int (*f)();
bool PadOperators
Only forAlignConsecutiveAssignments
. Whether short assignment operators are left-padded to the same length as long ones in order to put all assignment operators to the right of the left hand side.
bool PadOperators
仅适用于AlignConsecutiveAssignments
。短赋值运算符是否向左填充到与长赋值运算符相同的长度,以便将所有赋值运算符放在左侧的右侧。true: a >>= 2; bbb = 2; a = 2; bbb >>= 2; false: a >>= 2; bbb = 2; a = 2; bbb >>= 2;
- AlignEscapedNewlines (
EscapedNewlineAlignmentStyle
) clang-format 5 ¶ Options for aligning backslashes in escaped newlines.
用于在转义换行符中对齐反斜杠的选项。Possible values: 可能的值:
ENAS_DontAlign
(in configuration:DontAlign
) Don’t align escaped newlines.
ENAS_DontAlign
(在配置中:DontAlign
)不要对齐转义换行符。#define A \ int aaaa; \ int b; \ int dddddddddd;
ENAS_Left
(in configuration:Left
) Align escaped newlines as far left as possible.
ENAS_Left
(在配置中:Left
)将转义换行符尽可能靠左对齐。true: #define A \ int aaaa; \ int b; \ int dddddddddd; false:
ENAS_Right
(in configuration:Right
) Align escaped newlines in the right-most column.
ENAS_Right
(在配置中:Right
)在最右列中对齐转义换行符。#define A \ int aaaa; \ int b; \ int dddddddddd;
- AlignOperands (
OperandAlignmentStyle
) clang-format 3.5 ¶ If
true
, horizontally align operands of binary and ternary expressions.
如果true
,则水平对齐二元和三元表达式的操作数。Possible values: 可能的值:
OAS_DontAlign
(in configuration:DontAlign
) Do not align operands of binary and ternary expressions. The wrapped lines are indentedContinuationIndentWidth
spaces from the start of the line.
OAS_DontAlign
(在配置中:DontAlign
)不要对齐二进制和三元表达式的操作数。换行是从行首缩进的ContinuationIndentWidth
空格。OAS_Align
(in configuration:Align
) Horizontally align operands of binary and ternary expressions.
OAS_Align
(在配置中:Align
)水平对齐二元和三元表达式的操作数。Specifically, this aligns operands of a single expression that needs to be split over multiple lines, e.g.:
具体来说,这会对齐需要拆分为多行的单个表达式的操作数,例如:int aaa = bbbbbbbbbbbbbbb + ccccccccccccccc;
When
BreakBeforeBinaryOperators
is set, the wrapped operator is aligned with the operand on the first line.
当BreakBeforeBinaryOperators
设置时,包装运算符与第一行的操作数对齐。int aaa = bbbbbbbbbbbbbbb + ccccccccccccccc;
OAS_AlignAfterOperator
(in configuration:AlignAfterOperator
) Horizontally align operands of binary and ternary expressions.
OAS_AlignAfterOperator
(在配置中:AlignAfterOperator
)水平对齐二元和三元表达式的操作数。This is similar to
AO_Align
, except whenBreakBeforeBinaryOperators
is set, the operator is un-indented so that the wrapped operand is aligned with the operand on the first line.
这与AO_Align
类似,但当设置BreakBeforeBinaryOperators
时,运算符不缩进,以便包装的操作数与第一行的操作数对齐。int aaa = bbbbbbbbbbbbbbb + ccccccccccccccc;
- AlignTrailingComments (
TrailingCommentsAlignmentStyle
) clang-format 3.7 ¶ Control of trailing comments.
控制尾随评论。The alignment stops at closing braces after a line break, and only followed by other closing braces, a (
do-
)while
, a lambda call, or a semicolon.
对齐在换行后的右大括号处停止,并且仅后跟其他右大括号、(do-
)while
、lambda 调用或分号。Note 笔记
As of clang-format 16 this option is not a bool but can be set to the options. Conventional bool options still can be parsed as before.
从 clang-format 16 开始,此选项不是布尔值,但可以设置为选项。传统的 bool 选项仍然可以像以前一样解析。# Example of usage: AlignTrailingComments: Kind: Always OverEmptyLines: 2
Nested configuration flags:
嵌套配置标志:Alignment options 对齐选项
TrailingCommentsAlignmentKinds Kind
Specifies the way to align trailing comments.
TrailingCommentsAlignmentKinds Kind
指定对齐尾随注释的方式。Possible values: 可能的值:
TCAS_Leave
(in configuration:Leave
) Leave trailing comments as they are.
TCAS_Leave
(在配置中:Leave
)保留尾随注释不变。int a; // comment int ab; // comment int abc; // comment int abcd; // comment
TCAS_Always
(in configuration:Always
) Align trailing comments.
TCAS_Always
(在配置中:Always
)对齐尾随注释。int a; // comment int ab; // comment int abc; // comment int abcd; // comment
TCAS_Never
(in configuration:Never
) Don’t align trailing comments but other formatter applies.
TCAS_Never
(在配置中:Never
)不要对齐尾随注释,但其他格式化程序适用。int a; // comment int ab; // comment int abc; // comment int abcd; // comment
unsigned OverEmptyLines
How many empty lines to apply alignment. When bothMaxEmptyLinesToKeep
andOverEmptyLines
are set to 2, it formats like below.
unsigned OverEmptyLines
应用对齐方式的空行数。当MaxEmptyLinesToKeep
和OverEmptyLines
都设置为 2 时,其格式如下。int a; // all these int ab; // comments are int abcdef; // aligned
When
MaxEmptyLinesToKeep
is set to 2 andOverEmptyLines
is set to 1, it formats like below.
当MaxEmptyLinesToKeep
设置为2并且OverEmptyLines
设置为1时,其格式如下。int a; // these are int ab; // aligned int abcdef; // but this isn't
- AllowAllArgumentsOnNextLine (
Boolean
) clang-format 9 ¶ If a function call or braced initializer list doesn’t fit on a line, allow putting all arguments onto the next line, even if
BinPackArguments
isfalse
.
如果函数调用或大括号初始化列表不适合一行,则允许将所有参数放入下一行,即使BinPackArguments
是false
。true: callFunction( a, b, c, d); false: callFunction(a, b, c, d);
- AllowAllConstructorInitializersOnNextLine (
Boolean
) clang-format 9 ¶ This option is deprecated. See
NextLine
ofPackConstructorInitializers
.
此选项已弃用。请参阅PackConstructorInitializers
的NextLine
。
- AllowAllParametersOfDeclarationOnNextLine (
Boolean
) clang-format 3.3 ¶ If the function declaration doesn’t fit on a line, allow putting all parameters of a function declaration onto the next line even if
BinPackParameters
isfalse
.
如果函数声明无法容纳在一行中,则允许将函数声明的所有参数放在下一行,即使BinPackParameters
是false
。true: void myFunction( int a, int b, int c, int d, int e); false: void myFunction(int a, int b, int c, int d, int e);
- AllowBreakBeforeNoexceptSpecifier (
BreakBeforeNoexceptSpecifierStyle
) clang-format 18 ¶
AllowBreakBeforeNo exceptSpecifier (BreakBeforeNoexceptSpecifierStyle
) clang 格式 18 ¶ Controls if there could be a line break before a
noexcept
specifier.
控制noexcept
说明符之前是否可以有换行符。Possible values: 可能的值:
BBNSS_Never
(in configuration:Never
) No line break allowed.
BBNSS_Never
(在配置中:Never
)不允许换行。void foo(int arg1, double arg2) noexcept; void bar(int arg1, double arg2) noexcept( noexcept(baz(arg1)) && noexcept(baz(arg2)));
BBNSS_OnlyWithParen
(in configuration:OnlyWithParen
) For a simplenoexcept
there is no line break allowed, but when we have a condition it is.
BBNSS_OnlyWithParen
(在配置中:OnlyWithParen
)对于简单的noexcept
不允许换行,但是当我们有条件时就可以。void foo(int arg1, double arg2) noexcept; void bar(int arg1, double arg2) noexcept(noexcept(baz(arg1)) && noexcept(baz(arg2)));
BBNSS_Always
(in configuration:Always
) Line breaks are allowed. But note that because of the associated penaltiesclang-format
often prefers not to break before thenoexcept
.
BBNSS_Always
(在配置中:Always
)允许换行。但请注意,由于相关的惩罚,clang-format
通常不愿意在noexcept
之前中断。void foo(int arg1, double arg2) noexcept; void bar(int arg1, double arg2) noexcept(noexcept(baz(arg1)) && noexcept(baz(arg2)));
- AllowShortBlocksOnASingleLine (
ShortBlockStyle
) clang-format 3.5 ¶ Dependent on the value,
while (true) { continue; }
can be put on a single line.
根据值的不同,while (true) { continue; }
可以放在一行上。Possible values: 可能的值:
SBS_Never
(in configuration:Never
) Never merge blocks into a single line.
SBS_Never
(在配置中:Never
)切勿将块合并到一行中。while (true) { } while (true) { continue; }
SBS_Empty
(in configuration:Empty
) Only merge empty blocks.
SBS_Empty
(在配置中:Empty
)仅合并空块。while (true) {} while (true) { continue; }
SBS_Always
(in configuration:Always
) Always merge short blocks into a single line.
SBS_Always
(在配置中:Always
)始终将短块合并为一行。while (true) {} while (true) { continue; }
- AllowShortCaseExpressionOnASingleLine (
Boolean
) clang-format 19 ¶
允许ShortCaseExpressionOnASingleLine (Boolean
) clang-format 19 ¶ Whether to merge a short switch labeled rule into a single line.
是否将短开关标记规则合并到单行中。true: false: switch (a) { vs. switch (a) { case 1 -> 1; case 1 -> default -> 0; 1; }; default -> 0; };
- AllowShortCaseLabelsOnASingleLine (
Boolean
) clang-format 3.6 ¶ If
true
, short case labels will be contracted to a single line.
如果true
,短大小写标签将收缩为一行。true: false: switch (a) { vs. switch (a) { case 1: x = 1; break; case 1: case 2: return; x = 1; } break; case 2: return; }
- AllowShortCompoundRequirementOnASingleLine (
Boolean
) clang-format 18 ¶ Allow short compound requirement on a single line.
允许单行上的短复合要求。true: template <typename T> concept c = requires(T x) { { x + 1 } -> std::same_as<int>; }; false: template <typename T> concept c = requires(T x) { { x + 1 } -> std::same_as<int>; };
- AllowShortEnumsOnASingleLine (
Boolean
) clang-format 11 ¶
AllowShortEnumsOnASingleLine (Boolean
) clang 格式 11 ¶ Allow short enums on a single line.
允许在单行上使用短枚举。true: enum { A, B } myEnum; false: enum { A, B } myEnum;
- AllowShortFunctionsOnASingleLine (
ShortFunctionStyle
) clang-format 3.5 ¶ Dependent on the value,
int f() { return 0; }
can be put on a single line.
根据值的不同,int f() { return 0; }
可以放在一行上。Possible values: 可能的值:
SFS_None
(in configuration:None
) Never merge functions into a single line.
SFS_None
(在配置中:None
)切勿将函数合并到一行中。SFS_InlineOnly
(in configuration:InlineOnly
) Only merge functions defined inside a class. Same as “inline”, except it does not implies “empty”: i.e. top level empty functions are not merged either.
SFS_InlineOnly
(在配置中:InlineOnly
)仅合并类内部定义的函数。与“内联”相同,但它并不意味着“空”:即顶级空函数也不会合并。class Foo { void f() { foo(); } }; void f() { foo(); } void f() { }
SFS_Empty
(in configuration:Empty
) Only merge empty functions.
SFS_Empty
(在配置中:Empty
)仅合并空函数。void f() {} void f2() { bar2(); }
SFS_Inline
(in configuration:Inline
) Only merge functions defined inside a class. Implies “empty”.
SFS_Inline
(在配置中:Inline
)仅合并类内部定义的函数。含“空”之意。class Foo { void f() { foo(); } }; void f() { foo(); } void f() {}
SFS_All
(in configuration:All
) Merge all functions fitting on a single line.
SFS_All
(在配置中:All
)合并所有适合单行的函数。class Foo { void f() { foo(); } }; void f() { bar(); }
- AllowShortIfStatementsOnASingleLine (
ShortIfStyle
) clang-format 3.3 ¶ Dependent on the value,
if (a) return;
can be put on a single line.
根据值的不同,if (a) return;
可以放在一行上。Possible values: 可能的值:
SIS_Never
(in configuration:Never
) Never put short ifs on the same line.
SIS_Never
(在配置中:Never
)切勿将短 if 放在同一行。if (a) return; if (b) return; else return; if (c) return; else { return; }
SIS_WithoutElse
(in configuration:WithoutElse
) Put short ifs on the same line only if there is no else statement.
SIS_WithoutElse
(在配置中:WithoutElse
)仅当没有 else 语句时才将短 if 放在同一行。if (a) return; if (b) return; else return; if (c) return; else { return; }
SIS_OnlyFirstIf
(in configuration:OnlyFirstIf
) Put short ifs, but not else ifs nor else statements, on the same line.
SIS_OnlyFirstIf
(在配置中:OnlyFirstIf
)将短 if 放在同一行,但不要放置 else if 或 else 语句。if (a) return; if (b) return; else if (b) return; else return; if (c) return; else { return; }
SIS_AllIfsAndElse
(in configuration:AllIfsAndElse
) Always put short ifs, else ifs and else statements on the same line.
SIS_AllIfsAndElse
(在配置中:AllIfsAndElse
)始终将短 if、else if 和 else 语句放在同一行。if (a) return; if (b) return; else return; if (c) return; else { return; }
- AllowShortLambdasOnASingleLine (
ShortLambdaStyle
) clang-format 9 ¶ Dependent on the value,
auto lambda []() { return 0; }
can be put on a single line.
根据值的不同,auto lambda []() { return 0; }
可以放在一行上。Possible values: 可能的值:
SLS_None
(in configuration:None
) Never merge lambdas into a single line.
SLS_None
(在配置中:None
)切勿将 lambda 合并到一行中。SLS_Empty
(in configuration:Empty
) Only merge empty lambdas.
SLS_Empty
(在配置中:Empty
)仅合并空 lambda。auto lambda = [](int a) {}; auto lambda2 = [](int a) { return a; };
SLS_Inline
(in configuration:Inline
) Merge lambda into a single line if the lambda is argument of a function.
SLS_Inline
(在配置中:Inline
)如果 lambda 是函数的参数,则将 lambda 合并到一行中。auto lambda = [](int x, int y) { return x < y; }; sort(a.begin(), a.end(), [](int x, int y) { return x < y; });
SLS_All
(in configuration:All
) Merge all lambdas fitting on a single line.
SLS_All
(在配置中:All
)合并所有适合单行的 lambda。auto lambda = [](int a) {}; auto lambda2 = [](int a) { return a; };
- AllowShortLoopsOnASingleLine (
Boolean
) clang-format 3.7 ¶ If
true
,while (true) continue;
can be put on a single line.
如果true
、while (true) continue;
可以放在一行中。
- AlwaysBreakAfterDefinitionReturnType (
DefinitionReturnTypeBreakingStyle
) clang-format 3.7 ¶ The function definition return type breaking style to use. This option is deprecated and is retained for backwards compatibility.
要使用的函数定义返回类型破坏样式。此选项已弃用,保留是为了向后兼容。Possible values: 可能的值:
DRTBS_None
(in configuration:None
) Break after return type automatically.PenaltyReturnTypeOnItsOwnLine
is taken into account.
DRTBS_None
(在配置中:None
)返回类型后自动中断。PenaltyReturnTypeOnItsOwnLine
被考虑在内。DRTBS_All
(in configuration:All
) Always break after the return type.
DRTBS_All
(在配置中:All
)始终在返回类型之后中断。DRTBS_TopLevel
(in configuration:TopLevel
) Always break after the return types of top-level functions.
DRTBS_TopLevel
(在配置中:TopLevel
)始终在顶级函数的返回类型之后中断。
- AlwaysBreakAfterReturnType (
deprecated
) clang-format 3.8 ¶
AlwaysBreakAfterReturnType (deprecated
) clang 格式 3.8 ¶ This option is renamed to
BreakAfterReturnType
.
该选项被重命名为BreakAfterReturnType
。
- AlwaysBreakBeforeMultilineStrings (
Boolean
) clang-format 3.4 ¶ If
true
, always break before multiline string literals.
如果true
,则始终在多行字符串文字之前中断。This flag is mean to make cases where there are multiple multiline strings in a file look more consistent. Thus, it will only take effect if wrapping the string at that point leads to it being indented
ContinuationIndentWidth
spaces from the start of the line.
该标志的目的是使文件中存在多个多行字符串的情况看起来更加一致。因此,只有在该点换行字符串导致从行首缩进ContinuationIndentWidth
空格时,它才会生效。true: false: aaaa = vs. aaaa = "bbbb" "bbbb" "cccc"; "cccc";
- AlwaysBreakTemplateDeclarations (
deprecated
) clang-format 3.4 ¶ This option is renamed to
BreakTemplateDeclarations
.
该选项被重命名为BreakTemplateDeclarations
。
- AttributeMacros (
List of Strings
) clang-format 12 ¶
属性宏 (List of Strings
) clang-format 12 ¶ A vector of strings that should be interpreted as attributes/qualifiers instead of identifiers. This can be useful for language extensions or static analyzer annotations.
应被解释为属性/限定符而不是标识符的字符串向量。这对于语言扩展或静态分析器注释非常有用。For example: 例如:
x = (char *__capability)&y; int function(void) __unused; void only_writes_to_buffer(char *__output buffer);
In the .clang-format configuration file, this can be configured like:
在 .clang-format 配置文件中,可以这样配置:AttributeMacros: ['__capability', '__output', '__unused']
- BinPackArguments (
Boolean
) clang-format 3.7 ¶ If
false
, a function call’s arguments will either be all on the same line or will have one line each.
如果false
,函数调用的参数要么全部在同一行,要么各占一行。true: void f() { f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); } false: void f() { f(aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa); }
- BinPackParameters (
Boolean
) clang-format 3.7 ¶ If
false
, a function declaration’s or function definition’s parameters will either all be on the same line or will have one line each.
如果false
,函数声明或函数定义的参数要么全部位于同一行,要么各占一行。true: void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {} false: void f(int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaa, int aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) {}
- BitFieldColonSpacing (
BitFieldColonSpacingStyle
) clang-format 12 ¶ The BitFieldColonSpacingStyle to use for bitfields.
用于位域的 BitFieldColonSpacingStyle。Possible values: 可能的值:
BFCS_Both
(in configuration:Both
) Add one space on each side of the:
BFCS_Both
(配置中:Both
)在:
的每一侧添加一个空格unsigned bf : 2;
BFCS_None
(in configuration:None
) Add no space around the:
(except when needed forAlignConsecutiveBitFields
).
BFCS_None
(在配置中:None
)在:
周围不添加空格(除非AlignConsecutiveBitFields
需要)。unsigned bf:2;
BFCS_Before
(in configuration:Before
) Add space before the:
only
BFCS_Before
(在配置中:Before
)仅在:
之前添加空格unsigned bf :2;
BFCS_After
(in configuration:After
) Add space after the:
only (space may be added before if needed forAlignConsecutiveBitFields
).
BFCS_After
(在配置中:After
)仅在:
之后添加空格(如果AlignConsecutiveBitFields
需要,可以在之前添加空格)。unsigned bf: 2;
- BraceWrapping (
BraceWrappingFlags
) clang-format 3.8 ¶ Control of individual brace wrapping cases.
控制单个支架包裹案例。If
BreakBeforeBraces
is set toBS_Custom
, use this to specify how each individual brace case should be handled. Otherwise, this is ignored.
如果BreakBeforeBraces
设置为BS_Custom
,则使用它来指定应如何处理每个单独的大括号情况。否则,这将被忽略。# Example of usage: BreakBeforeBraces: Custom BraceWrapping: AfterEnum: true AfterStruct: false SplitEmptyFunction: false
Nested configuration flags:
嵌套配置标志:Precise control over the wrapping of braces.
精确控制牙套的缠绕。# Should be declared this way: BreakBeforeBraces: Custom BraceWrapping: AfterClass: true
bool AfterCaseLabel
Wrap case labels.
bool AfterCaseLabel
包裹箱子标签。false: true: switch (foo) { vs. switch (foo) { case 1: { case 1: bar(); { break; bar(); } break; default: { } plop(); default: } { } plop(); } }
bool AfterClass
Wrap class definitions.
bool AfterClass
包装类定义。true: class foo {}; false: class foo {};
BraceWrappingAfterControlStatementStyle AfterControlStatement
Wrap control statements (if
/for
/while
/switch
/..).
BraceWrappingAfterControlStatementStyle AfterControlStatement
换行控制语句(if
/for
/while
/switch
/..)。Possible values: 可能的值:
BWACS_Never
(in configuration:Never
) Never wrap braces after a control statement.
BWACS_Never
(在配置中:Never
)切勿在控制语句后用大括号括起来。if (foo()) { } else { } for (int i = 0; i < 10; ++i) { }
BWACS_MultiLine
(in configuration:MultiLine
) Only wrap braces after a multi-line control statement.
BWACS_MultiLine
(在配置中:MultiLine
)仅在多行控制语句后用大括号括起来。if (foo && bar && baz) { quux(); } while (foo || bar) { }
BWACS_Always
(in configuration:Always
) Always wrap braces after a control statement.
BWACS_Always
(在配置中:Always
)始终在控制语句后用大括号括起来。if (foo()) { } else {} for (int i = 0; i < 10; ++i) {}
bool AfterEnum
Wrap enum definitions.
bool AfterEnum
包装枚举定义。true: enum X : int { B }; false: enum X : int { B };
bool AfterFunction
Wrap function definitions.
bool AfterFunction
包装函数定义。true: void foo() { bar(); bar2(); } false: void foo() { bar(); bar2(); }
bool AfterNamespace
Wrap namespace definitions.
bool AfterNamespace
包装命名空间定义。true: namespace { int foo(); int bar(); } false: namespace { int foo(); int bar(); }
bool AfterObjCDeclaration
Wrap ObjC definitions (interfaces, implementations…).
bool AfterObjCDeclaration
包装 ObjC 定义(接口、实现……)。Note 笔记
@autoreleasepool and @synchronized blocks are wrapped according to
AfterControlStatement
flag.
@autoreleasepool 和 @synchronized 块根据AfterControlStatement
标志进行包装。bool AfterStruct
Wrap struct definitions.
bool AfterStruct
包装结构定义。true: struct foo { int x; }; false: struct foo { int x; };
bool AfterUnion
Wrap union definitions.
bool AfterUnion
换行联合定义。true: union foo { int x; } false: union foo { int x; }
bool AfterExternBlock
Wrap extern blocks.
bool AfterExternBlock
包裹外部块。true: extern "C" { int foo(); } false: extern "C" { int foo(); }
bool BeforeCatch
Wrap beforecatch
.
bool BeforeCatch
在catch
之前换行。true: try { foo(); } catch () { } false: try { foo(); } catch () { }
bool BeforeElse
Wrap beforeelse
.
bool BeforeElse
在else
之前换行。true: if (foo()) { } else { } false: if (foo()) { } else { }
bool BeforeLambdaBody
Wrap lambda block.
bool BeforeLambdaBody
包裹 lambda 块。true: connect( []() { foo(); bar(); }); false: connect([]() { foo(); bar(); });
bool BeforeWhile
Wrap beforewhile
.
bool BeforeWhile
在while
之前换行。true: do { foo(); } while (1); false: do { foo(); } while (1);
bool IndentBraces
Indent the wrapped braces themselves.
bool IndentBraces
缩进包裹的大括号本身。bool SplitEmptyFunction
Iffalse
, empty function body can be put on a single line. This option is used only if the opening brace of the function has already been wrapped, i.e. theAfterFunction
brace wrapping mode is set, and the function could/should not be put on a single line (as perAllowShortFunctionsOnASingleLine
and constructor formatting options).
bool SplitEmptyFunction
如果false
,空函数体可以放在一行中。仅当函数的左大括号已被换行时才使用此选项,即设置了AfterFunction
大括号换行模式,并且函数可以/不应该放在单行上(根据AllowShortFunctionsOnASingleLine
和构造函数格式选项)。false: true: int f() vs. int f() {} { }
bool SplitEmptyRecord
Iffalse
, empty record (e.g. class, struct or union) body can be put on a single line. This option is used only if the opening brace of the record has already been wrapped, i.e. theAfterClass
(for classes) brace wrapping mode is set.
bool SplitEmptyRecord
如果false
,空记录(例如类、结构或联合)主体可以放在一行上。仅当记录的左大括号已被换行时才使用此选项,即设置了AfterClass
(对于类)大括号换行模式。false: true: class Foo vs. class Foo {} { }
bool SplitEmptyNamespace
Iffalse
, empty namespace body can be put on a single line. This option is used only if the opening brace of the namespace has already been wrapped, i.e. theAfterNamespace
brace wrapping mode is set.
bool SplitEmptyNamespace
如果false
,空的命名空间主体可以放在一行中。仅当命名空间的左大括号已被换行时才使用此选项,即设置了AfterNamespace
大括号换行模式。false: true: namespace Foo vs. namespace Foo {} { }
- BracedInitializerIndentWidth (
Unsigned
) clang-format 17 ¶ The number of columns to use to indent the contents of braced init lists. If unset,
ContinuationIndentWidth
is used.
用于缩进大括号初始化列表内容的列数。如果未设置,则使用ContinuationIndentWidth
。AlignAfterOpenBracket: AlwaysBreak BracedInitializerIndentWidth: 2 void f() { SomeClass c{ "foo", "bar", "baz", }; auto s = SomeStruct{ .foo = "foo", .bar = "bar", .baz = "baz", }; SomeArrayT a[3] = { { foo, bar, }, { foo, bar, }, SomeArrayT{}, }; }
- BreakAdjacentStringLiterals (
Boolean
) clang-format 18 ¶
BreakAdjacentStringLiterals (Boolean
) clang 格式 18 ¶ Break between adjacent string literals.
相邻字符串文字之间的分隔符。true: return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA"; false: return "Code" "\0\52\26\55\55\0" "x013" "\02\xBA";
- BreakAfterAttributes (
AttributeBreakingStyle
) clang-format 16 ¶ Break after a group of C++11 attributes before variable or function (including constructor/destructor) declaration/definition names or before control statements, i.e.
if
,switch
(includingcase
anddefault
labels),for
, andwhile
statements.
在变量或函数(包括构造函数/析构函数)声明/定义名称之前或控制语句之前的一组 C++11 属性之后中断,即if
、switch
(包括case
和default
标签)、for
和while
语句。Possible values: 可能的值:
ABS_Always
(in configuration:Always
) Always break after attributes.
ABS_Always
(在配置中:Always
)始终在属性之后中断。[[maybe_unused]] const int i; [[gnu::const]] [[maybe_unused]] int j; [[nodiscard]] inline int f(); [[gnu::const]] [[nodiscard]] int g(); [[likely]] if (a) f(); else g(); switch (b) { [[unlikely]] case 1: ++b; break; [[likely]] default: return; }
ABS_Leave
(in configuration:Leave
) Leave the line breaking after attributes as is.
ABS_Leave
(在配置中:Leave
)按原样保留属性后面的换行符。[[maybe_unused]] const int i; [[gnu::const]] [[maybe_unused]] int j; [[nodiscard]] inline int f(); [[gnu::const]] [[nodiscard]] int g(); [[likely]] if (a) f(); else g(); switch (b) { [[unlikely]] case 1: ++b; break; [[likely]] default: return; }
ABS_Never
(in configuration:Never
) Never break after attributes.
ABS_Never
(在配置中:Never
)切勿在属性之后中断。[[maybe_unused]] const int i; [[gnu::const]] [[maybe_unused]] int j; [[nodiscard]] inline int f(); [[gnu::const]] [[nodiscard]] int g(); [[likely]] if (a) f(); else g(); switch (b) { [[unlikely]] case 1: ++b; break; [[likely]] default: return; }
- BreakAfterJavaFieldAnnotations (
Boolean
) clang-format 3.8 ¶
BreakAfterJavaFieldAnnotations (Boolean
) clang 格式 3.8 ¶ Break after each annotation on a field in Java files.
在 Java 文件中字段上的每个注释后中断。true: false: @Partial vs. @Partial @Mock DataLoad loader; @Mock DataLoad loader;
- BreakAfterReturnType (
ReturnTypeBreakingStyle
) clang-format 19 ¶ The function declaration return type breaking style to use.
要使用的函数声明返回类型破坏样式。Possible values: 可能的值:
RTBS_None
(in configuration:None
) This is deprecated. SeeAutomatic
below.
RTBS_None
(在配置中:None
)这已被弃用。请参阅下面的Automatic
。RTBS_Automatic
(in configuration:Automatic
) Break after return type based onPenaltyReturnTypeOnItsOwnLine
.
RTBS_Automatic
(在配置中:Automatic
)基于PenaltyReturnTypeOnItsOwnLine
返回类型后中断。class A { int f() { return 0; }; }; int f(); int f() { return 1; } int LongName::AnotherLongName();
RTBS_ExceptShortType
(in configuration:ExceptShortType
) Same asAutomatic
above, except that there is no break after short return types.
RTBS_ExceptShortType
(在配置中:ExceptShortType
)与上面的Automatic
相同,只是短返回类型后面没有中断。class A { int f() { return 0; }; }; int f(); int f() { return 1; } int LongName:: AnotherLongName();
RTBS_All
(in configuration:All
) Always break after the return type.
RTBS_All
(在配置中:All
)始终在返回类型之后中断。class A { int f() { return 0; }; }; int f(); int f() { return 1; } int LongName::AnotherLongName();
RTBS_TopLevel
(in configuration:TopLevel
) Always break after the return types of top-level functions.
RTBS_TopLevel
(在配置中:TopLevel
)始终在顶级函数的返回类型之后中断。class A { int f() { return 0; }; }; int f(); int f() { return 1; } int LongName::AnotherLongName();
RTBS_AllDefinitions
(in configuration:AllDefinitions
) Always break after the return type of function definitions.
RTBS_AllDefinitions
(在配置中:AllDefinitions
)始终在函数定义的返回类型之后中断。class A { int f() { return 0; }; }; int f(); int f() { return 1; } int LongName::AnotherLongName();
RTBS_TopLevelDefinitions
(in configuration:TopLevelDefinitions
) Always break after the return type of top-level definitions.
RTBS_TopLevelDefinitions
(在配置中:TopLevelDefinitions
)始终在顶级定义的返回类型之后中断。class A { int f() { return 0; }; }; int f(); int f() { return 1; } int LongName::AnotherLongName();
- BreakArrays (
Boolean
) clang-format 16 ¶ If
true
, clang-format will always break after a Json array[
otherwise it will scan until the closing]
to determine if it should add newlines between elements (prettier compatible).
如果true
,clang-format 将始终在 Json 数组[
之后中断,否则它将扫描直到结束]
以确定是否应该在元素之间添加换行符(更兼容)。Note 笔记
This is currently only for formatting JSON.
目前这仅用于格式化 JSON。true: false: [ vs. [1, 2, 3, 4] 1, 2, 3, 4 ]
- BreakBeforeBinaryOperators (
BinaryOperatorStyle
) clang-format 3.6 ¶ The way to wrap binary operators.
包装二元运算符的方式。Possible values: 可能的值:
BOS_None
(in configuration:None
) Break after operators.
BOS_None
(在配置中:None
)在运算符之后中断。LooooooooooongType loooooooooooooooooooooongVariable = someLooooooooooooooooongFunction(); bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ccccccccccccccccccccccccccccccccccccccccc;
BOS_NonAssignment
(in configuration:NonAssignment
) Break before operators that aren’t assignments.
BOS_NonAssignment
(在配置中:NonAssignment
)在不是赋值的运算符之前中断。LooooooooooongType loooooooooooooooooooooongVariable = someLooooooooooooooooongFunction(); bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ccccccccccccccccccccccccccccccccccccccccc;
BOS_All
(in configuration:All
) Break before operators.
BOS_All
(在配置中:All
)在运算符之前中断。LooooooooooongType loooooooooooooooooooooongVariable = someLooooooooooooooooongFunction(); bool value = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa == aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa && aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa > ccccccccccccccccccccccccccccccccccccccccc;
- BreakBeforeBraces (
BraceBreakingStyle
) clang-format 3.7 ¶ The brace breaking style to use.
要使用的大括号破坏样式。Possible values: 可能的值:
BS_Attach
(in configuration:Attach
) Always attach braces to surrounding context.
BS_Attach
(在配置中:Attach
)始终将大括号附加到周围的上下文。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_Linux
(in configuration:Linux
) LikeAttach
, but break before braces on function, namespace and class definitions.
BS_Linux
(在配置中:Linux
)与Attach
类似,但在函数、命名空间和类定义的大括号之前断开。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_Mozilla
(in configuration:Mozilla
) LikeAttach
, but break before braces on enum, function, and record definitions.
BS_Mozilla
(在配置中:Mozilla
)与Attach
类似,但在枚举、函数和记录定义的大括号之前断开。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_Stroustrup
(in configuration:Stroustrup
) LikeAttach
, but break before function definitions,catch
, andelse
.
BS_Stroustrup
(在配置中:Stroustrup
)类似于Attach
,但在函数定义、catch
和else
之前中断。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_Allman
(in configuration:Allman
) Always break before braces.
BS_Allman
(在配置中:Allman
)始终在大括号之前断开。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_Whitesmiths
(in configuration:Whitesmiths
) LikeAllman
but always indent braces and line up code with braces.
BS_Whitesmiths
(在配置中:Whitesmiths
)与Allman
类似,但始终缩进大括号并将代码与大括号对齐。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_GNU
(in configuration:GNU
) Always break before braces and add an extra level of indentation to braces of control statements, not to those of class, function or other definitions.
BS_GNU
(在配置中:GNU
)始终在大括号之前断开,并向控制语句的大括号添加额外的缩进级别,而不是类、函数或其他定义的大括号。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_WebKit
(in configuration:WebKit
) LikeAttach
, but break before functions.
BS_WebKit
(在配置中:WebKit
)与Attach
类似,但在函数之前中断。namespace N { enum E { E1, E2, }; class C { public: C(); }; bool baz(int i) { try { do { switch (i) { case 1: { foobar(); break; } default: { break; } } } while (--i); return true; } catch (...) { handleError(); return false; } } void foo(bool b) { if (b) { baz(2); } else { baz(5); } } void bar() { foo(true); } } // namespace N
BS_Custom
(in configuration:Custom
) Configure each individual brace inBraceWrapping
.
BS_Custom
(在配置中:Custom
)在BraceWrapping
中配置每个单独的大括号。
- BreakBeforeConceptDeclarations (
BreakBeforeConceptDeclarationsStyle
) clang-format 12 ¶
BreakBeforeConceptDeclarations (BreakBeforeConceptDeclarationsStyle
) clang 格式 12 ¶ The concept declaration style to use.
要使用的概念声明样式。Possible values: 可能的值:
BBCDS_Never
(in configuration:Never
) Keep the template declaration line together withconcept
.
BBCDS_Never
(在配置中:Never
)将模板声明行与concept
放在一起。template <typename T> concept C = ...;
BBCDS_Allowed
(in configuration:Allowed
) Breaking between template declaration andconcept
is allowed. The actual behavior depends on the content and line breaking rules and penalties.
BBCDS_Allowed
(在配置中:Allowed
)允许在模板声明和concept
之间进行中断。实际行为取决于内容以及违规规则和处罚。BBCDS_Always
(in configuration:Always
) Always break beforeconcept
, putting it in the line after the template declaration.
BBCDS_Always
(在配置中:Always
)始终在concept
之前中断,将其放在模板声明之后的行中。template <typename T> concept C = ...;
- BreakBeforeInlineASMColon (
BreakBeforeInlineASMColonStyle
) clang-format 16 ¶
BreakBeforeInlineASMColon (BreakBeforeInlineASMColonStyle
) clang 格式 16 ¶ The inline ASM colon style to use.
要使用的内联 ASM 冒号样式。Possible values: 可能的值:
BBIAS_Never
(in configuration:Never
) No break before inline ASM colon.
BBIAS_Never
(在配置中:Never
)内联 ASM 冒号之前没有中断。asm volatile("string", : : val);
BBIAS_OnlyMultiline
(in configuration:OnlyMultiline
) Break before inline ASM colon if the line length is longer than column limit.
BBIAS_OnlyMultiline
(在配置中:OnlyMultiline
)如果行长度长于列限制,则在内联 ASM 冒号之前中断。asm volatile("string", : : val); asm("cmoveq %1, %2, %[result]" : [result] "=r"(result) : "r"(test), "r"(new), "[result]"(old));
BBIAS_Always
(in configuration:Always
) Always break before inline ASM colon.
BBIAS_Always
(在配置中:Always
)始终在内联 ASM 冒号之前中断。asm volatile("string", : : val);
- BreakBeforeTernaryOperators (
Boolean
) clang-format 3.7 ¶ If
true
, ternary operators will be placed after line breaks.
如果true
,三元运算符将放置在换行符之后。true: veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? firstValue : SecondValueVeryVeryVeryVeryLong; false: veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongDescription ? firstValue : SecondValueVeryVeryVeryVeryLong;
- BreakConstructorInitializers (
BreakConstructorInitializersStyle
) clang-format 5 ¶
BreakConstructorInitializers (BreakConstructorInitializersStyle
) clang 格式 5 ¶ The break constructor initializers style to use.
要使用的中断构造函数初始值设定项样式。Possible values: 可能的值:
BCIS_BeforeColon
(in configuration:BeforeColon
) Break constructor initializers before the colon and after the commas.
BCIS_BeforeColon
(在配置中:BeforeColon
)在冒号之前和逗号之后中断构造函数初始值设定项。Constructor() : initializer1(), initializer2()
BCIS_BeforeComma
(in configuration:BeforeComma
) Break constructor initializers before the colon and commas, and align the commas with the colon.
BCIS_BeforeComma
(在配置中:BeforeComma
)在冒号和逗号之前中断构造函数初始值设定项,并将逗号与冒号对齐。Constructor() : initializer1() , initializer2()
BCIS_AfterColon
(in configuration:AfterColon
) Break constructor initializers after the colon and commas.
BCIS_AfterColon
(在配置中:AfterColon
)在冒号和逗号之后中断构造函数初始值设定项。Constructor() : initializer1(), initializer2()
- BreakFunctionDefinitionParameters (
Boolean
) clang-format 19 ¶ If
true
, clang-format will always break before function definition parameters.
如果true
,clang-format 总是会在函数定义参数之前中断。true: void functionDefinition( int A, int B) {} false: void functionDefinition(int A, int B) {}
- BreakInheritanceList (
BreakInheritanceListStyle
) clang-format 7 ¶ The inheritance list style to use.
要使用的继承列表样式。Possible values: 可能的值:
BILS_BeforeColon
(in configuration:BeforeColon
) Break inheritance list before the colon and after the commas.
BILS_BeforeColon
(在配置中:BeforeColon
)在冒号之前和逗号之后打破继承列表。class Foo : Base1, Base2 {};
BILS_BeforeComma
(in configuration:BeforeComma
) Break inheritance list before the colon and commas, and align the commas with the colon.
BILS_BeforeComma
(在配置中:BeforeComma
)在冒号和逗号之前断开继承列表,并将逗号与冒号对齐。class Foo : Base1 , Base2 {};
BILS_AfterColon
(in configuration:AfterColon
) Break inheritance list after the colon and commas.
BILS_AfterColon
(在配置中:AfterColon
)在冒号和逗号之后中断继承列表。class Foo : Base1, Base2 {};
BILS_AfterComma
(in configuration:AfterComma
) Break inheritance list only after the commas.
BILS_AfterComma
(在配置中:AfterComma
)仅在逗号之后中断继承列表。class Foo : Base1, Base2 {};
- BreakStringLiterals (
Boolean
) clang-format 3.9 ¶ Allow breaking string literals when formatting.
允许在格式化时破坏字符串文字。In C, C++, and Objective-C:
在 C、C++ 和 Objective-C 中:true: const char* x = "veryVeryVeryVeryVeryVe" "ryVeryVeryVeryVeryVery" "VeryLongString"; false: const char* x = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
In C# and Java:
在 C# 和 Java 中:true: string x = "veryVeryVeryVeryVeryVe" + "ryVeryVeryVeryVeryVery" + "VeryLongString"; false: string x = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
C# interpolated strings are not broken.
C# 内插字符串不会被破坏。In Verilog: 在 Verilog 中:
true: string x = {"veryVeryVeryVeryVeryVe", "ryVeryVeryVeryVeryVery", "VeryLongString"}; false: string x = "veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongString";
- BreakTemplateDeclarations (
BreakTemplateDeclarationsStyle
) clang-format 19 ¶
BreakTemplateDeclarations (BreakTemplateDeclarationsStyle
) clang 格式 19 ¶ The template declaration breaking style to use.
要使用的模板声明破坏样式。Possible values: 可能的值:
BTDS_Leave
(in configuration:Leave
) Do not change the line breaking before the declaration.
BTDS_Leave
(在配置中:Leave
)不要更改声明之前的换行符。template <typename T> T foo() { } template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbbbbbbbbbb) { }
BTDS_No
(in configuration:No
) Do not force break before declaration.PenaltyBreakTemplateDeclaration
is taken into account.
BTDS_No
(在配置中:No
)声明前不要强制中断。PenaltyBreakTemplateDeclaration
被考虑在内。template <typename T> T foo() { } template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbbbbbbbbbb) { }
BTDS_MultiLine
(in configuration:MultiLine
) Force break after template declaration only when the following declaration spans multiple lines.
BTDS_MultiLine
(在配置中:MultiLine
)仅当以下声明跨越多行时,才在模板声明后强制中断。template <typename T> T foo() { } template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbbbbbbbbbb) { }
BTDS_Yes
(in configuration:Yes
) Always break after template declaration.
BTDS_Yes
(在配置中:Yes
)始终在模板声明后中断。template <typename T> T foo() { } template <typename T> T foo(int aaaaaaaaaaaaaaaaaaaaa, int bbbbbbbbbbbbbbbbbbbbb) { }
- ColumnLimit (
Unsigned
) clang-format 3.7 ¶ The column limit. 列限制。
A column limit of
0
means that there is no column limit. In this case, clang-format will respect the input’s line breaking decisions within statements unless they contradict other rules.
列限制0
表示没有列限制。在这种情况下,clang-format 将尊重语句中输入的换行决定,除非它们与其他规则相矛盾。
- CommentPragmas (
String
) clang-format 3.7 ¶ A regular expression that describes comments with special meaning, which should not be split into lines or otherwise changed.
描述具有特殊含义的注释的正则表达式,不应将其拆分为行或以其他方式更改。// CommentPragmas: '^ FOOBAR pragma:' // Will leave the following line unaffected #include <vector> // FOOBAR pragma: keep
- CompactNamespaces (
Boolean
) clang-format 5 ¶
紧凑命名空间 (Boolean
) clang-format 5 ¶ If
true
, consecutive namespace declarations will be on the same line. Iffalse
, each namespace is declared on a new line.
如果true
,连续的命名空间声明将位于同一行。如果false
,则每个命名空间都在新行中声明。true: namespace Foo { namespace Bar { }} false: namespace Foo { namespace Bar { } }
If it does not fit on a single line, the overflowing namespaces get wrapped:
如果它无法容纳在一行中,则溢出的名称空间将被包装:namespace Foo { namespace Bar { namespace Extra { }}}
- ConstructorInitializerAllOnOneLineOrOnePerLine (
Boolean
) clang-format 3.7 ¶ This option is deprecated. See
CurrentLine
ofPackConstructorInitializers
.
此选项已弃用。请参阅PackConstructorInitializers
的CurrentLine
。
- ConstructorInitializerIndentWidth (
Unsigned
) clang-format 3.7 ¶ The number of characters to use for indentation of constructor initializer lists as well as inheritance lists.
用于构造函数初始值设定项列表和继承列表缩进的字符数。
- ContinuationIndentWidth (
Unsigned
) clang-format 3.7 ¶ Indent width for line continuations.
行延续的缩进宽度。ContinuationIndentWidth: 2 int i = // VeryVeryVeryVeryVeryLongComment longFunction( // Again a long comment arg);
- Cpp11BracedListStyle (
Boolean
) clang-format 3.4 ¶
Cpp11BrcedListStyle (Boolean
) clang-format 3.4 ¶ If
true
, format braced lists as best suited for C++11 braced lists.
如果true
,则将大括号列表格式化为最适合 C++11 大括号列表。Important differences: - No spaces inside the braced list. - No line break before the closing brace. - Indentation with the continuation indent, not with the block indent.
重要区别: - 大括号列表内没有空格。 - 右大括号之前没有换行符。 - 使用连续缩进而不是块缩进进行缩进。Fundamentally, C++11 braced lists are formatted exactly like function calls would be formatted in their place. If the braced list follows a name (e.g. a type or variable name), clang-format formats as if the
{}
were the parentheses of a function call with that name. If there is no name, a zero-length name is assumed.
从根本上来说,C++11 大括号列表的格式与函数调用在其位置的格式完全相同。如果大括号列表后面有一个名称(例如类型或变量名称),则 clang-format 的格式就好像{}
是使用该名称的函数调用的括号。如果没有名称,则假定名称长度为零。true: false: vector<int> x{1, 2, 3, 4}; vs. vector<int> x{ 1, 2, 3, 4 }; vector<T> x{{}, {}, {}, {}}; vector<T> x{ {}, {}, {}, {} }; f(MyMap[{composite, key}]); f(MyMap[{ composite, key }]); new int[3]{1, 2, 3}; new int[3]{ 1, 2, 3 };
- DeriveLineEnding (
Boolean
) clang-format 10 ¶ This option is deprecated. See
DeriveLF
andDeriveCRLF
ofLineEnding
.
此选项已弃用。请参阅LineEnding
的DeriveLF
和DeriveCRLF
。
- DerivePointerAlignment (
Boolean
) clang-format 3.7 ¶ If
true
, analyze the formatted file for the most common alignment of&
and*
. Pointer and reference alignment styles are going to be updated according to the preferences found in the file.PointerAlignment
is then used only as fallback.
如果是true
,则分析格式化文件中&
和*
最常见的对齐方式。指针和参考对齐样式将根据文件中的首选项进行更新。PointerAlignment
仅用作后备。
- DisableFormat (
Boolean
) clang-format 3.7 ¶ Disables formatting completely.
完全禁用格式化。
- EmptyLineAfterAccessModifier (
EmptyLineAfterAccessModifierStyle
) clang-format 13 ¶ Defines when to put an empty line after access modifiers.
EmptyLineBeforeAccessModifier
configuration handles the number of empty lines between two access modifiers.
定义何时在访问修饰符后放置空行。EmptyLineBeforeAccessModifier
配置处理两个访问修饰符之间的空行数。Possible values: 可能的值:
ELAAMS_Never
(in configuration:Never
) Remove all empty lines after access modifiers.
ELAAMS_Never
(在配置中:Never
)删除访问修饰符后面的所有空行。struct foo { private: int i; protected: int j; /* comment */ public: foo() {} private: protected: };
ELAAMS_Leave
(in configuration:Leave
) Keep existing empty lines after access modifiers. MaxEmptyLinesToKeep is applied instead.
ELAAMS_Leave
(在配置中:Leave
)在访问修饰符之后保留现有的空行。改为应用 MaxEmptyLinesToKeep。ELAAMS_Always
(in configuration:Always
) Always add empty line after access modifiers if there are none. MaxEmptyLinesToKeep is applied also.
ELAAMS_Always
(在配置中:Always
)如果没有访问修饰符,请始终在访问修饰符后面添加空行。 MaxEmptyLinesToKeep 也适用。struct foo { private: int i; protected: int j; /* comment */ public: foo() {} private: protected: };
- EmptyLineBeforeAccessModifier (
EmptyLineBeforeAccessModifierStyle
) clang-format 12 ¶ Defines in which cases to put empty line before access modifiers.
定义在什么情况下在访问修饰符之前放置空行。Possible values: 可能的值:
ELBAMS_Never
(in configuration:Never
) Remove all empty lines before access modifiers.
ELBAMS_Never
(在配置中:Never
)删除访问修饰符之前的所有空行。struct foo { private: int i; protected: int j; /* comment */ public: foo() {} private: protected: };
ELBAMS_Leave
(in configuration:Leave
) Keep existing empty lines before access modifiers.
ELBAMS_Leave
(在配置中:Leave
)在访问修饰符之前保留现有的空行。ELBAMS_LogicalBlock
(in configuration:LogicalBlock
) Add empty line only when access modifier starts a new logical block. Logical block is a group of one or more member fields or functions.
ELBAMS_LogicalBlock
(在配置中:LogicalBlock
)仅在访问修饰符启动新逻辑块时添加空行。逻辑块是一组一个或多个成员字段或函数。struct foo { private: int i; protected: int j; /* comment */ public: foo() {} private: protected: };
ELBAMS_Always
(in configuration:Always
) Always add empty line before access modifiers unless access modifier is at the start of struct or class definition.
ELBAMS_Always
(在配置中:Always
)始终在访问修饰符之前添加空行,除非访问修饰符位于结构或类定义的开头。struct foo { private: int i; protected: int j; /* comment */ public: foo() {} private: protected: };
- ExperimentalAutoDetectBinPacking (
Boolean
) clang-format 3.7 ¶ If
true
, clang-format detects whether function calls and definitions are formatted with one parameter per line.
如果true
,clang-format 会检测函数调用和定义是否采用每行一个参数进行格式化。Each call can be bin-packed, one-per-line or inconclusive. If it is inconclusive, e.g. completely on one line, but a decision needs to be made, clang-format analyzes whether there are other bin-packed cases in the input file and act accordingly.
每个调用可以是打包的、每行一个的或不确定的。如果没有结论,例如完全在一行,但需要做出决定,clang-format 分析输入文件中是否存在其他 bin-packed 案例并采取相应行动。Note 笔记
This is an experimental flag, that might go away or be renamed. Do not use this in config files, etc. Use at your own risk.
这是一个实验性标志,可能会消失或被重命名。不要在配置文件等中使用它。使用风险自负。
- FixNamespaceComments (
Boolean
) clang-format 5 ¶ If
true
, clang-format adds missing namespace end comments for namespaces and fixes invalid existing ones. This doesn’t affect short namespaces, which are controlled byShortNamespaceLines
.
如果true
,clang-format 会为命名空间添加缺少的命名空间结束注释,并修复无效的现有注释。这不会影响由ShortNamespaceLines
控制的短命名空间。true: false: namespace longNamespace { vs. namespace longNamespace { void foo(); void foo(); void bar(); void bar(); } // namespace a } namespace shortNamespace { namespace shortNamespace { void baz(); void baz(); } }
- ForEachMacros (
List of Strings
) clang-format 3.7 ¶ A vector of macros that should be interpreted as foreach loops instead of as function calls.
宏向量,应解释为 foreach 循环而不是函数调用。These are expected to be macros of the form:
这些预计是以下形式的宏:FOREACH(<variable-declaration>, ...) <loop-body>
In the .clang-format configuration file, this can be configured like:
在 .clang-format 配置文件中,可以这样配置:ForEachMacros: ['RANGES_FOR', 'FOREACH']
For example: BOOST_FOREACH.
例如:BOOST_FOREACH。
- IfMacros (
List of Strings
) clang-format 13 ¶ A vector of macros that should be interpreted as conditionals instead of as function calls.
应被解释为条件而不是函数调用的宏向量。These are expected to be macros of the form:
这些预计是以下形式的宏:IF(...) <conditional-body> else IF(...) <conditional-body>
In the .clang-format configuration file, this can be configured like:
在 .clang-format 配置文件中,可以这样配置:IfMacros: ['IF']
For example: KJ_IF_MAYBE 例如:KJ_IF_MAYBE
- IncludeBlocks (
IncludeBlocksStyle
) clang-format 6 ¶ Dependent on the value, multiple
#include
blocks can be sorted as one and divided based on category.
根据值的不同,多个#include
块可以被排序为一个并根据类别进行划分。Possible values: 可能的值:
IBS_Preserve
(in configuration:Preserve
) Sort each#include
block separately.
IBS_Preserve
(在配置中:Preserve
)分别对每个#include
块进行排序。#include "b.h" into #include "b.h" #include <lib/main.h> #include "a.h" #include "a.h" #include <lib/main.h>
IBS_Merge
(in configuration:Merge
) Merge multiple#include
blocks together and sort as one.
IBS_Merge
(在配置中:Merge
)将多个#include
块合并在一起并排序为一个。#include "b.h" into #include "a.h" #include "b.h" #include <lib/main.h> #include <lib/main.h> #include "a.h"
IBS_Regroup
(in configuration:Regroup
) Merge multiple#include
blocks together and sort as one. Then split into groups based on category priority. SeeIncludeCategories
.
IBS_Regroup
(在配置中:Regroup
)将多个#include
块合并在一起并排序为一个。然后根据类别优先级分成组。请参阅IncludeCategories
。#include "b.h" into #include "a.h" #include "b.h" #include <lib/main.h> #include "a.h" #include <lib/main.h>
- IncludeCategories (
List of IncludeCategories
) clang-format 3.8 ¶ Regular expressions denoting the different
#include
categories used for ordering#includes
.
表示用于排序#includes
的不同#include
类别的正则表达式。POSIX extended regular expressions are supported.
支持 POSIX 扩展正则表达式。These regular expressions are matched against the filename of an include (including the <> or “”) in order. The value belonging to the first matching regular expression is assigned and
#includes
are sorted first according to increasing category number and then alphabetically within each category.
这些正则表达式按顺序与包含文件名(包括 <> 或“”)进行匹配。分配属于第一个匹配正则表达式的值,并且首先根据递增的类别编号对#includes
进行排序,然后在每个类别中按字母顺序排序。If none of the regular expressions match, INT_MAX is assigned as category. The main header for a source file automatically gets category 0. so that it is generally kept at the beginning of the
#includes
(https://llvm.org/docs/CodingStandards.html#include-style). However, you can also assign negative priorities if you have certain headers that always need to be first.
如果没有任何正则表达式匹配,则将 INT_MAX 指定为类别。源文件的主标头自动获取类别 0.,因此它通常保留在#includes
的开头(https://llvm.org/docs/CodingStandards.html#include-style)。但是,如果您有某些始终需要放在第一位的标头,您也可以分配负优先级。There is a third and optional field
SortPriority
which can used whileIncludeBlocks = IBS_Regroup
to define the priority in which#includes
should be ordered. The value ofPriority
defines the order of#include blocks
and also allows the grouping of#includes
of different priority.SortPriority
is set to the value ofPriority
as default if it is not assigned.
还有第三个可选字段SortPriority
,可以与IncludeBlocks = IBS_Regroup
一起使用来定义#includes
的排序优先级。Priority
的值定义了#include blocks
的顺序,并且还允许对不同优先级的#includes
进行分组。如果未分配SortPriority
,则默认设置为Priority
的值。Each regular expression can be marked as case sensitive with the field
CaseSensitive
, per default it is not.
每个正则表达式都可以使用字段CaseSensitive
标记为区分大小写,但默认情况下并非如此。To configure this in the .clang-format file, use:
要在 .clang-format 文件中进行配置,请使用:IncludeCategories: - Regex: '^"(llvm|llvm-c|clang|clang-c)/' Priority: 2 SortPriority: 2 CaseSensitive: true - Regex: '^((<|")(gtest|gmock|isl|json)/)' Priority: 3 - Regex: '<[[:alnum:].]+>' Priority: 4 - Regex: '.*' Priority: 1 SortPriority: 0
- IncludeIsMainRegex (
String
) clang-format 3.9 ¶ Specify a regular expression of suffixes that are allowed in the file-to-main-include mapping.
指定文件到主包含映射中允许的后缀正则表达式。When guessing whether a #include is the “main” include (to assign category 0, see above), use this regex of allowed suffixes to the header stem. A partial match is done, so that: - “” means “arbitrary suffix” - “$” means “no suffix”
当猜测 #include 是否是“主要”包含(分配类别 0,见上文)时,请使用此标头主干允许后缀的正则表达式。完成部分匹配,因此: - “”表示“任意后缀” - “$”表示“无后缀”For example, if configured to “(_test)?$”, then a header a.h would be seen as the “main” include in both a.cc and a_test.cc.
例如,如果配置为“(_test)?$”,则标头 a.h 将被视为 a.cc 和 a_test.cc 中的“main”。
- IncludeIsMainSourceRegex (
String
) clang-format 10 ¶ Specify a regular expression for files being formatted that are allowed to be considered “main” in the file-to-main-include mapping.
为正在格式化的文件指定正则表达式,这些文件允许在文件到主包含映射中被视为“主”。By default, clang-format considers files as “main” only when they end with:
.c
,.cc
,.cpp
,.c++
,.cxx
,.m
or.mm
extensions. For these files a guessing of “main” include takes place (to assign category 0, see above). This config option allows for additional suffixes and extensions for files to be considered as “main”.
默认情况下,clang-format 仅当文件以.c
、.cc
、.cpp
、.c++
结尾时才将其视为“main”.cxx
、.m
或.mm
扩展名。对于这些文件,会猜测“main”包含(分配类别 0,见上文)。此配置选项允许将文件的附加后缀和扩展名视为“主”。For example, if this option is configured to
(Impl\.hpp)$
, then a fileClassImpl.hpp
is considered “main” (in addition toClass.c
,Class.cc
,Class.cpp
and so on) and “main include file” logic will be executed (with IncludeIsMainRegex setting also being respected in later phase). Without this option set,ClassImpl.hpp
would not have the main include file put on top before any other include.
例如,如果此选项配置为(Impl\.hpp)$
,则文件ClassImpl.hpp
被视为“main”(除了Class.c
、Class.cc
、Class.cpp
等)和“主包含文件”逻辑将被执行(在后期阶段也会考虑 IncludeIsMainRegex 设置)。如果没有设置此选项,ClassImpl.hpp
不会将主包含文件放在任何其他包含文件之前。
- IndentAccessModifiers (
Boolean
) clang-format 13 ¶ Specify whether access modifiers should have their own indentation level.
指定访问修饰符是否应该有自己的缩进级别。When
false
, access modifiers are indented (or outdented) relative to the record members, respecting theAccessModifierOffset
. Record members are indented one level below the record. Whentrue
, access modifiers get their own indentation level. As a consequence, record members are always indented 2 levels below the record, regardless of the access modifier presence. Value of theAccessModifierOffset
is ignored.
当false
时,访问修饰符相对于记录成员缩进(或减少缩进),尊重AccessModifierOffset
。记录成员缩进记录下一级。当true
时,访问修饰符获得自己的缩进级别。因此,无论访问修饰符是否存在,记录成员始终缩进记录下方 2 级。AccessModifierOffset
的值被忽略。false: true: class C { vs. class C { class D { class D { void bar(); void bar(); protected: protected: D(); D(); }; }; public: public: C(); C(); }; }; void foo() { void foo() { return 1; return 1; } }
- IndentCaseBlocks (
Boolean
) clang-format 11 ¶ Indent case label blocks one level from the case label.
缩进 case 标签与 case 标签挡住一层。When
false
, the block following the case label uses the same indentation level as for the case label, treating the case label the same as an if-statement. Whentrue
, the block gets indented as a scope block.
当false
时,case 标签后面的块使用与 case 标签相同的缩进级别,将 case 标签视为 if 语句。当true
时,该块将缩进为范围块。false: true: switch (fool) { vs. switch (fool) { case 1: { case 1: bar(); { } break; bar(); default: { } plop(); break; } default: } { plop(); } }
- IndentCaseLabels (
Boolean
) clang-format 3.3 ¶ Indent case labels one level from the switch statement.
缩进大小写标记 switch 语句的一级。When
false
, use the same indentation level as for the switch statement. Switch statement body is always indented one level more than case labels (except the first block following the case label, which itself indents the code - unless IndentCaseBlocks is enabled).
当false
时,使用与 switch 语句相同的缩进级别。 Switch 语句主体始终比 case 标签缩进一级(case 标签后面的第一个块除外,它本身会缩进代码 - 除非启用了 IndentCaseBlocks)。false: true: switch (fool) { vs. switch (fool) { case 1: case 1: bar(); bar(); break; break; default: default: plop(); plop(); } }
- IndentExternBlock (
IndentExternBlockStyle
) clang-format 11 ¶ IndentExternBlockStyle is the type of indenting of extern blocks.
IndentExternBlockStyle 是外部块的缩进类型。Possible values: 可能的值:
IEBS_AfterExternBlock
(in configuration:AfterExternBlock
) Backwards compatible with AfterExternBlock’s indenting.
IEBS_AfterExternBlock
(配置中:AfterExternBlock
)向后兼容 AfterExternBlock 的缩进。IndentExternBlock: AfterExternBlock BraceWrapping.AfterExternBlock: true extern "C" { void foo(); }
IndentExternBlock: AfterExternBlock BraceWrapping.AfterExternBlock: false extern "C" { void foo(); }
IEBS_NoIndent
(in configuration:NoIndent
) Does not indent extern blocks.
IEBS_NoIndent
(在配置中:NoIndent
)不缩进外部块。extern "C" { void foo(); }
IEBS_Indent
(in configuration:Indent
) Indents extern blocks.
IEBS_Indent
(在配置中:Indent
)缩进外部块。extern "C" { void foo(); }
- IndentGotoLabels (
Boolean
) clang-format 10 ¶ Indent goto labels. 缩进转到标签。
When
false
, goto labels are flushed left.
当false
时,转到标签向左刷新。true: false: int f() { vs. int f() { if (foo()) { if (foo()) { label1: label1: bar(); bar(); } } label2: label2: return 1; return 1; } }
- IndentPPDirectives (
PPDirectiveIndentStyle
) clang-format 6 ¶ The preprocessor directive indenting style to use.
要使用的预处理器指令缩进样式。Possible values: 可能的值:
PPDIS_None
(in configuration:None
) Does not indent any directives.
PPDIS_None
(在配置中:None
)不缩进任何指令。#if FOO #if BAR #include <foo> #endif #endif
PPDIS_AfterHash
(in configuration:AfterHash
) Indents directives after the hash.
PPDIS_AfterHash
(在配置中:AfterHash
)在哈希之后缩进指令。#if FOO # if BAR # include <foo> # endif #endif
PPDIS_BeforeHash
(in configuration:BeforeHash
) Indents directives before the hash.
PPDIS_BeforeHash
(在配置中:BeforeHash
)在哈希之前缩进指令。#if FOO #if BAR #include <foo> #endif #endif
- IndentRequiresClause (
Boolean
) clang-format 15 ¶ Indent the requires clause in a template. This only applies when
RequiresClausePosition
isOwnLine
, orWithFollowing
.
缩进模板中的requires 子句。仅当RequiresClausePosition
为OwnLine
或WithFollowing
时才适用。In clang-format 12, 13 and 14 it was named
IndentRequires
.
在 clang-format 12、13 和 14 中,它被命名为IndentRequires
。true: template <typename It> requires Iterator<It> void sort(It begin, It end) { //.... } false: template <typename It> requires Iterator<It> void sort(It begin, It end) { //.... }
- IndentWidth (
Unsigned
) clang-format 3.7 ¶
缩进宽度 (Unsigned
) clang-format 3.7 ¶ The number of columns to use for indentation.
用于缩进的列数。IndentWidth: 3 void f() { someFunction(); if (true, false) { f(); } }
- IndentWrappedFunctionNames (
Boolean
) clang-format 3.7 ¶ Indent if a function definition or declaration is wrapped after the type.
如果函数定义或声明包含在类型后面,则缩进。true: LoooooooooooooooooooooooooooooooooooooooongReturnType LoooooooooooooooooooooooooooooooongFunctionDeclaration(); false: LoooooooooooooooooooooooooooooooooooooooongReturnType LoooooooooooooooooooooooooooooooongFunctionDeclaration();
- InsertBraces (
Boolean
) clang-format 15 ¶ Insert braces after control statements (
if
,else
,for
,do
, andwhile
) in C++ unless the control statements are inside macro definitions or the braces would enclose preprocessor directives.
在 C++ 中的控制语句(if
、else
、for
、do
和while
)后插入大括号,除非控制语句位于宏定义内,或者大括号将预处理器指令括起来。Warning 警告
Setting this option to
true
could lead to incorrect code formatting due to clang-format’s lack of complete semantic information. As such, extra care should be taken to review code changes made by this option.
将此选项设置为true
可能会由于 clang-format 缺乏完整的语义信息而导致代码格式不正确。因此,应格外小心地检查此选项所做的代码更改。false: true: if (isa<FunctionDecl>(D)) vs. if (isa<FunctionDecl>(D)) { handleFunctionDecl(D); handleFunctionDecl(D); else if (isa<VarDecl>(D)) } else if (isa<VarDecl>(D)) { handleVarDecl(D); handleVarDecl(D); else } else { return; return; } while (i--) vs. while (i--) { for (auto *A : D.attrs()) for (auto *A : D.attrs()) { handleAttr(A); handleAttr(A); } } do vs. do { --i; --i; while (i); } while (i);
- InsertNewlineAtEOF (
Boolean
) clang-format 16 ¶ Insert a newline at end of file if missing.
如果缺少,请在文件末尾插入换行符。
- InsertTrailingCommas (
TrailingCommaStyle
) clang-format 11 ¶ If set to
TCS_Wrapped
will insert trailing commas in container literals (arrays and objects) that wrap across multiple lines. It is currently only available for JavaScript and disabled by defaultTCS_None
.InsertTrailingCommas
cannot be used together withBinPackArguments
as inserting the comma disables bin-packing.
如果设置为TCS_Wrapped
将在跨多行的容器文字(数组和对象)中插入尾随逗号。它目前仅适用于 JavaScript,并且默认禁用TCS_None
。InsertTrailingCommas
不能与BinPackArguments
一起使用,因为插入逗号会禁用装箱。TSC_Wrapped: const someArray = [ aaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaa, // ^ inserted ]
Possible values: 可能的值:
TCS_None
(in configuration:None
) Do not insert trailing commas.
TCS_None
(在配置中:None
)不要插入尾随逗号。TCS_Wrapped
(in configuration:Wrapped
) Insert trailing commas in container literals that were wrapped over multiple lines. Note that this is conceptually incompatible with bin-packing, because the trailing comma is used as an indicator that a container should be formatted one-per-line (i.e. not bin-packed). So inserting a trailing comma counteracts bin-packing.
TCS_Wrapped
(在配置中:Wrapped
)在多行换行的容器文字中插入尾随逗号。请注意,这在概念上与装箱不兼容,因为尾随逗号用作容器应逐行格式化的指示符(即不装箱)。因此插入尾随逗号可以抵消装箱的影响。
- IntegerLiteralSeparator (
IntegerLiteralSeparatorStyle
) clang-format 16 ¶ Format integer literal separators (
'
for C++ and_
for C#, Java, and JavaScript).
设置整数文字分隔符的格式(对于 C++ 为'
,对于 C#、Java 和 JavaScript 为_
)。Nested configuration flags:
嵌套配置标志:Separator format of integer literals of different bases.
不同基数的整数文字的分隔符格式。If negative, remove separators. If
0
, leave the literal as is. If positive, insert separators between digits starting from the rightmost digit.
如果为负,请删除分隔符。如果0
,则保留文字原样。如果为正数,则从最右边的数字开始在数字之间插入分隔符。For example, the config below will leave separators in binary literals alone, insert separators in decimal literals to separate the digits into groups of 3, and remove separators in hexadecimal literals.
例如,下面的配置将仅保留二进制文字中的分隔符,在十进制文字中插入分隔符以将数字分成 3 个组,并删除十六进制文字中的分隔符。IntegerLiteralSeparator: Binary: 0 Decimal: 3 Hex: -1
You can also specify a minimum number of digits (
BinaryMinDigits
,DecimalMinDigits
, andHexMinDigits
) the integer literal must have in order for the separators to be inserted.
您还可以指定整数文字必须具有的最小位数(BinaryMinDigits
、DecimalMinDigits
和HexMinDigits
),以便插入分隔符。int8_t Binary
Format separators in binary literals.
int8_t Binary
以二进制文字格式化分隔符。/* -1: */ b = 0b100111101101; /* 0: */ b = 0b10011'11'0110'1; /* 3: */ b = 0b100'111'101'101; /* 4: */ b = 0b1001'1110'1101;
int8_t BinaryMinDigits
Format separators in binary literals with a minimum number of digits.
int8_t BinaryMinDigits
使用最少位数的二进制文字格式化分隔符。// Binary: 3 // BinaryMinDigits: 7 b1 = 0b101101; b2 = 0b1'101'101;
int8_t Decimal
Format separators in decimal literals.
int8_t Decimal
以十进制文字格式化分隔符。/* -1: */ d = 18446744073709550592ull; /* 0: */ d = 184467'440737'0'95505'92ull; /* 3: */ d = 18'446'744'073'709'550'592ull;
int8_t DecimalMinDigits
Format separators in decimal literals with a minimum number of digits.
int8_t DecimalMinDigits
使用最少位数的十进制文字格式设置分隔符。// Decimal: 3 // DecimalMinDigits: 5 d1 = 2023; d2 = 10'000;
int8_t Hex
Format separators in hexadecimal literals.
int8_t Hex
以十六进制文字格式化分隔符。/* -1: */ h = 0xDEADBEEFDEADBEEFuz; /* 0: */ h = 0xDEAD'BEEF'DE'AD'BEE'Fuz; /* 2: */ h = 0xDE'AD'BE'EF'DE'AD'BE'EFuz;
int8_t HexMinDigits
Format separators in hexadecimal literals with a minimum number of digits.
int8_t HexMinDigits
使用最少位数的十六进制文字格式化分隔符。// Hex: 2 // HexMinDigits: 6 h1 = 0xABCDE; h2 = 0xAB'CD'EF;
- JavaImportGroups (
List of Strings
) clang-format 8 ¶ A vector of prefixes ordered by the desired groups for Java imports.
按 Java 导入所需组排序的前缀向量。One group’s prefix can be a subset of another - the longest prefix is always matched. Within a group, the imports are ordered lexicographically. Static imports are grouped separately and follow the same group rules. By default, static imports are placed before non-static imports, but this behavior is changed by another option,
SortJavaStaticImport
.
一个组的前缀可以是另一个组的子集 - 最长的前缀始终匹配。在组内,导入按字典顺序排序。静态导入单独分组并遵循相同的组规则。默认情况下,静态导入放置在非静态导入之前,但此行为由另一个选项SortJavaStaticImport
更改。In the .clang-format configuration file, this can be configured like in the following yaml example. This will result in imports being formatted as in the Java example below.
在 .clang-format 配置文件中,可以像下面的 yaml 示例一样进行配置。这将导致导入的格式如下面的 Java 示例所示。JavaImportGroups: ['com.example', 'com', 'org']
import static com.example.function1; import static com.test.function2; import static org.example.function3; import com.example.ClassA; import com.example.Test; import com.example.a.ClassB; import com.test.ClassC; import org.example.ClassD;
- JavaScriptQuotes (
JavaScriptQuoteStyle
) clang-format 3.9 ¶ The JavaScriptQuoteStyle to use for JavaScript strings.
用于 JavaScript 字符串的 JavaScriptQuoteStyle。Possible values: 可能的值:
JSQS_Leave
(in configuration:Leave
) Leave string quotes as they are.
JSQS_Leave
(在配置中:Leave
)保留字符串引号不变。string1 = "foo"; string2 = 'bar';
JSQS_Single
(in configuration:Single
) Always use single quotes.
JSQS_Single
(在配置中:Single
)始终使用单引号。string1 = 'foo'; string2 = 'bar';
JSQS_Double
(in configuration:Double
) Always use double quotes.
JSQS_Double
(在配置中:Double
)始终使用双引号。string1 = "foo"; string2 = "bar";
- JavaScriptWrapImports (
Boolean
) clang-format 3.9 ¶ Whether to wrap JavaScript import/export statements.
是否包装 JavaScript 导入/导出语句。true: import { VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, } from 'some/module.js' false: import {VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying, VeryLongImportsAreAnnoying,} from "some/module.js"
- KeepEmptyLinesAtEOF (
Boolean
) clang-format 17 ¶ Keep empty lines (up to
MaxEmptyLinesToKeep
) at end of file.
在文件末尾保留空行(最多MaxEmptyLinesToKeep
)。
- KeepEmptyLinesAtTheStartOfBlocks (
Boolean
) clang-format 3.7 ¶ If true, the empty line at the start of blocks is kept.
如果为 true,则保留块开头的空行。true: false: if (foo) { vs. if (foo) { bar(); bar(); } }
- LambdaBodyIndentation (
LambdaBodyIndentationKind
) clang-format 13 ¶ The indentation style of lambda bodies.
Signature
(the default) causes the lambda body to be indented one additional level relative to the indentation level of the signature.OuterScope
forces the lambda body to be indented one additional level relative to the parent scope containing the lambda signature.
lambda 体的缩进样式。Signature
(默认值)使 lambda 主体相对于签名的缩进级别再缩进一级。OuterScope
强制 lambda 主体相对于包含 lambda 签名的父作用域再缩进一层。Possible values: 可能的值:
LBI_Signature
(in configuration:Signature
) Align lambda body relative to the lambda signature. This is the default.
LBI_Signature
(在配置中:Signature
)相对于 lambda 签名对齐 lambda 主体。这是默认设置。someMethod( [](SomeReallyLongLambdaSignatureArgument foo) { return; });
LBI_OuterScope
(in configuration:OuterScope
) For statements within block scope, align lambda body relative to the indentation level of the outer scope the lambda signature resides in.
LBI_OuterScope
(在配置中:OuterScope
)对于块作用域内的语句,将 lambda 主体相对于 lambda 签名所在的外部作用域的缩进级别对齐。someMethod( [](SomeReallyLongLambdaSignatureArgument foo) { return; }); someMethod(someOtherMethod( [](SomeReallyLongLambdaSignatureArgument foo) { return; }));
- Language (
LanguageKind
) clang-format 3.5 ¶
语言 (LanguageKind
) clang-format 3.5 ¶ Language, this format style is targeted at.
语言,这种格式样式是针对的。Possible values: 可能的值:
LK_None
(in configuration:None
) Do not use.
LK_None
(在配置中:None
)不要使用。LK_Cpp
(in configuration:Cpp
) Should be used for C, C++.
LK_Cpp
(在配置中:Cpp
)应该用于 C、C++。LK_CSharp
(in configuration:CSharp
) Should be used for C#.
LK_CSharp
(在配置中:CSharp
)应该用于 C#。LK_Java
(in configuration:Java
) Should be used for Java.
LK_Java
(在配置中:Java
)应该用于 Java。LK_JavaScript
(in configuration:JavaScript
) Should be used for JavaScript.
LK_JavaScript
(在配置中:JavaScript
)应该用于 JavaScript。LK_Json
(in configuration:Json
) Should be used for JSON.
LK_Json
(在配置中:Json
)应该用于 JSON。LK_ObjC
(in configuration:ObjC
) Should be used for Objective-C, Objective-C++.
LK_ObjC
(在配置中:ObjC
)应该用于 Objective-C、Objective-C++。LK_Proto
(in configuration:Proto
) Should be used for Protocol Buffers (https://developers.google.com/protocol-buffers/).
LK_Proto
(在配置中:Proto
)应用于 Protocol Buffers ( https://developers.google.com/protocol-buffers/ )。LK_TableGen
(in configuration:TableGen
) Should be used for TableGen code.
LK_TableGen
(在配置中:TableGen
)应用于 TableGen 代码。LK_TextProto
(in configuration:TextProto
) Should be used for Protocol Buffer messages in text format (https://developers.google.com/protocol-buffers/).
LK_TextProto
(在配置中:TextProto
)应用于文本格式的 Protocol Buffer 消息 ( https://developers.google.com/protocol-buffers/ )。LK_Verilog
(in configuration:Verilog
) Should be used for Verilog and SystemVerilog. https://standards.ieee.org/ieee/1800/6700/ https://sci-hub.st/10.1109/IEEESTD.2018.8299595
LK_Verilog
(在配置中:Verilog
)应用于 Verilog 和 SystemVerilog。 https://standards.ieee.org/ieee/1800/6700/ https://sci-hub.st/10.1109/IEEESTD.2018.8299595
- LineEnding (
LineEndingStyle
) clang-format 16 ¶ Line ending style (
\n
or\r\n
) to use.
要使用的行结束样式(\n
或\r\n
)。Possible values: 可能的值:
LE_LF
(in configuration:LF
) Use\n
.
LE_LF
(在配置中:LF
)使用\n
。LE_CRLF
(in configuration:CRLF
) Use\r\n
.
LE_CRLF
(在配置中:CRLF
)使用\r\n
。LE_DeriveLF
(in configuration:DeriveLF
) Use\n
unless the input has more lines ending in\r\n
.
LE_DeriveLF
(在配置中:DeriveLF
)使用\n
,除非输入有更多以\r\n
结尾的行。LE_DeriveCRLF
(in configuration:DeriveCRLF
) Use\r\n
unless the input has more lines ending in\n
.
LE_DeriveCRLF
(在配置中:DeriveCRLF
)使用\r\n
,除非输入有更多以\n
结尾的行。
- MacroBlockBegin (
String
) clang-format 3.7 ¶ A regular expression matching macros that start a block.
匹配启动块的宏的正则表达式。# With: MacroBlockBegin: "^NS_MAP_BEGIN|\ NS_TABLE_HEAD$" MacroBlockEnd: "^\ NS_MAP_END|\ NS_TABLE_.*_END$" NS_MAP_BEGIN foo(); NS_MAP_END NS_TABLE_HEAD bar(); NS_TABLE_FOO_END # Without: NS_MAP_BEGIN foo(); NS_MAP_END NS_TABLE_HEAD bar(); NS_TABLE_FOO_END
- MacroBlockEnd (
String
) clang-format 3.7 ¶ A regular expression matching macros that end a block.
匹配结束块的宏的正则表达式。
- Macros (
List of Strings
) clang-format 17 ¶
宏 (List of Strings
) clang-format 17 ¶ A list of macros of the form
<definition>=<expansion>
.
<definition>=<expansion>
形式的宏列表。Code will be parsed with macros expanded, in order to determine how to interpret and format the macro arguments.
代码将通过扩展的宏进行解析,以确定如何解释和格式化宏参数。For example, the code:
例如,代码:A(a*b);
will usually be interpreted as a call to a function A, and the multiplication expression will be formatted as
a * b
.
通常会被解释为对函数 A 的调用,并且乘法表达式将被格式化为a * b
。If we specify the macro definition:
如果我们指定宏定义:Macros: - A(x)=x
the code will now be parsed as a declaration of the variable b of type a*, and formatted as
a* b
(depending on pointer-binding rules).
该代码现在将被解析为 a* 类型的变量 b 的声明,并格式化为a* b
(取决于指针绑定规则)。- Features and restrictions:
特点和限制: Both function-like macros and object-like macros are supported.
支持类函数宏和类对象宏。Macro arguments must be used exactly once in the expansion.
宏参数必须在扩展中仅使用一次。No recursive expansion; macros referencing other macros will be ignored.
没有递归扩展;引用其他宏的宏将被忽略。Overloading by arity is supported: for example, given the macro definitions A=x, A()=y, A(a)=a
支持按数量重载:例如,给定宏定义 A=x、A()=y、A(a)=a
A; -> x; A(); -> y; A(z); -> z; A(a, b); // will not be expanded.
- Features and restrictions:
- MainIncludeChar (
MainIncludeCharDiscriminator
) clang-format 19 ¶ When guessing whether a #include is the “main” include, only the include directives that use the specified character are considered.
当猜测 #include 是否是“主”包含时,仅考虑使用指定字符的包含指令。Possible values: 可能的值:
MICD_Quote
(in configuration:Quote
) Main include uses quotes:#include "foo.hpp"
(the default).
MICD_Quote
(在配置中:Quote
)主要包含使用引号:#include "foo.hpp"
(默认)。MICD_AngleBracket
(in configuration:AngleBracket
) Main include uses angle brackets:#include <foo.hpp>
.
MICD_AngleBracket
(配置中:AngleBracket
)主要包含使用尖括号:#include <foo.hpp>
。MICD_Any
(in configuration:Any
) Main include uses either quotes or angle brackets.
MICD_Any
(在配置中:Any
)主要包含使用引号或尖括号。
- MaxEmptyLinesToKeep (
Unsigned
) clang-format 3.7 ¶ The maximum number of consecutive empty lines to keep.
要保留的连续空行的最大数量。MaxEmptyLinesToKeep: 1 vs. MaxEmptyLinesToKeep: 0 int f() { int f() { int = 1; int i = 1; i = foo(); i = foo(); return i; } return i; }
- NamespaceIndentation (
NamespaceIndentationKind
) clang-format 3.7 ¶
命名空间缩进 (NamespaceIndentationKind
) clang-format 3.7 ¶ The indentation used for namespaces.
用于命名空间的缩进。Possible values: 可能的值:
NI_None
(in configuration:None
) Don’t indent in namespaces.
NI_None
(在配置中:None
)不要在命名空间中缩进。namespace out { int i; namespace in { int i; } }
NI_Inner
(in configuration:Inner
) Indent only in inner namespaces (nested in other namespaces).
NI_Inner
(在配置中:Inner
)仅在内部命名空间(嵌套在其他命名空间中)中缩进。namespace out { int i; namespace in { int i; } }
NI_All
(in configuration:All
) Indent in all namespaces.
NI_All
(在配置中:All
)在所有命名空间中缩进。namespace out { int i; namespace in { int i; } }
- NamespaceMacros (
List of Strings
) clang-format 9 ¶
命名空间宏 (List of Strings
) clang-format 9 ¶ A vector of macros which are used to open namespace blocks.
用于打开命名空间块的宏向量。These are expected to be macros of the form:
这些预计是以下形式的宏:NAMESPACE(<namespace-name>, ...) { <namespace-content> }
For example: TESTSUITE 例如:测试套件
- ObjCBinPackProtocolList (
BinPackStyle
) clang-format 7 ¶ Controls bin-packing Objective-C protocol conformance list items into as few lines as possible when they go over
ColumnLimit
.
当 Objective-C 协议一致性列表项经过ColumnLimit
时,控制将它们装箱到尽可能少的行中。If
Auto
(the default), delegates to the value inBinPackParameters
. If that istrue
, bin-packs Objective-C protocol conformance list items into as few lines as possible whenever they go overColumnLimit
.
如果是Auto
(默认值),则委托给BinPackParameters
中的值。如果是true
,则只要超过ColumnLimit
,就会将 Objective-C 协议一致性列表项打包到尽可能少的行中。If
Always
, always bin-packs Objective-C protocol conformance list items into as few lines as possible whenever they go overColumnLimit
.
如果是Always
,每当 Objective-C 协议一致性列表项超过ColumnLimit
时,总是将其打包到尽可能少的行中。If
Never
, lays out Objective-C protocol conformance list items onto individual lines whenever they go overColumnLimit
.
如果是Never
,则只要超过ColumnLimit
,就会将 Objective-C 协议一致性列表项布置到单独的行上。Always (or Auto, if BinPackParameters=true): @interface ccccccccccccc () < ccccccccccccc, ccccccccccccc, ccccccccccccc, ccccccccccccc> { } Never (or Auto, if BinPackParameters=false): @interface ddddddddddddd () < ddddddddddddd, ddddddddddddd, ddddddddddddd, ddddddddddddd> { }
Possible values: 可能的值:
BPS_Auto
(in configuration:Auto
) Automatically determine parameter bin-packing behavior.
BPS_Auto
(在配置中:Auto
)自动确定参数装箱行为。BPS_Always
(in configuration:Always
) Always bin-pack parameters.
BPS_Always
(在配置中:Always
)始终对参数进行装箱。BPS_Never
(in configuration:Never
) Never bin-pack parameters.
BPS_Never
(在配置中:Never
)切勿对参数进行装箱。
- ObjCBlockIndentWidth (
Unsigned
) clang-format 3.7 ¶ The number of characters to use for indentation of ObjC blocks.
用于 ObjC 块缩进的字符数。ObjCBlockIndentWidth: 4 [operation setCompletionBlock:^{ [self onOperationDone]; }];
- ObjCBreakBeforeNestedBlockParam (
Boolean
) clang-format 11 ¶ Break parameters list into lines when there is nested block parameters in a function call.
当函数调用中存在嵌套块参数时,将参数列表分成行。false: - (void)_aMethod { [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { u = c; }] } true: - (void)_aMethod { [self.test1 t:self w:self callback:^(typeof(self) self, NSNumber *u, NSNumber *v) { u = c; }] }
- ObjCPropertyAttributeOrder (
List of Strings
) clang-format 18 ¶ The order in which ObjC property attributes should appear.
ObjC 属性应出现的顺序。Attributes in code will be sorted in the order specified. Any attributes encountered that are not mentioned in this array will be sorted last, in stable order. Comments between attributes will leave the attributes untouched.
代码中的属性将按指定的顺序排序。遇到的任何未在此数组中提及的属性都将按稳定顺序排在最后。属性之间的注释将使属性保持不变。Warning 警告
Using this option could lead to incorrect code formatting due to clang-format’s lack of complete semantic information. As such, extra care should be taken to review code changes made by this option.
由于 clang-format 缺乏完整的语义信息,使用此选项可能会导致错误的代码格式。因此,应格外小心地检查此选项所做的代码更改。ObjCPropertyAttributeOrder: [ class, direct, atomic, nonatomic, assign, retain, strong, copy, weak, unsafe_unretained, readonly, readwrite, getter, setter, nullable, nonnull, null_resettable, null_unspecified ]
- ObjCSpaceAfterProperty (
Boolean
) clang-format 3.7 ¶ Add a space after
@property
in Objective-C, i.e. use@property (readonly)
instead of@property(readonly)
.
在 Objective-C 中@property
之后添加一个空格,即使用@property (readonly)
而不是@property(readonly)
。
- ObjCSpaceBeforeProtocolList (
Boolean
) clang-format 3.7 ¶ Add a space in front of an Objective-C protocol list, i.e. use
Foo <Protocol>
instead ofFoo<Protocol>
.
在 Objective-C 协议列表前面添加一个空格,即使用Foo <Protocol>
而不是Foo<Protocol>
。
- PPIndentWidth (
Integer
) clang-format 13 ¶ The number of columns to use for indentation of preprocessor statements. When set to -1 (default)
IndentWidth
is used also for preprocessor statements.
用于预处理器语句缩进的列数。当设置为 -1(默认)时,IndentWidth
也用于预处理器语句。PPIndentWidth: 1 #ifdef __linux__ # define FOO #else # define BAR #endif
- PackConstructorInitializers (
PackConstructorInitializersStyle
) clang-format 14 ¶ The pack constructor initializers style to use.
要使用的包构造函数初始值设定项样式。Possible values: 可能的值:
PCIS_Never
(in configuration:Never
) Always put each constructor initializer on its own line.
PCIS_Never
(在配置中:Never
)始终将每个构造函数初始值设定项放在自己的行上。Constructor() : a(), b()
PCIS_BinPack
(in configuration:BinPack
) Bin-pack constructor initializers.
PCIS_BinPack
(在配置中:BinPack
)Bin-pack 构造函数初始值设定项。Constructor() : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), cccccccccccccccccccc()
PCIS_CurrentLine
(in configuration:CurrentLine
) Put all constructor initializers on the current line if they fit. Otherwise, put each one on its own line.
PCIS_CurrentLine
(在配置中:CurrentLine
)将所有构造函数初始值设定项放在当前行(如果合适)。否则,将每个都放在自己的行上。Constructor() : a(), b() Constructor() : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd()
PCIS_NextLine
(in configuration:NextLine
) Same asPCIS_CurrentLine
except that if all constructor initializers do not fit on the current line, try to fit them on the next line.
PCIS_NextLine
(在配置中:NextLine
)与PCIS_CurrentLine
相同,只是如果所有构造函数初始值设定项不适合当前行,请尝试将它们适合下一行。Constructor() : a(), b() Constructor() : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd() Constructor() : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), cccccccccccccccccccc()
PCIS_NextLineOnly
(in configuration:NextLineOnly
) Put all constructor initializers on the next line if they fit. Otherwise, put each one on its own line.
PCIS_NextLineOnly
(在配置中:NextLineOnly
)将所有构造函数初始值设定项放在下一行(如果合适)。否则,将每个都放在自己的行上。Constructor() : a(), b() Constructor() : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), ddddddddddddd() Constructor() : aaaaaaaaaaaaaaaaaaaa(), bbbbbbbbbbbbbbbbbbbb(), cccccccccccccccccccc()
- PenaltyBreakAssignment (
Unsigned
) clang-format 5 ¶ The penalty for breaking around an assignment operator.
破坏赋值运算符的惩罚。
- PenaltyBreakBeforeFirstCallParameter (
Unsigned
) clang-format 3.7 ¶ The penalty for breaking a function call after
call(
.
在call(
之后中断函数调用的惩罚。
- PenaltyBreakComment (
Unsigned
) clang-format 3.7 ¶ The penalty for each line break introduced inside a comment.
评论中介绍了每次换行的惩罚。
- PenaltyBreakFirstLessLess (
Unsigned
) clang-format 3.7 ¶ The penalty for breaking before the first
<<
.
在第一个<<
之前打破的惩罚。
- PenaltyBreakOpenParenthesis (
Unsigned
) clang-format 14 ¶ The penalty for breaking after
(
.
(
之后中断的惩罚。
- PenaltyBreakScopeResolution (
Unsigned
) clang-format 18 ¶ The penalty for breaking after
::
.
::
之后中断的惩罚。
- PenaltyBreakString (
Unsigned
) clang-format 3.7 ¶ The penalty for each line break introduced inside a string literal.
字符串文字中引入的每个换行符的惩罚。
- PenaltyBreakTemplateDeclaration (
Unsigned
) clang-format 7 ¶ The penalty for breaking after template declaration.
模板声明后破坏的惩罚。
- PenaltyExcessCharacter (
Unsigned
) clang-format 3.7 ¶ The penalty for each character outside of the column limit.
超出列限制的每个字符的惩罚。
- PenaltyIndentedWhitespace (
Unsigned
) clang-format 12 ¶ Penalty for each character of whitespace indentation (counted relative to leading non-whitespace column).
空白缩进的每个字符的惩罚(相对于前导非空白列计算)。
- PenaltyReturnTypeOnItsOwnLine (
Unsigned
) clang-format 3.7 ¶ Penalty for putting the return type of a function onto its own line.
将函数的返回类型放在自己的行上的惩罚。
- PointerAlignment (
PointerAlignmentStyle
) clang-format 3.7 ¶
指针对齐 (PointerAlignmentStyle
) clang-format 3.7 ¶ Pointer and reference alignment style.
指针和参考对齐样式。Possible values: 可能的值:
PAS_Left
(in configuration:Left
) Align pointer to the left.
PAS_Left
(在配置中:Left
)将指针向左对齐。int* a;
PAS_Right
(in configuration:Right
) Align pointer to the right.
PAS_Right
(在配置中:Right
)将指针向右对齐。int *a;
PAS_Middle
(in configuration:Middle
) Align pointer in the middle.
PAS_Middle
(在配置中:Middle
)将指针居中对齐。int * a;
- QualifierAlignment (
QualifierAlignmentStyle
) clang-format 14 ¶ Different ways to arrange specifiers and qualifiers (e.g. const/volatile).
排列说明符和限定符的不同方式(例如 const/volatile)。Warning 警告
Setting
QualifierAlignment
to something other thanLeave
, COULD lead to incorrect code formatting due to incorrect decisions made due to clang-formats lack of complete semantic information. As such extra care should be taken to review code changes made by the use of this option.
将QualifierAlignment
设置为Leave
之外的其他内容,可能会导致由于 clang-formats 缺乏完整语义信息而做出的错误决定,导致代码格式不正确。因此,应格外小心地检查使用此选项所做的代码更改。Possible values: 可能的值:
QAS_Leave
(in configuration:Leave
) Don’t change specifiers/qualifiers to either Left or Right alignment (default).
QAS_Leave
(在配置中:Leave
)不要将说明符/限定符更改为左对齐或右对齐(默认)。int const a; const int *a;
QAS_Left
(in configuration:Left
) Change specifiers/qualifiers to be left-aligned.
QAS_Left
(在配置中:Left
)将说明符/限定符更改为左对齐。const int a; const int *a;
QAS_Right
(in configuration:Right
) Change specifiers/qualifiers to be right-aligned.
QAS_Right
(在配置中:Right
)将说明符/限定符更改为右对齐。int const a; int const *a;
QAS_Custom
(in configuration:Custom
) Change specifiers/qualifiers to be aligned based onQualifierOrder
. With:
QAS_Custom
(在配置中:Custom
)更改说明符/限定符以基于QualifierOrder
对齐。和:QualifierOrder: ['inline', 'static', 'type', 'const']
int const a; int const *a;
- QualifierOrder (
List of Strings
) clang-format 14 ¶ The order in which the qualifiers appear. Order is an array that can contain any of the following:
限定符出现的顺序。 Order 是一个数组,可以包含以下任意内容:const 常量
inline 排队
static 静止的
friend 朋友
constexpr 常量表达式
volatile 易挥发的
restrict 限制
type 类型
Note 笔记
it MUST contain ‘type’.
它必须包含“类型”。Items to the left of ‘type’ will be placed to the left of the type and aligned in the order supplied. Items to the right of ‘type’ will be placed to the right of the type and aligned in the order supplied.
“类型”左侧的项目将放置在类型的左侧,并按照提供的顺序对齐。 “类型”右侧的项目将放置在类型的右侧,并按提供的顺序对齐。QualifierOrder: ['inline', 'static', 'type', 'const', 'volatile' ]
- RawStringFormats (
List of RawStringFormats
) clang-format 6 ¶ Defines hints for detecting supported languages code blocks in raw strings.
定义用于检测原始字符串中支持的语言代码块的提示。A raw string with a matching delimiter or a matching enclosing function name will be reformatted assuming the specified language based on the style for that language defined in the .clang-format file. If no style has been defined in the .clang-format file for the specific language, a predefined style given by ‘BasedOnStyle’ is used. If ‘BasedOnStyle’ is not found, the formatting is based on llvm style. A matching delimiter takes precedence over a matching enclosing function name for determining the language of the raw string contents.
具有匹配分隔符或匹配封闭函数名称的原始字符串将根据 .clang-format 文件中定义的语言样式重新格式化,假设指定语言。如果 .clang-format 文件中没有为特定语言定义样式,则使用“BasedOnStyle”给出的预定义样式。如果未找到“BasedOnStyle”,则格式化基于 llvm 样式。匹配的分隔符优先于匹配的封闭函数名称来确定原始字符串内容的语言。If a canonical delimiter is specified, occurrences of other delimiters for the same language will be updated to the canonical if possible.
如果指定了规范分隔符,则在可能的情况下,出现的同一语言的其他分隔符将更新为规范分隔符。There should be at most one specification per language and each delimiter and enclosing function should not occur in multiple specifications.
每种语言最多应有一个规范,并且每个分隔符和封闭函数不应出现在多个规范中。To configure this in the .clang-format file, use:
要在 .clang-format 文件中进行配置,请使用:RawStringFormats: - Language: TextProto Delimiters: - 'pb' - 'proto' EnclosingFunctions: - 'PARSE_TEXT_PROTO' BasedOnStyle: google - Language: Cpp Delimiters: - 'cc' - 'cpp' BasedOnStyle: llvm CanonicalDelimiter: 'cc'
- ReferenceAlignment (
ReferenceAlignmentStyle
) clang-format 13 ¶ Reference alignment style (overrides
PointerAlignment
for references).
引用对齐样式(覆盖引用的PointerAlignment
)。Possible values: 可能的值:
RAS_Pointer
(in configuration:Pointer
) Align reference likePointerAlignment
.
RAS_Pointer
(在配置中:Pointer
)像PointerAlignment
一样对齐引用。RAS_Left
(in configuration:Left
) Align reference to the left.
RAS_Left
(在配置中:Left
)将引用左对齐。int& a;
RAS_Right
(in configuration:Right
) Align reference to the right.
RAS_Right
(在配置中:Right
)将引用向右对齐。int &a;
RAS_Middle
(in configuration:Middle
) Align reference in the middle.
RAS_Middle
(在配置中:Middle
)在中间对齐参考。int & a;
- ReflowComments (
Boolean
) clang-format 3.8 ¶
回流注释 (Boolean
) clang-format 3.8 ¶ If
true
, clang-format will attempt to re-flow comments. That is it will touch a comment and reflow long comments into new lines, trying to obey theColumnLimit
.
如果true
,clang-format 将尝试重新排列注释。也就是说,它将触及注释并将长注释回流到新行中,尝试遵守ColumnLimit
。false: // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of information */ true: // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of // information /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of * information */
- RemoveBracesLLVM (
Boolean
) clang-format 14 ¶
删除括号LLVM (Boolean
) clang-format 14 ¶ Remove optional braces of control statements (
if
,else
,for
, andwhile
) in C++ according to the LLVM coding style.
根据 LLVM 编码风格,删除 C++ 中控制语句的可选大括号(if
、else
、for
和while
)。Warning 警告
This option will be renamed and expanded to support other styles.
该选项将被重命名并扩展以支持其他样式。Warning 警告
Setting this option to
true
could lead to incorrect code formatting due to clang-format’s lack of complete semantic information. As such, extra care should be taken to review code changes made by this option.
将此选项设置为true
可能会由于 clang-format 缺乏完整的语义信息而导致代码格式不正确。因此,应格外小心地检查此选项所做的代码更改。false: true: if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) handleFunctionDecl(D); handleFunctionDecl(D); } else if (isa<VarDecl>(D)) { else if (isa<VarDecl>(D)) handleVarDecl(D); handleVarDecl(D); } if (isa<VarDecl>(D)) { vs. if (isa<VarDecl>(D)) { for (auto *A : D.attrs()) { for (auto *A : D.attrs()) if (shouldProcessAttr(A)) { if (shouldProcessAttr(A)) handleAttr(A); handleAttr(A); } } } } if (isa<FunctionDecl>(D)) { vs. if (isa<FunctionDecl>(D)) for (auto *A : D.attrs()) { for (auto *A : D.attrs()) handleAttr(A); handleAttr(A); } } if (auto *D = (T)(D)) { vs. if (auto *D = (T)(D)) { if (shouldProcess(D)) { if (shouldProcess(D)) handleVarDecl(D); handleVarDecl(D); } else { else markAsIgnored(D); markAsIgnored(D); } } } if (a) { vs. if (a) b(); b(); } else { else if (c) if (c) { d(); d(); else } else { e(); e(); } }
- RemoveParentheses (
RemoveParenthesesStyle
) clang-format 17 ¶
删除括号 (RemoveParenthesesStyle
) clang-format 17 ¶ Remove redundant parentheses.
删除多余的括号。Warning 警告
Setting this option to any value other than
Leave
could lead to incorrect code formatting due to clang-format’s lack of complete semantic information. As such, extra care should be taken to review code changes made by this option.
由于 clang-format 缺乏完整的语义信息,将此选项设置为Leave
之外的任何值都可能导致代码格式不正确。因此,应格外小心地检查此选项所做的代码更改。Possible values: 可能的值:
RPS_Leave
(in configuration:Leave
) Do not remove parentheses.
RPS_Leave
(在配置中:Leave
)不要删除括号。class __declspec((dllimport)) X {}; co_return (((0))); return ((a + b) - ((c + d)));
RPS_MultipleParentheses
(in configuration:MultipleParentheses
) Replace multiple parentheses with single parentheses.
RPS_MultipleParentheses
(在配置中:MultipleParentheses
)用单括号替换多个括号。class __declspec(dllimport) X {}; co_return (0); return ((a + b) - (c + d));
RPS_ReturnStatement
(in configuration:ReturnStatement
) Also remove parentheses enclosing the expression in areturn
/co_return
statement.
RPS_ReturnStatement
(在配置中:ReturnStatement
)同时删除return
/co_return
语句中包含表达式的括号。class __declspec(dllimport) X {}; co_return 0; return (a + b) - (c + d);
- RemoveSemicolon (
Boolean
) clang-format 16 ¶
删除分号 (Boolean
) clang-format 16 ¶ Remove semicolons after the closing braces of functions and constructors/destructors.
删除函数和构造函数/析构函数右大括号后面的分号。Warning 警告
Setting this option to
true
could lead to incorrect code formatting due to clang-format’s lack of complete semantic information. As such, extra care should be taken to review code changes made by this option.
将此选项设置为true
可能会由于 clang-format 缺乏完整的语义信息而导致代码格式不正确。因此,应格外小心地检查此选项所做的代码更改。false: true: int max(int a, int b) { int max(int a, int b) { return a > b ? a : b; return a > b ? a : b; }; }
- RequiresClausePosition (
RequiresClausePositionStyle
) clang-format 15 ¶ The position of the
requires
clause.
requires
子句的位置。Possible values: 可能的值:
RCPS_OwnLine
(in configuration:OwnLine
) Always put therequires
clause on its own line.
RCPS_OwnLine
(在配置中:OwnLine
)始终将requires
子句放在自己的行上。template <typename T> requires C<T> struct Foo {... template <typename T> requires C<T> void bar(T t) {... template <typename T> void baz(T t) requires C<T> {...
RCPS_WithPreceding
(in configuration:WithPreceding
) Try to put the clause together with the preceding part of a declaration. For class templates: stick to the template declaration. For function templates: stick to the template declaration. For function declaration followed by a requires clause: stick to the parameter list.
RCPS_WithPreceding
(在配置中:WithPreceding
)尝试将该子句与声明的前面部分放在一起。对于类模板:坚持模板声明。对于函数模板:坚持模板声明。对于后跟 require 子句的函数声明:坚持参数列表。template <typename T> requires C<T> struct Foo {... template <typename T> requires C<T> void bar(T t) {... template <typename T> void baz(T t) requires C<T> {...
RCPS_WithFollowing
(in configuration:WithFollowing
) Try to put therequires
clause together with the class or function declaration.
RCPS_WithFollowing
(在配置中:WithFollowing
)尝试将requires
子句与类或函数声明放在一起。template <typename T> requires C<T> struct Foo {... template <typename T> requires C<T> void bar(T t) {... template <typename T> void baz(T t) requires C<T> {...
RCPS_SingleLine
(in configuration:SingleLine
) Try to put everything in the same line if possible. Otherwise normal line breaking rules take over.
RCPS_SingleLine
(在配置中:SingleLine
)如果可能的话,尝试将所有内容放在同一行中。否则正常的换行规则将被接管。// Fitting: template <typename T> requires C<T> struct Foo {... template <typename T> requires C<T> void bar(T t) {... template <typename T> void bar(T t) requires C<T> {... // Not fitting, one possible example: template <typename LongName> requires C<LongName> struct Foo {... template <typename LongName> requires C<LongName> void bar(LongName ln) { template <typename LongName> void bar(LongName ln) requires C<LongName> {
- RequiresExpressionIndentation (
RequiresExpressionIndentationKind
) clang-format 16 ¶
需要ExpressionIndentation (RequiresExpressionIndentationKind
) clang-format 16 ¶ The indentation used for requires expression bodies.
用于的缩进需要表达式主体。Possible values: 可能的值:
REI_OuterScope
(in configuration:OuterScope
) Align requires expression body relative to the indentation level of the outer scope the requires expression resides in. This is the default.
REI_OuterScope
(在配置中:OuterScope
)将需要表达式主体相对于需要表达式所在的外部范围的缩进级别对齐。这是默认设置。template <typename T> concept C = requires(T t) { ... }
REI_Keyword
(in configuration:Keyword
) Align requires expression body relative to therequires
keyword.
REI_Keyword
(在配置中:Keyword
)对齐需要相对于requires
关键字的表达式主体。template <typename T> concept C = requires(T t) { ... }
- SeparateDefinitionBlocks (
SeparateDefinitionStyle
) clang-format 14 ¶
分离定义块 (SeparateDefinitionStyle
) clang-format 14 ¶ Specifies the use of empty lines to separate definition blocks, including classes, structs, enums, and functions.
指定使用空行来分隔定义块,包括类、结构、枚举和函数。Never v.s. Always #include <cstring> #include <cstring> struct Foo { int a, b, c; struct Foo { }; int a, b, c; namespace Ns { }; class Bar { public: namespace Ns { struct Foobar { class Bar { int a; public: int b; struct Foobar { }; int a; private: int b; int t; }; int method1() { // ... private: } int t; enum List { ITEM1, int method1() { ITEM2 // ... }; } template<typename T> int method2(T x) { enum List { // ... ITEM1, } ITEM2 int i, j, k; }; int method3(int par) { // ... template<typename T> } int method2(T x) { }; // ... class C {}; } } int i, j, k; int method3(int par) { // ... } }; class C {}; }
Possible values: 可能的值:
SDS_Leave
(in configuration:Leave
) Leave definition blocks as they are.
SDS_Leave
(在配置中:Leave
)保留定义块不变。SDS_Always
(in configuration:Always
) Insert an empty line between definition blocks.
SDS_Always
(在配置中:Always
)在定义块之间插入空行。SDS_Never
(in configuration:Never
) Remove any empty line between definition blocks.
SDS_Never
(在配置中:Never
)删除定义块之间的任何空行。
- ShortNamespaceLines (
Unsigned
) clang-format 13 ¶ The maximal number of unwrapped lines that a short namespace spans. Defaults to 1.
短命名空间跨越的最大展开行数。默认为 1。This determines the maximum length of short namespaces by counting unwrapped lines (i.e. containing neither opening nor closing namespace brace) and makes “FixNamespaceComments” omit adding end comments for those.
这通过计算展开的行(即既不包含开始也不包含结束命名空间大括号)来确定短命名空间的最大长度,并使“FixNamespaceComments”省略为这些行添加结束注释。ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 namespace a { namespace a { int foo; int foo; } } // namespace a ShortNamespaceLines: 1 vs. ShortNamespaceLines: 0 namespace b { namespace b { int foo; int foo; int bar; int bar; } // namespace b } // namespace b
- SkipMacroDefinitionBody (
Boolean
) clang-format 18 ¶ Do not format macro definition body.
不要格式化宏定义体。
- SortIncludes (
SortIncludesOptions
) clang-format 3.8 ¶
排序包含 (SortIncludesOptions
) clang-format 3.8 ¶ Controls if and how clang-format will sort
#includes
.
控制 clang-format 是否以及如何排序#includes
。Possible values: 可能的值:
SI_Never
(in configuration:Never
) Includes are never sorted.
SI_Never
(在配置中:Never
)包含永远不会排序。#include "B/A.h" #include "A/B.h" #include "a/b.h" #include "A/b.h" #include "B/a.h"
SI_CaseSensitive
(in configuration:CaseSensitive
) Includes are sorted in an ASCIIbetical or case sensitive fashion.
SI_CaseSensitive
(在配置中:CaseSensitive
)包含内容以 ASCII 或区分大小写的方式排序。#include "A/B.h" #include "A/b.h" #include "B/A.h" #include "B/a.h" #include "a/b.h"
SI_CaseInsensitive
(in configuration:CaseInsensitive
) Includes are sorted in an alphabetical or case insensitive fashion.
SI_CaseInsensitive
(在配置中:CaseInsensitive
)包含内容按字母顺序或不区分大小写的方式排序。#include "A/B.h" #include "A/b.h" #include "a/b.h" #include "B/A.h" #include "B/a.h"
- SortJavaStaticImport (
SortJavaStaticImportOptions
) clang-format 12 ¶ When sorting Java imports, by default static imports are placed before non-static imports. If
JavaStaticImportAfterImport
isAfter
, static imports are placed after non-static imports.
对 Java 导入进行排序时,默认情况下静态导入位于非静态导入之前。如果JavaStaticImportAfterImport
为After
,则静态导入将放置在非静态导入之后。Possible values: 可能的值:
SJSIO_Before
(in configuration:Before
) Static imports are placed before non-static imports.
SJSIO_Before
(在配置中:Before
)静态导入放置在非静态导入之前。import static org.example.function1; import org.example.ClassA;
SJSIO_After
(in configuration:After
) Static imports are placed after non-static imports.
SJSIO_After
(在配置中:After
)静态导入放置在非静态导入之后。import org.example.ClassA; import static org.example.function1;
- SortUsingDeclarations (
SortUsingDeclarationsOptions
) clang-format 5 ¶ Controls if and how clang-format will sort using declarations.
控制 clang-format 是否以及如何使用声明进行排序。Possible values: 可能的值:
SUD_Never
(in configuration:Never
) Using declarations are never sorted.
SUD_Never
(在配置中:Never
)使用声明永远不会排序。using std::chrono::duration_cast; using std::move; using boost::regex; using boost::regex_constants::icase; using std::string;
SUD_Lexicographic
(in configuration:Lexicographic
) Using declarations are sorted in the order defined as follows: Split the strings by “::” and discard any initial empty strings. Sort the lists of names lexicographically, and within those groups, names are in case-insensitive lexicographic order.
SUD_Lexicographic
(在配置中:Lexicographic
)使用声明按如下定义的顺序排序:用“::”分割字符串并丢弃任何初始空字符串。按字典顺序对名称列表进行排序,并且在这些组中,名称按不区分大小写的字典顺序排列。using boost::regex; using boost::regex_constants::icase; using std::chrono::duration_cast; using std::move; using std::string;
SUD_LexicographicNumeric
(in configuration:LexicographicNumeric
) Using declarations are sorted in the order defined as follows: Split the strings by “::” and discard any initial empty strings. The last element of each list is a non-namespace name; all others are namespace names. Sort the lists of names lexicographically, where the sort order of individual names is that all non-namespace names come before all namespace names, and within those groups, names are in case-insensitive lexicographic order.
SUD_LexicographicNumeric
(在配置中:LexicographicNumeric
)使用声明按如下定义的顺序排序:用“::”分割字符串并丢弃任何初始空字符串。每个列表的最后一个元素是非命名空间名称;所有其他都是名称空间名称。按字典顺序对名称列表进行排序,其中各个名称的排序顺序是所有非命名空间名称都位于所有命名空间名称之前,并且在这些组中,名称按不区分大小写的字典顺序排列。using boost::regex; using boost::regex_constants::icase; using std::move; using std::string; using std::chrono::duration_cast;
- SpaceAfterCStyleCast (
Boolean
) clang-format 3.5 ¶ If
true
, a space is inserted after C style casts.
如果true
,则在 C 样式转换后插入一个空格。true: false: (int) i; vs. (int)i;
- SpaceAfterLogicalNot (
Boolean
) clang-format 9 ¶ If
true
, a space is inserted after the logical not operator (!
).
如果是true
,则在逻辑非运算符 (!
) 之后插入一个空格。true: false: ! someExpression(); vs. !someExpression();
- SpaceAfterTemplateKeyword (
Boolean
) clang-format 4 ¶ If
true
, a space will be inserted after the ‘template’ keyword.
如果true
,则在“template”关键字后面插入一个空格。true: false: template <int> void foo(); vs. template<int> void foo();
- SpaceAroundPointerQualifiers (
SpaceAroundPointerQualifiersStyle
) clang-format 12 ¶ Defines in which cases to put a space before or after pointer qualifiers
定义在什么情况下在指针限定符之前或之后放置空格Possible values: 可能的值:
SAPQ_Default
(in configuration:Default
) Don’t ensure spaces around pointer qualifiers and use PointerAlignment instead.
SAPQ_Default
(在配置中:Default
)不要确保指针限定符周围有空格,而是使用 PointerAlignment 。PointerAlignment: Left PointerAlignment: Right void* const* x = NULL; vs. void *const *x = NULL;
SAPQ_Before
(in configuration:Before
) Ensure that there is a space before pointer qualifiers.
SAPQ_Before
(在配置中:Before
)确保指针限定符之前有一个空格。PointerAlignment: Left PointerAlignment: Right void* const* x = NULL; vs. void * const *x = NULL;
SAPQ_After
(in configuration:After
) Ensure that there is a space after pointer qualifiers.
SAPQ_After
(在配置中:After
)确保指针限定符后面有一个空格。PointerAlignment: Left PointerAlignment: Right void* const * x = NULL; vs. void *const *x = NULL;
SAPQ_Both
(in configuration:Both
) Ensure that there is a space both before and after pointer qualifiers.
SAPQ_Both
(在配置中:Both
)确保指针限定符前后都有空格。PointerAlignment: Left PointerAlignment: Right void* const * x = NULL; vs. void * const *x = NULL;
- SpaceBeforeAssignmentOperators (
Boolean
) clang-format 3.7 ¶ If
false
, spaces will be removed before assignment operators.
如果false
,则赋值运算符之前的空格将被删除。true: false: int a = 5; vs. int a= 5; a += 42; a+= 42;
- SpaceBeforeCaseColon (
Boolean
) clang-format 12 ¶ If
false
, spaces will be removed before case colon.
如果false
,则冒号前的空格将被删除。true: false switch (x) { vs. switch (x) { case 1 : break; case 1: break; } }
- SpaceBeforeCpp11BracedList (
Boolean
) clang-format 7 ¶
SpaceBeforeCpp11BrcedList (Boolean
) clang-format 7 ¶ If
true
, a space will be inserted before a C++11 braced list used to initialize an object (after the preceding identifier or type).
如果true
,则在用于初始化对象的 C++11 大括号列表之前(在前面的标识符或类型之后)插入一个空格。true: false: Foo foo { bar }; vs. Foo foo{ bar }; Foo {}; Foo{}; vector<int> { 1, 2, 3 }; vector<int>{ 1, 2, 3 }; new int[3] { 1, 2, 3 }; new int[3]{ 1, 2, 3 };
- SpaceBeforeCtorInitializerColon (
Boolean
) clang-format 7 ¶ If
false
, spaces will be removed before constructor initializer colon.
如果false
,构造函数初始化冒号之前的空格将被删除。true: false: Foo::Foo() : a(a) {} Foo::Foo(): a(a) {}
- SpaceBeforeInheritanceColon (
Boolean
) clang-format 7 ¶ If
false
, spaces will be removed before inheritance colon.
如果false
,继承冒号之前的空格将被删除。true: false: class Foo : Bar {} vs. class Foo: Bar {}
- SpaceBeforeJsonColon (
Boolean
) clang-format 17 ¶ If
true
, a space will be added before a JSON colon. For other languages, e.g. JavaScript, useSpacesInContainerLiterals
instead.
如果true
,则在 JSON 冒号之前添加一个空格。对于其他语言,例如JavaScript,请改用SpacesInContainerLiterals
。true: false: { { "key" : "value" vs. "key": "value" } }
- SpaceBeforeParens (
SpaceBeforeParensStyle
) clang-format 3.5 ¶ Defines in which cases to put a space before opening parentheses.
定义在什么情况下在左括号前放置空格。Possible values: 可能的值:
SBPO_Never
(in configuration:Never
) This is deprecated and replaced byCustom
below, with allSpaceBeforeParensOptions
butAfterPlacementOperator
set tofalse
.
SBPO_Never
(在配置中:Never
)这已被弃用并被下面的Custom
取代,除了AfterPlacementOperator
> 设置为false
。SBPO_ControlStatements
(in configuration:ControlStatements
) Put a space before opening parentheses only after control statement keywords (for/if/while...
).
SBPO_ControlStatements
(在配置中:ControlStatements
)仅在控制语句关键字(for/if/while...
)之后的左括号前放置一个空格。void f() { if (true) { f(); } }
SBPO_ControlStatementsExceptControlMacros
(in configuration:ControlStatementsExceptControlMacros
) Same asSBPO_ControlStatements
except this option doesn’t apply to ForEach and If macros. This is useful in projects where ForEach/If macros are treated as function calls instead of control statements.SBPO_ControlStatementsExceptForEachMacros
remains an alias for backward compatibility.
SBPO_ControlStatementsExceptControlMacros
(在配置中:ControlStatementsExceptControlMacros
)与SBPO_ControlStatements
相同,但此选项不适用于 ForEach 和 If 宏。这在 ForEach/If 宏被视为函数调用而不是控制语句的项目中非常有用。SBPO_ControlStatementsExceptForEachMacros
保留别名以实现向后兼容性。void f() { Q_FOREACH(...) { f(); } }
SBPO_NonEmptyParentheses
(in configuration:NonEmptyParentheses
) Put a space before opening parentheses only if the parentheses are not empty i.e. ‘()’
SBPO_NonEmptyParentheses
(在配置中:NonEmptyParentheses
)仅当括号不为空时才在左括号前添加空格,即“()”void() { if (true) { f(); g (x, y, z); } }
SBPO_Always
(in configuration:Always
) Always put a space before opening parentheses, except when it’s prohibited by the syntax rules (in function-like macro definitions) or when determined by other style rules (after unary operators, opening parentheses, etc.)
SBPO_Always
(在配置中:Always
)始终在左括号前放置一个空格,除非语法规则(在类似函数的宏定义中)禁止或由其他样式规则确定(在一元运算符、左括号等之后)void f () { if (true) { f (); } }
SBPO_Custom
(in configuration:Custom
) Configure each individual space before parentheses inSpaceBeforeParensOptions
.
SBPO_Custom
(在配置中:Custom
)在SpaceBeforeParensOptions
中的括号前配置每个单独的空格。
- SpaceBeforeParensOptions (
SpaceBeforeParensCustom
) clang-format 14 ¶ Control of individual space before parentheses.
控制括号前的单独空格。If
SpaceBeforeParens
is set toCustom
, use this to specify how each individual space before parentheses case should be handled. Otherwise, this is ignored.
如果SpaceBeforeParens
设置为Custom
,则使用它来指定如何处理括号大小写之前的每个单独空格。否则,这将被忽略。# Example of usage: SpaceBeforeParens: Custom SpaceBeforeParensOptions: AfterControlStatements: true AfterFunctionDefinitionName: true
Nested configuration flags:
嵌套配置标志:Precise control over the spacing before parentheses.
精确控制括号前的间距。# Should be declared this way: SpaceBeforeParens: Custom SpaceBeforeParensOptions: AfterControlStatements: true AfterFunctionDefinitionName: true
bool AfterControlStatements
Iftrue
, put space between control statement keywords (for/if/while…) and opening parentheses.
bool AfterControlStatements
如果true
,则在控制语句关键字(for/if/while...)和左括号之间添加空格。true: false: if (...) {} vs. if(...) {}
bool AfterForeachMacros
Iftrue
, put space between foreach macros and opening parentheses.
bool AfterForeachMacros
如果true
,则在 foreach 宏和左括号之间添加空格。true: false: FOREACH (...) vs. FOREACH(...) <loop-body> <loop-body>
bool AfterFunctionDeclarationName
Iftrue
, put a space between function declaration name and opening parentheses.
bool AfterFunctionDeclarationName
如果true
,则在函数声明名称和左括号之间放置一个空格。true: false: void f (); vs. void f();
bool AfterFunctionDefinitionName
Iftrue
, put a space between function definition name and opening parentheses.
bool AfterFunctionDefinitionName
如果true
,则在函数定义名称和左括号之间放置一个空格。true: false: void f () {} vs. void f() {}
bool AfterIfMacros
Iftrue
, put space between if macros and opening parentheses.
bool AfterIfMacros
如果true
,则在 if 宏和左括号之间添加空格。true: false: IF (...) vs. IF(...) <conditional-body> <conditional-body>
bool AfterOverloadedOperator
Iftrue
, put a space between operator overloading and opening parentheses.
bool AfterOverloadedOperator
如果true
,则在运算符重载和左括号之间放置一个空格。true: false: void operator++ (int a); vs. void operator++(int a); object.operator++ (10); object.operator++(10);
bool AfterPlacementOperator
Iftrue
, put a space between operatornew
/delete
and opening parenthesis.
bool AfterPlacementOperator
如果true
,则在运算符new
/delete
和左括号之间放置一个空格。true: false: new (buf) T; vs. new(buf) T; delete (buf) T; delete(buf) T;
bool AfterRequiresInClause
Iftrue
, put space between requires keyword in a requires clause and opening parentheses, if there is one.
bool AfterRequiresInClause
如果true
,则在requires子句中的requires关键字和左括号(如果有)之间放置空格。true: false: template<typename T> vs. template<typename T> requires (A<T> && B<T>) requires(A<T> && B<T>) ... ...
bool AfterRequiresInExpression
Iftrue
, put space between requires keyword in a requires expression and opening parentheses.
bool AfterRequiresInExpression
如果true
,则在requires表达式中的requires关键字和左括号之间放置空格。true: false: template<typename T> vs. template<typename T> concept C = requires (T t) { concept C = requires(T t) { ... ... } }
bool BeforeNonEmptyParentheses
Iftrue
, put a space before opening parentheses only if the parentheses are not empty.
bool BeforeNonEmptyParentheses
如果true
,仅当括号不为空时,才在左括号前添加一个空格。true: false: void f (int a); vs. void f(); f (a); f();
- SpaceBeforeRangeBasedForLoopColon (
Boolean
) clang-format 7 ¶ If
false
, spaces will be removed before range-based for loop colon.
如果false
,则基于范围的 for 循环冒号之前的空格将被删除。true: false: for (auto v : values) {} vs. for(auto v: values) {}
- SpaceBeforeSquareBrackets (
Boolean
) clang-format 10 ¶ If
true
, spaces will be before[
. Lambdas will not be affected. Only the first[
will get a space added.
如果true
,空格将在[
之前。 Lambda 不会受到影响。只有第一个[
才会添加空格。true: false: int a [5]; vs. int a[5]; int a [5][5]; vs. int a[5][5];
- SpaceInEmptyBlock (
Boolean
) clang-format 10 ¶ If
true
, spaces will be inserted into{}
.
如果是true
,则{}
中将插入空格。true: false: void f() { } vs. void f() {} while (true) { } while (true) {}
- SpaceInEmptyParentheses (
Boolean
) clang-format 3.7 ¶ If
true
, spaces may be inserted into()
. This option is deprecated. SeeInEmptyParentheses
ofSpacesInParensOptions
.
如果是true
,则可以在()
中插入空格。此选项已弃用。请参阅SpacesInParensOptions
的InEmptyParentheses
。
- SpacesBeforeTrailingComments (
Unsigned
) clang-format 3.7 ¶ The number of spaces before trailing line comments (
//
- comments).
尾随行注释之前的空格数(//
- 注释)。This does not affect trailing block comments (
/*
- comments) as those commonly have different usage patterns and a number of special cases. In the case of Verilog, it doesn’t affect a comment right after the opening parenthesis in the port or parameter list in a module header, because it is probably for the port on the following line instead of the parenthesis it follows.
这不会影响尾随块注释(/*
- 注释),因为它们通常具有不同的使用模式和许多特殊情况。在 Verilog 的情况下,它不会影响模块头中端口或参数列表中左括号之后的注释,因为它可能是针对下一行的端口而不是它后面的括号。SpacesBeforeTrailingComments: 3 void f() { if (true) { // foo1 f(); // bar } // foo }
- SpacesInAngles (
SpacesInAnglesStyle
) clang-format 3.4 ¶ The SpacesInAnglesStyle to use for template argument lists.
用于模板参数列表的 SpacesInAnglesStyle。Possible values: 可能的值:
SIAS_Never
(in configuration:Never
) Remove spaces after<
and before>
.
SIAS_Never
(在配置中:Never
)删除<
之后和>
之前的空格。static_cast<int>(arg); std::function<void(int)> fct;
SIAS_Always
(in configuration:Always
) Add spaces after<
and before>
.
SIAS_Always
(在配置中:Always
)在<
之后和>
之前添加空格。static_cast< int >(arg); std::function< void(int) > fct;
SIAS_Leave
(in configuration:Leave
) Keep a single space after<
and before>
if any spaces were present. OptionStandard: Cpp03
takes precedence.
SIAS_Leave
(在配置中:Leave
)如果存在任何空格,请在<
之后和>
之前保留一个空格。选项Standard: Cpp03
优先。
- SpacesInCStyleCastParentheses (
Boolean
) clang-format 3.7 ¶ If
true
, spaces may be inserted into C style casts. This option is deprecated. SeeInCStyleCasts
ofSpacesInParensOptions
.
如果true
,则可以将空格插入到 C 样式转换中。此选项已弃用。请参阅SpacesInParensOptions
的InCStyleCasts
。
- SpacesInConditionalStatement (
Boolean
) clang-format 10 ¶ If
true
, spaces will be inserted around if/for/switch/while conditions. This option is deprecated. SeeInConditionalStatements
ofSpacesInParensOptions
.
如果true
,则 if/for/switch/while 条件周围将插入空格。此选项已弃用。请参阅SpacesInParensOptions
的InConditionalStatements
。
- SpacesInContainerLiterals (
Boolean
) clang-format 3.7 ¶ If
true
, spaces are inserted inside container literals (e.g. ObjC and Javascript array and dict literals). For JSON, useSpaceBeforeJsonColon
instead.
如果true
,空格将插入到容器文字中(例如 ObjC 和 Javascript 数组和字典文字)。对于 JSON,请改用SpaceBeforeJsonColon
。true: false: var arr = [ 1, 2, 3 ]; vs. var arr = [1, 2, 3]; f({a : 1, b : 2, c : 3}); f({a: 1, b: 2, c: 3});
- SpacesInLineCommentPrefix (
SpacesInLineComment
) clang-format 13 ¶ How many spaces are allowed at the start of a line comment. To disable the maximum set it to
-1
, apart from that the maximum takes precedence over the minimum.
行注释开头允许有多少个空格。要禁用最大值,请将其设置为-1
,除此之外,最大值优先于最小值。Minimum = 1 Maximum = -1 // One space is forced // but more spaces are possible Minimum = 0 Maximum = 0 //Forces to start every comment directly after the slashes
Note that in line comment sections the relative indent of the subsequent lines is kept, that means the following:
请注意,在行注释部分中,保留后续行的相对缩进,这意味着:before: after: Minimum: 1 //if (b) { // if (b) { // return true; // return true; //} // } Maximum: 0 /// List: ///List: /// - Foo /// - Foo /// - Bar /// - Bar
This option has only effect if
ReflowComments
is set totrue
.
仅当ReflowComments
设置为true
时,此选项才有效。Nested configuration flags:
嵌套配置标志:Control of spaces within a single line comment.
控制单行注释中的空格。unsigned Minimum
The minimum number of spaces at the start of the comment.
unsigned Minimum
注释开头的最小空格数。unsigned Maximum
The maximum number of spaces at the start of the comment.
unsigned Maximum
注释开头的最大空格数。
- SpacesInParens (
SpacesInParensStyle
) clang-format 17 ¶ Defines in which cases spaces will be inserted after
(
and before)
.
定义在什么情况下将在(
之后和)
之前插入空格。Possible values: 可能的值:
SIPO_Never
(in configuration:Never
) Never put a space in parentheses.
SIPO_Never
(在配置中:Never
)切勿在括号中添加空格。void f() { if(true) { f(); } }
SIPO_Custom
(in configuration:Custom
) Configure each individual space in parentheses in SpacesInParensOptions.
SIPO_Custom
(在配置中:Custom
)在 SpacesInParensOptions 的括号中配置每个单独的空间。
- SpacesInParensOptions (
SpacesInParensCustom
) clang-format 17 ¶ Control of individual spaces in parentheses.
控制括号中的各个空格。If
SpacesInParens
is set toCustom
, use this to specify how each individual space in parentheses case should be handled. Otherwise, this is ignored.
如果SpacesInParens
设置为Custom
,则使用它来指定应如何处理括号中的每个单独空格。否则,这将被忽略。# Example of usage: SpacesInParens: Custom SpacesInParensOptions: InConditionalStatements: true InEmptyParentheses: true
Nested configuration flags:
嵌套配置标志:Precise control over the spacing in parentheses.
精确控制括号内的间距。# Should be declared this way: SpacesInParens: Custom SpacesInParensOptions: InConditionalStatements: true Other: true
bool InConditionalStatements
Put a space in parentheses only inside conditional statements (for/if/while/switch...
).
bool InConditionalStatements
仅在条件语句 (for/if/while/switch...
) 内的括号中添加空格。true: false: if ( a ) { ... } vs. if (a) { ... } while ( i < 5 ) { ... } while (i < 5) { ... }
bool InCStyleCasts
Put a space in C style casts.
bool InCStyleCasts
在 C 风格转换中放置一个空格。true: false: x = ( int32 )y vs. x = (int32)y
bool InEmptyParentheses
Put a space in parentheses only if the parentheses are empty i.e. ‘()’
bool InEmptyParentheses
仅当括号为空时才在括号中添加空格,即“()”true: false: void f( ) { vs. void f() { int x[] = {foo( ), bar( )}; int x[] = {foo(), bar()}; if (true) { if (true) { f( ); f(); } } } }
bool Other
Put a space in parentheses not covered by preceding options.
bool Other
在前面的选项未涵盖的括号中放置一个空格。true: false: t f( Deleted & ) & = delete; vs. t f(Deleted &) & = delete;
- SpacesInParentheses (
Boolean
) clang-format 3.7 ¶
括号内的空格 (Boolean
) clang-format 3.7 ¶ If
true
, spaces will be inserted after(
and before)
. This option is deprecated. The previous behavior is preserved by usingSpacesInParens
withCustom
and by setting allSpacesInParensOptions
totrue
except forInCStyleCasts
andInEmptyParentheses
.
如果是true
,则在(
之后和)
之前插入空格。此选项已弃用。通过将SpacesInParens
与Custom
一起使用并将除InCStyleCasts
之外的所有SpacesInParensOptions
设置为true
来保留先前的行为和InEmptyParentheses
。
- SpacesInSquareBrackets (
Boolean
) clang-format 3.7 ¶ If
true
, spaces will be inserted after[
and before]
. Lambdas without arguments or unspecified size array declarations will not be affected.
如果是true
,则在[
之后和]
之前插入空格。没有参数或未指定大小的数组声明的 Lambda 不会受到影响。true: false: int a[ 5 ]; vs. int a[5]; std::unique_ptr<int[]> foo() {} // Won't be affected
- Standard (
LanguageStandard
) clang-format 3.7 ¶
标准 (LanguageStandard
) clang-format 3.7 ¶ Parse and format C++ constructs compatible with this standard.
解析和格式化与此标准兼容的 C++ 结构。c++03: latest: vector<set<int> > x; vs. vector<set<int>> x;
Possible values: 可能的值:
LS_Cpp03
(in configuration:c++03
) Parse and format as C++03.Cpp03
is a deprecated alias forc++03
LS_Cpp03
(在配置中:c++03
)解析并格式化为 C++03。Cpp03
是c++03
的已弃用别名LS_Cpp11
(in configuration:c++11
) Parse and format as C++11.
LS_Cpp11
(在配置中:c++11
)解析并格式化为 C++11。LS_Cpp14
(in configuration:c++14
) Parse and format as C++14.
LS_Cpp14
(在配置中:c++14
)解析并格式化为 C++14。LS_Cpp17
(in configuration:c++17
) Parse and format as C++17.
LS_Cpp17
(在配置中:c++17
)解析并格式化为 C++17。LS_Cpp20
(in configuration:c++20
) Parse and format as C++20.
LS_Cpp20
(在配置中:c++20
)解析并格式化为 C++20。LS_Latest
(in configuration:Latest
) Parse and format using the latest supported language version.Cpp11
is a deprecated alias forLatest
LS_Latest
(在配置中:Latest
)使用最新支持的语言版本进行解析和格式化。Cpp11
是Latest
的已弃用别名LS_Auto
(in configuration:Auto
) Automatic detection based on the input.
LS_Auto
(配置中:Auto
)根据输入自动检测。
- StatementAttributeLikeMacros (
List of Strings
) clang-format 12 ¶ Macros which are ignored in front of a statement, as if they were an attribute. So that they are not parsed as identifier, for example for Qts emit.
在语句前面被忽略的宏,就像它们是属性一样。这样它们就不会被解析为标识符,例如 Qts 发出的标识符。AlignConsecutiveDeclarations: true StatementAttributeLikeMacros: [] unsigned char data = 'x'; emit signal(data); // This is parsed as variable declaration. AlignConsecutiveDeclarations: true StatementAttributeLikeMacros: [emit] unsigned char data = 'x'; emit signal(data); // Now it's fine again.
- StatementMacros (
List of Strings
) clang-format 8 ¶
语句宏 (List of Strings
) clang-format 8 ¶ A vector of macros that should be interpreted as complete statements.
应被解释为完整语句的宏向量。Typical macros are expressions, and require a semi-colon to be added; sometimes this is not the case, and this allows to make clang-format aware of such cases.
典型的宏是表达式,需要加分号;有时情况并非如此,这使得 clang-format 能够意识到这种情况。For example: Q_UNUSED 例如:Q_UNUSED
- TabWidth (
Unsigned
) clang-format 3.7 ¶ The number of columns used for tab stops.
用于制表位的列数。
- TableGenBreakInsideDAGArg (
DAGArgStyle
) clang-format 19 ¶
TableGenBreakInsideDAGARg (DAGArgStyle
) clang 格式 19 ¶ The styles of the line break inside the DAGArg in TableGen.
TableGen 中 DAGArg 内部换行的样式。Possible values: 可能的值:
DAS_DontBreak
(in configuration:DontBreak
) Never break inside DAGArg.
DAS_DontBreak
(在配置中:DontBreak
)切勿破坏 DAGArg 内部。let DAGArgIns = (ins i32:$src1, i32:$src2);
DAS_BreakElements
(in configuration:BreakElements
) Break inside DAGArg after each list element but for the last. This aligns to the first element.
DAS_BreakElements
(在配置中:BreakElements
)在每个列表元素之后(但最后一个)在 DAGArg 内中断。这与第一个元素对齐。let DAGArgIns = (ins i32:$src1, i32:$src2);
DAS_BreakAll
(in configuration:BreakAll
) Break inside DAGArg after the operator and the all elements.
DAS_BreakAll
(在配置中:BreakAll
)在运算符和所有元素之后在 DAGArg 内中断。let DAGArgIns = (ins i32:$src1, i32:$src2 );
- TableGenBreakingDAGArgOperators (
List of Strings
) clang-format 19 ¶ Works only when TableGenBreakInsideDAGArg is not DontBreak. The string list needs to consist of identifiers in TableGen. If any identifier is specified, this limits the line breaks by TableGenBreakInsideDAGArg option only on DAGArg values beginning with the specified identifiers.
仅当 TableGenBreakInsideDAGArg 不是 DontBreak 时才有效。字符串列表需要由 TableGen 中的标识符组成。如果指定了任何标识符,则 TableGenBreakInsideDAGArg 选项仅在以指定标识符开头的 DAGArg 值上限制换行符。For example the configuration,
例如配置,TableGenBreakInsideDAGArg: BreakAll TableGenBreakingDAGArgOperators: ['ins', 'outs']
makes the line break only occurs inside DAGArgs beginning with the specified identifiers ‘ins’ and ‘outs’.
使换行符仅出现在以指定标识符“ins”和“outs”开头的 DAGArgs 内。let DAGArgIns = (ins i32:$src1, i32:$src2 ); let DAGArgOtherID = (other i32:$other1, i32:$other2); let DAGArgBang = (!cast<SomeType>("Some") i32:$src1, i32:$src2)
- TypeNames (
List of Strings
) clang-format 17 ¶
类型名称 (List of Strings
) clang-format 17 ¶ A vector of non-keyword identifiers that should be interpreted as type names.
应解释为类型名称的非关键字标识符向量。A
*
,&
, or&&
between a type name and another non-keyword identifier is annotated as a pointer or reference token instead of a binary operator.
类型名称和另一个非关键字标识符之间的*
、&
或&&
被注释为指针或引用标记,而不是二元运算符。
- TypenameMacros (
List of Strings
) clang-format 9 ¶
类型名称宏 (List of Strings
) clang-format 9 ¶ A vector of macros that should be interpreted as type declarations instead of as function calls.
宏向量,应解释为类型声明而不是函数调用。These are expected to be macros of the form:
这些预计是以下形式的宏:STACK_OF(...)
In the .clang-format configuration file, this can be configured like:
在 .clang-format 配置文件中,可以这样配置:TypenameMacros: ['STACK_OF', 'LIST']
For example: OpenSSL STACK_OF, BSD LIST_ENTRY.
例如:OpenSSL STACK_OF、BSD LIST_ENTRY。
- UseCRLF (
Boolean
) clang-format 10 ¶
使用CRLF (Boolean
) clang-format 10 ¶ This option is deprecated. See
LF
andCRLF
ofLineEnding
.
此选项已弃用。请参阅LineEnding
的LF
和CRLF
。
- UseTab (
UseTabStyle
) clang-format 3.7 ¶ The way to use tab characters in the resulting file.
在结果文件中使用制表符的方式。Possible values: 可能的值:
UT_Never
(in configuration:Never
) Never use tab.
UT_Never
(在配置中:Never
)切勿使用制表符。UT_ForIndentation
(in configuration:ForIndentation
) Use tabs only for indentation.
UT_ForIndentation
(在配置中:ForIndentation
)仅使用制表符进行缩进。UT_ForContinuationAndIndentation
(in configuration:ForContinuationAndIndentation
) Fill all leading whitespace with tabs, and use spaces for alignment that appears within a line (e.g. consecutive assignments and declarations).
UT_ForContinuationAndIndentation
(在配置中:ForContinuationAndIndentation
)用制表符填充所有前导空白,并使用空格来对齐行内出现的内容(例如连续的赋值和声明)。UT_AlignWithSpaces
(in configuration:AlignWithSpaces
) Use tabs for line continuation and indentation, and spaces for alignment.
UT_AlignWithSpaces
(在配置中:AlignWithSpaces
)使用制表符进行行延续和缩进,使用空格进行对齐。UT_Always
(in configuration:Always
) Use tabs whenever we need to fill whitespace that spans at least from one tab stop to the next one.
UT_Always
(在配置中:Always
)每当我们需要填充至少从一个制表位到下一个制表位的空白时,请使用制表符。
- VerilogBreakBetweenInstancePorts (
Boolean
) clang-format 17 ¶
VerilogBreakBetweenInstancePorts (Boolean
) clang 格式 17 ¶ For Verilog, put each port on its own line in module instantiations.
对于 Verilog,在模块实例化中将每个端口放在自己的线上。true: ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2)); false: ffnand ff1(.q(), .qbar(out1), .clear(in1), .preset(in2));
- WhitespaceSensitiveMacros (
List of Strings
) clang-format 11 ¶ A vector of macros which are whitespace-sensitive and should not be touched.
对空格敏感且不应触及的宏向量。These are expected to be macros of the form:
这些预计是以下形式的宏:STRINGIZE(...)
In the .clang-format configuration file, this can be configured like:
在 .clang-format 配置文件中,可以这样配置:WhitespaceSensitiveMacros: ['STRINGIZE', 'PP_STRINGIZE']
For example: BOOST_PP_STRINGIZE
例如:BOOST_PP_STRINGIZE
Adding additional style options¶
添加额外的样式选项 ¶
Each additional style option adds costs to the clang-format project. Some of
these costs affect the clang-format development itself, as we need to make
sure that any given combination of options work and that new features don’t
break any of the existing options in any way. There are also costs for end users
as options become less discoverable and people have to think about and make a
decision on options they don’t really care about.
每个额外的样式选项都会增加 clang-format 项目的成本。其中一些成本会影响 clang-format 开发本身,因为我们需要确保任何给定的选项组合都有效,并且新功能不会以任何方式破坏任何现有选项。最终用户也会付出成本,因为选项变得越来越难以发现,人们必须考虑他们并不真正关心的选项并做出决定。
The goal of the clang-format project is more on the side of supporting a
limited set of styles really well as opposed to supporting every single style
used by a codebase somewhere in the wild. Of course, we do want to support all
major projects and thus have established the following bar for adding style
options. Each new style option must ..
clang-format 项目的目标更多的是真正很好地支持一组有限的样式,而不是支持野外代码库使用的每种样式。当然,我们确实希望支持所有主要项目,因此建立了以下添加样式选项的栏。每个新款式选项必须..
be used in a project of significant size (have dozens of contributors)
用于大型项目(有数十个贡献者)have a publicly accessible style guide
有一个可公开访问的风格指南have a person willing to contribute and maintain patches
有一个人愿意贡献和维护补丁
Examples¶ 例子 ¶
A style similar to the Linux Kernel style:
类似于Linux内核风格的风格:
BasedOnStyle: LLVM
IndentWidth: 8
UseTab: Always
BreakBeforeBraces: Linux
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
The result is (imagine that tabs are used for indentation here):
结果是(想象一下这里使用制表符进行缩进):
void test()
{
switch (x) {
case 0:
case 1:
do_something();
break;
case 2:
do_something_else();
break;
default:
break;
}
if (condition)
do_something_completely_different();
if (x == y) {
q();
} else if (x > y) {
w();
} else {
r();
}
}
A style similar to the default Visual Studio formatting style:
类似于默认 Visual Studio 格式化样式的样式:
UseTab: Never
IndentWidth: 4
BreakBeforeBraces: Allman
AllowShortIfStatementsOnASingleLine: false
IndentCaseLabels: false
ColumnLimit: 0
The result is: 结果是:
void test()
{
switch (suffix)
{
case 0:
case 1:
do_something();
break;
case 2:
do_something_else();
break;
default:
break;
}
if (condition)
do_something_completely_different();
if (x == y)
{
q();
}
else if (x > y)
{
w();
}
else
{
r();
}
}