class 字段和方法的 clang 格式缩进,函数和枚举的左花括号
clang-format indentation of class fields and methods, opening curly braces for functions and enums
我的 clang-format 生成如下代码:
enum class SomeEnum{ VAL1, VAL2, VAL3 };
class SomeClass {
public:
void someMethod();
private:
int m_field;
};
void someFunc()
{
// ...
}
但我希望它是这样的:
enum class SomeEnum {
VAL1,
VAL2,
VAL3
};
class SomeClass {
public:
void someMethod();
private:
int m_field;
};
void someFunc() {
// ...
}
所以我需要枚举不要像这样减少到一行,因为 class 方法和字段在访问说明符之后有一个额外的缩进级别,并且我的函数的左大括号是一个 space 在 ')' 之后而不是在另一行
这是我的 .clang 格式文件
AccessModifierOffset: '0'
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: 'true'
AlignEscapedNewlines: Left
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'false'
AllowAllConstructorInitializersOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BreakBeforeBraces: Stroustrup
ColumnLimit: '120'
CompactNamespaces: 'false'
Cpp11BracedListStyle: 'true'
DerivePointerAlignment: 'true'
FixNamespaceComments: 'true'
IndentCaseLabels: 'true'
IndentWidth: '4'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: All
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SpaceAfterCStyleCast: 'false'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInSquareBrackets: 'false'
TabWidth: '4'
UseTab: ForContinuationAndIndentation
AllowShortEnumsOnASingleLine: false # is available since clang-format 12.
IndentAccessModifiers: true # is available since clang-format 13.
BraceWrapping:
AfterFunction: false
我的 clang-format 生成如下代码:
enum class SomeEnum{ VAL1, VAL2, VAL3 };
class SomeClass {
public:
void someMethod();
private:
int m_field;
};
void someFunc()
{
// ...
}
但我希望它是这样的:
enum class SomeEnum {
VAL1,
VAL2,
VAL3
};
class SomeClass {
public:
void someMethod();
private:
int m_field;
};
void someFunc() {
// ...
}
所以我需要枚举不要像这样减少到一行,因为 class 方法和字段在访问说明符之后有一个额外的缩进级别,并且我的函数的左大括号是一个 space 在 ')' 之后而不是在另一行
这是我的 .clang 格式文件
AccessModifierOffset: '0'
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: 'true'
AlignEscapedNewlines: Left
AlignTrailingComments: 'true'
AllowAllArgumentsOnNextLine: 'false'
AllowAllConstructorInitializersOnNextLine: 'true'
AllowShortBlocksOnASingleLine: 'true'
AllowShortCaseLabelsOnASingleLine: 'true'
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: Never
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakTemplateDeclarations: 'Yes'
BreakBeforeBraces: Stroustrup
ColumnLimit: '120'
CompactNamespaces: 'false'
Cpp11BracedListStyle: 'true'
DerivePointerAlignment: 'true'
FixNamespaceComments: 'true'
IndentCaseLabels: 'true'
IndentWidth: '4'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '2'
NamespaceIndentation: All
SortIncludes: 'true'
SortUsingDeclarations: 'true'
SpaceAfterCStyleCast: 'false'
SpaceAfterLogicalNot: 'false'
SpaceAfterTemplateKeyword: 'false'
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeCtorInitializerColon: 'true'
SpaceBeforeInheritanceColon: 'true'
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: 'true'
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInSquareBrackets: 'false'
TabWidth: '4'
UseTab: ForContinuationAndIndentation
AllowShortEnumsOnASingleLine: false # is available since clang-format 12.
IndentAccessModifiers: true # is available since clang-format 13.
BraceWrapping:
AfterFunction: false