Open mcichecki opened 1 month ago
Synced to Apple’s issue tracker as rdar://137341062
This is by design; in most cases where a complex expression follows an assignment, we move the expression to the next line and indent it. There are a limited number of cases where we don't do this, like function calls. However, my gut feeling is to not add more cases like that and we're better off using something like the rectangle rule to guide our line breaking and indentation philosophy here (which is what we do for cases not covered by those exceptions).
@allevato so there is no way to prevent that? I wouldn't say that the example that I provided is "a complex expression".
There is no way to prevent that behavior today and it's not planned.
I wonder if that's my config file or it's a default behaviour that can't be changed but it seems quite weird to me. When using if conditional blocks as expressions (introduced in Swift 5.9) and assigning them to the properties I'd like to keep them in the same line as the property. When running swift-format the whole expression is moved to the next line.
original:
after formatting:
Config:
```json { "fileScopedDeclarationPrivacy" : { "accessLevel" : "private" }, "indentConditionalCompilationBlocks" : false, "indentSwitchCaseLabels" : false, "indentation" : { "spaces" : 4 }, "lineBreakAroundMultilineExpressionChainComponents" : false, "lineBreakBeforeControlFlowKeywords" : false, "lineBreakBeforeEachArgument" : false, "lineBreakBeforeEachGenericRequirement" : true, "lineBreakBetweenDeclarationAttributes": true, "lineLength" : 90, "maximumBlankLines" : 1, "multiElementCollectionTrailingCommas" : false, "prioritizeKeepingFunctionOutputTogether" : true, "respectsExistingLineBreaks" : true, "rules" : { "AllPublicDeclarationsHaveDocumentation" : false, "AlwaysUseLiteralForEmptyCollectionInit" : true, "AlwaysUseLowerCamelCase" : true, "AmbiguousTrailingClosureOverload" : true, "BeginDocumentationCommentWithOneLineSummary" : false, "DoNotUseSemicolons" : true, "DontRepeatTypeInStaticProperties" : true, "FileScopedDeclarationPrivacy" : true, "FullyIndirectEnum" : true, "GroupNumericLiterals" : true, "IdentifiersMustBeASCII" : true, "NeverForceUnwrap" : false, "NeverUseForceTry" : false, "NeverUseImplicitlyUnwrappedOptionals" : false, "NoAccessLevelOnExtensionDeclaration" : true, "NoAssignmentInExpressions" : true, "NoBlockComments" : true, "NoCasesWithOnlyFallthrough" : true, "NoEmptyTrailingClosureParentheses" : true, "NoLabelsInCasePatterns" : true, "NoLeadingUnderscores" : true, "NoParensAroundConditions" : true, "NoPlaygroundLiterals" : false, "NoVoidReturnOnFunctionSignature" : true, "OmitExplicitReturns" : true, "OneCasePerLine" : true, "OneVariableDeclarationPerLine" : true, "OnlyOneTrailingClosureArgument" : true, "OrderedImports" : false, "ReplaceForEachWithForLoop" : true, "ReturnVoidInsteadOfEmptyTuple" : true, "TypeNamesShouldBeCapitalized" : true, "UseEarlyExits" : false, "UseExplicitNilCheckInConditions" : true, "UseLetInEveryBoundCaseVariable" : true, "UseShorthandTypeNames" : true, "UseSingleLinePropertyGetter" : true, "UseSynthesizedInitializer" : true, "UseTripleSlashForDocumentationComments" : true, "UseWhereClausesInForLoops" : false, "ValidateDocumentationComments" : false }, "spacesAroundRangeFormationOperators" : false, "tabWidth" : 4, "version" : 1 } ```How can I prevent from adding line break in this case?