nicklockwood / SwiftFormat

A command-line tool and Xcode Extension for formatting Swift code
MIT License
7.77k stars 629 forks source link

`Alman = false` in combination with long char count in line breaks the `{` into a new row #1534

Closed tscholze closed 10 months ago

tscholze commented 11 months ago

Is it configurable that if the style alman = false is applied, that the opening bracket on a method will still be on the same line as the function itself?

This is no problem if the function name is short, but if you have some AppDelegate methods, the alman style will not be applied.

nicklockwood commented 11 months ago

If I understand correctly, you want something like this?

func foo(bar,
         baz) {
    ...
}

Instead of this?

func foo(bar,
         baz)
{
    ...
}

If so, there's current no option for that, however this style is supported if that would work for you?

func foo(
    bar,
    baz
) {
    ...
}
tscholze commented 11 months ago

@nicklockwood thanks for your blazing fast reply. I meant something else. Maybe the following sample helps to understand my confusing words.

Input

func application(_: UIApplication, willFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool
{ 
//
}

and

func applicationDidEnterBackground(_: UIApplication)
{
//
}

Output after the formatter run

func application(_: UIApplication, willFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool
{ 
//
}

and

func applicationDidEnterBackground(_: UIApplication) {
//
}

Expected behavior I would expect that both function will get their { moved to the same lane as the method header is and not just only on the "shorter" applicationDidEnterBackground.

This behavior occurs on every "long" method name.

nicklockwood commented 11 months ago

Ah, OK. That could be a bug - I'll check.

tscholze commented 11 months ago

Thanks buddy! Your work is amazing!

nicklockwood commented 10 months ago

@tscholze I found the issue. For some reason I don't recall, the code was set not to unwrap braces if the width would exceed 100 chars. I'll remove that limit, but in the meantime you can override it by setting --maxwidth 120 (or whatever).

nicklockwood commented 10 months ago

@tscholze fixed in 0.52.5. Thanks for the report!

tscholze commented 10 months ago

Thanks! ❤️