nicklockwood / SwiftFormat

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

Unexpected closure changes with 0.49.10 #1202

Closed frehulfd closed 2 years ago

frehulfd commented 2 years ago

With the latest update we are seeing some unexpected indentation with closure parameters to functions. Given the input code, we would expect it to remain unchanged which matches what "Control + I" produces in Xcode.

What we are seeing is the below output where the body of the closure is aligned to the function parameter list.

Our .swiftformat file contains:

--indent 4

Adding --xcodeindentation enabled doesn't have any effect.

Input

private final class FadeTransitionStyle: NSObject, UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        0.3
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = transitionContext.viewController(forKey: .from),
              let toVC = transitionContext.viewController(forKey: .to) else { return }

        toVC.view.alpha = 0
        UIView.transition(
            with: transitionContext.containerView,
            duration: transitionDuration(using: transitionContext),
            options: []) {
                fromVC.view.alpha = 0
                transitionContext.containerView.addSubview(toVC.view)
                toVC.view.frame = transitionContext.finalFrame(for: toVC)
                toVC.view.alpha = 1
            } completion: { _ in
                transitionContext.completeTransition(true)
                fromVC.view.removeFromSuperview()
            }
    }
}

Output:

private final class FadeTransitionStyle: NSObject, UIViewControllerAnimatedTransitioning {
    func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
        0.3
    }

    func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
        guard let fromVC = transitionContext.viewController(forKey: .from),
              let toVC = transitionContext.viewController(forKey: .to) else { return }

        toVC.view.alpha = 0
        UIView.transition(
            with: transitionContext.containerView,
            duration: transitionDuration(using: transitionContext),
            options: []) {
            fromVC.view.alpha = 0
            transitionContext.containerView.addSubview(toVC.view)
            toVC.view.frame = transitionContext.finalFrame(for: toVC)
            toVC.view.alpha = 1
        } completion: { _ in
            transitionContext.completeTransition(true)
            fromVC.view.removeFromSuperview()
        }
    }
}
nicklockwood commented 2 years ago

@frehulfd fixed in 0.49.11

frehulfd commented 2 years ago

@nicklockwood awesome, thank you!