Я бы хотел использовать формат clang для автоформатирования моего исходного кода, но я не могу понять, как он работает с аналогичными структурами.Пожалуйста, смотрите следующий код C ++:
static someStructLongName structInstanceLong{
Method1LongLong,
structInstanceMethod1,
structInstanceMethod1,
structInstanceMethod3,
structInstanceMethod4,
structInstanceMethod5,
structInstanceMethod6,
structInstanceMethod7,
structInstanceMethod8
};
static someStructLongName structInstanceLong{
Method1,
structInstanceMethod1,
structInstanceMethod1,
structInstanceMethod3,
structInstanceMethod4,
structInstanceMethod5,
structInstanceMethod6,
structInstanceMethod7,
structInstanceMethod8
};
И когда я форматирую его в формате clang, используя мой пользовательский файл конфигурации (прикрепленный внизу поста), я получаю следующий вывод:
static someStructLongName structInstanceLong{Method1LongLing, structInstanceMethod1, structInstanceMethod1,
structInstanceMethod3, structInstanceMethod4, structInstanceMethod5,
structInstanceMethod6, structInstanceMethod7, structInstanceMethod8};
static someStructLongName structInstanceLong{Method1,
structInstanceMethod1,
structInstanceMethod1,
structInstanceMethod3,
structInstanceMethod4,
structInstanceMethod5,
structInstanceMethod6,
structInstanceMethod7,
structInstanceMethod8};
Второй вариант предпочтительнее, но я не могу понять, какое правило отвечает за это поведение, так что собирается изменить этот результат для всех структур.
Интересная вещь - когда я использую этоонлайн-инструмент: https://zed0.co.uk/clang-format-configurator/ при загрузке моей конфигурации и кода выше все выглядит как ожидалось.
Ниже пользовательской конфигурации в формате clang:
---
AccessModifierOffset: '-4'
AlignEscapedNewlinesLeft: 'true'
AllowAllParametersOfDeclarationOnNextLine: 'true'
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'
AlwaysBreakBeforeMultilineStrings: 'false'
AlwaysBreakTemplateDeclarations: 'true'
BinPackParameters: 'false'
BreakBeforeBinaryOperators: 'NonAssignment'
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
BreakBeforeBraces: Custom
BreakBeforeTernaryOperators: 'false'
BreakConstructorInitializersBeforeComma: 'true'
ColumnLimit: '120'
ConstructorInitializerAllOnOneLineOrOnePerLine: 'false'
ConstructorInitializerIndentWidth: '4'
ContinuationIndentWidth: '4'
Cpp11BracedListStyle: 'true'
DerivePointerAlignment: 'false'
DisableFormat: 'false'
ExperimentalAutoDetectBinPacking: 'false'
IndentCaseLabels: 'false'
IndentWidth: '4'
IndentWrappedFunctionNames: 'false'
KeepEmptyLinesAtTheStartOfBlocks: 'false'
Language: Cpp
MaxEmptyLinesToKeep: '1'
NamespaceIndentation: All
PointerAlignment: Left
SpaceBeforeAssignmentOperators: 'true'
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: 'false'
SpacesInAngles: 'false'
SpacesInCStyleCastParentheses: 'false'
SpacesInParentheses: 'false'
Standard: Cpp11
TabWidth: '4'
UseTab: Never
...