Skip to content

Avoid indent for single-line argument lists in BasicFormat#3334

Open
broken-circle wants to merge 1 commit into
swiftlang:mainfrom
broken-circle:basic-format-indent-1473-2082
Open

Avoid indent for single-line argument lists in BasicFormat#3334
broken-circle wants to merge 1 commit into
swiftlang:mainfrom
broken-circle:basic-format-indent-1473-2082

Conversation

@broken-circle

@broken-circle broken-circle commented May 16, 2026

Copy link
Copy Markdown
Member

Closes #1473.
Closes #2082.

FunctionCallExprSyntax.arguments and TupleExprSyntax.elements were unconditional indentation scopes in BasicFormat.requiresIndent. When the argument list itself was single-line (no argument starting on its own line) but contained a multi-line expression like a closure or collection literal, the inner expression's indentation got double-counted: once from the argument-list scope and once from the expression's own scope.

For example:

foo(someClosure: { _ in
    return 1
})

formatted to:

foo(someClosure: { _ in
        return 1
    })

This PR treats the argument-list keypaths as indentation scopes only when the argument list is multi-line at the argument level. That indentation only exists to lay out arguments that wrap onto their own lines. When arguments are all on the same line as (, any multi-line content comes from a nested expression that brings its own scope.

The same change is applied to TupleExprSyntax.elements, which has the same structure (also a LabeledExprListSyntax), with the same bug (see updated ExpressionMacroTests.testStringifyExpression()).

Testing

This PR adds three new tests in BasicFormatTests, and updates 5 existing tests in CallToTrailingClosuresTest, VariableTests, DebugDescriptionTests, and ExpressionMacroTests to expect the correct format.

Treat argument-list keypaths as indentation scopes only when the
argument list is multi-line at the argument level. That indentation
only exists to lay out arguments that wrap onto their own lines. When
arguments are all on the same line as `(`, any multi-line content comes
from a nested expression that brings its own scope.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BasicFormat indents closing } of closure passed as a function parameter BasicFormat indents closure parameter

1 participant