nicklockwood / SwiftFormat

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

Trailing closure indentation issue #909

Closed jakubkiermasz-zd closed 3 years ago

jakubkiermasz-zd commented 3 years ago

Hi!

I'm curious if it's an issue or intended behavior, but when I run SwiftFormat on that code:

UIView.animate(withDuration: duration,
               options: .allowUserInteraction) {
    presentingView?.frame = finalFrame
} completion: { _ in
    transitionContext.completeTransition(true)
}

It is formatted to:

UIView.animate(withDuration: duration,
               options: .allowUserInteraction) {
        presentingView?.frame = finalFrame
} completion: { _ in
    transitionContext.completeTransition(true)
}

Any feedback will be appreciated!

nicklockwood commented 3 years ago

@jakubkiermasz-zd this looks like a bug.

jakubkiermasz-zd commented 3 years ago

Thanks for the info!

nicklockwood commented 3 years ago

@jakubkiermasz-zd I'm not able to reproduce this with the default settings. Can you share your configuration?

jakubkiermasz-zd commented 3 years ago

Sure!

ticketno909.swiftformat.zip

``` --allman false --assetliterals visual-width --beforemarks --binarygrouping 4,8 --categorymark "MARK: %c" --classthreshold 0 --closingparen same-line --commas inline --conflictmarkers reject --decimalgrouping 3,6 --elseposition same-line --enumthreshold 0 --exponentcase lowercase --exponentgrouping disabled --extensionacl on-declarations --extensionlength 0 --extensionmark "MARK: - %t + %c" --fractiongrouping disabled --fragment false --funcattributes prev-line --groupedextension "MARK: %c" --guardelse auto --header ignore --hexgrouping 4,8 --hexliteralcase uppercase --ifdef no-indent --importgrouping alpha --indent 4 --indentcase false --lifecycle --linebreaks lf --markextensions always --marktypes always --maxwidth none --modifierorder acl,required,override --nevertrailing --nospaceoperators --nowrapoperators --octalgrouping 4,8 --operatorfunc spaced --organizetypes class,enum,struct --patternlet hoist --ranges spaced --redundanttype inferred --self remove --selfrequired --semicolons inline --shortoptionals always --smarttabs enabled --stripunusedargs always --structthreshold 0 --tabwidth unspecified --trailingclosures --trimwhitespace always --typeattributes prev-line --typemark "MARK: - %t" --varattributes same-line --voidtype void --wraparguments after-first --wrapcollections after-first --wrapconditions after-first --wrapparameters after-first --wrapreturntype preserve --xcodeindentation disabled --yodaswap always --disable blankLinesAtEndOfScope,blankLinesAtStartOfScope,fileHeader,strongOutlets,unusedArguments,wrapMultilineStatementBraces --enable isEmpty,sortedSwitchCases ```
nicklockwood commented 3 years ago

@jakubkiermasz-zd thanks. It looks like --closingparen same-line is triggering the bug. I'll fix it asap, but in the meantime removing that option should fix it.

jakubkiermasz-zd commented 3 years ago

Thank you so much!

nicklockwood commented 3 years ago

@jakubkiermasz-zd I now realize this was by design and not a bug. I might need to think about the right approach here since it does seem surprising: https://github.com/nicklockwood/SwiftFormat/pull/667

jakubkiermasz-zd commented 3 years ago

Thanks for letting me know! I totally understand the intention of #667, but it fights with what I want to achieve. If you need anything, ping me :)

nicklockwood commented 3 years ago

I've fixed this now in a way that should hopefully satisfy both requirements

jakubkiermasz-zd commented 3 years ago

Thanks!

jakubkiermasz-zd commented 3 years ago

Is there any way to replace the executable file in the macos app? I want to use the swiftformat (as xcode extension) built from the develop, since it contains your fix.

nicklockwood commented 3 years ago

You'd need to rebuild the whole app from source.

nicklockwood commented 3 years ago

If you rebuild the Mac app, it should build and bundle the extension correctly. For best results use the Archive option and then export the app from Organizer.

jakubkiermasz-zd commented 3 years ago

Thank you so much for your help!

I did what you suggested. Definitely a good idea. I just run into an issue. I archived an app, with the personal development team, with a different bundle identifier. Moved it into the Applications folder, granted extensions permission in sysprefs and it's still not available from XCode's editor tab. Can it be caused by the bundle id?

nicklockwood commented 3 years ago

The bundle ID shouldn't be a problem in itself, but extensions are pretty flaky generally. It might have been confused by there being multiple copies of the same extension.

Try quitting Xcode, moving it to a different folder and then moving it back again.

jakubkiermasz-zd commented 3 years ago

Still nothing :/ I'll probably wait till the release of the new version. When do you plan to update this amazing tool ^^?

nicklockwood commented 3 years ago

@jakubkiermasz-zd fixed in 0.48.1

jakubkiermasz-zd commented 3 years ago

Awesome!