Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lineBreakBeforeEachArgument adds a line break *after* the last argument #838

Open
John-Colvin opened this issue Oct 5, 2024 · 5 comments

Comments

@John-Colvin
Copy link

I don't know whether it's intended, but a) it's not mentioned in the docs & b) personally I would prefer control over that separately

e.g.

foo(a,  // something
    b)  // else

becomes

foo(
    a,  // something
    b
)  // else

What I would like to see

foo(
    a,  // something
    b)  // else
@John-Colvin John-Colvin changed the title lineBreakBeforeEachArgument adds line break *after* the last argument lineBreakBeforeEachArgument adds a line break *after* the last argument Oct 5, 2024
@ahoppen
Copy link
Member

ahoppen commented Oct 5, 2024

Synced to Apple’s issue tracker as rdar://137353549

@jkmathew
Copy link

jkmathew commented Oct 6, 2024

A small addition to lineBreakBeforeEachArgument

I have this code

foo(a
    b)

And "lineBreakBeforeEachArgument": false in the configuration file. Still, when running the format command, this is changed to

foo(
    a
    b)

Is this intended to do so?

@allevato
Copy link
Member

allevato commented Oct 7, 2024

lineBreakBeforeEachArgument would be better named eachArgumentOnOwnLine, but alas, we're stuck with the name unless we want to change it and then write some migration code to preserve the old name in existing configurations. I'd rather wait until we have a reason to do a larger-scale configuration refactoring to do that, vs. fixing the name for one-off cases.

@jkmathew
Copy link

jkmathew commented Oct 7, 2024

I agree the name is a bit ambiguous. I am still confused why this code is getting formatted even though the rule is disabled with "lineBreakBeforeEachArgument": false 🤔

Plus a humble suggestion for future refactoring, if any 🙂
It would be better if we can configure this rule to keep the first argument in the same line and format others.
Similar to this rule: https://github.com/nicklockwood/SwiftFormat/blob/main/Rules.md#wraparguments and https://realm.github.io/SwiftLint/multiline_arguments.html.

Or is this already possible?

@allevato
Copy link
Member

allevato commented Oct 7, 2024

swift-format's formatting algorithm was explicitly designed to not do hanging indentation where the indentation level is determined by what column an element on the first line is; one of the core philosophical choices we made was that indentation was always a constant amount not based on tokens from the previous line. So the example that you've given:

someFunction(a,
             b)
someOtherFunction(a,
                  b)

is something that we've chosen not to support.

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

No branches or pull requests

4 participants