Clang-Format неправильно выравнивает аргументы функции - PullRequest
1 голос
/ 28 мая 2020

Я пытаюсь отформатировать свой код таким образом:

int foo(int a,
        int b,
        int c)
{
}

Однако все мои попытки привели к следующим результатам:

int foo(int a,
   int b,
   int c)
{
}

Вот моя конфигурация формата clang, работает на Manjaro:

# Under Visual studio, the plugin https://marketplace.visualstudio.com/items?itemName=LLVMExtensions.ClangFormat makes the use of the clang formatter easier.

Language: Cpp

AccessModifierOffset: -4 
AlignAfterOpenBracket: Align #AlwaysBreak 
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: true 
AlignEscapedNewlines: Left 
AlignOperands: true
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: false
AllowAllConstructorInitializersOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Always 
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All 
AllowShortIfStatementsOnASingleLine: Always 
AllowShortLambdasOnASingleLine: All
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: true 

BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: None 
BreakBeforeBraces: Allman 
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon 
BreakInheritanceList: AfterColon 
BreakStringLiterals: true

ColumnLimit: 120
CompactNamespaces: true
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4

ContinuationIndentWidth: 4
Cpp11BracedListStyle: true

DerivePointerAlignment: false

FixNamespaceComments: true

IndentCaseLabels: false
IndentPPDirectives: BeforeHash   
IndentWidth: 4
IndentWrappedFunctionNames: false


KeepEmptyLinesAtTheStartOfBlocks: false

MaxEmptyLinesToKeep: 1

NamespaceIndentation: Inner 

PointerAlignment: Middle 

ReflowComments: true

SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: false
SpaceBeforeParens: Never
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 4
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false


TabWidth: 4
UseTab: Never 

## Penalites: This decides what order things should be done if a line is too long. 
## For instance, using the policies specified here:  https://stackoverflow.com/questions/26635370/in-clang-format-what-do-the-penalties-do

PenaltyBreakAssignment: 5
PenaltyBreakBeforeFirstCallParameter: 5
PenaltyBreakComment: 10
PenaltyBreakFirstLessLess: 0
PenaltyBreakString: 10
PenaltyBreakTemplateDeclaration : 30
PenaltyExcessCharacter: 30
PenaltyReturnTypeOnItsOwnLine: 30

Кто-нибудь знает, как принудительно выполнить это выравнивание?

FYI, уже пробовал: Clang-format: Выровнять имена параметров функций и clang-format: параметры функции прерывания

Большое спасибо

Ура

1 Ответ

0 голосов
/ 28 мая 2020

Как я уже сказал, я уже безуспешно пробовал эти решения ... Установка для AlignConsecutiveDeclarations значения true генерирует

Scene(const std::filesystem::path           scene_directory,
    Object3D *                            parent,
    Magnum::SceneGraph::DrawableGroup3D * group);

РЕДАКТИРОВАТЬ 1: Проблема обнаружена! Это было вызвано моей IDE по неизвестным причинам. Копирование вставки в текстовый редактор показывает, что форматирование правильное .. Спасибо за помощь!

...