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

[SR-2188] Xcode closure auto-indentation is hard to read with some styles #44796

Open
swift-ci opened this issue Jul 27, 2016 · 1 comment
Open
Assignees
Labels

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Jul 27, 2016

Previous ID SR-2188
Radar None
Original Reporter bnut (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 3
Component/s Source Tooling
Labels Bug
Assignee @nkcsgexi
Priority Medium

md5: 51aa435be00baf4ac468c07bab9de164

blocks:

  • SR-146 Move the swift indentation mechanism from SourceKit to libIDE and utilize it for a 'swift-format' tool

Issue Description:

Currently Xcode handles this indentation well:

UIView.animate(
    withDuration: 12.0,
    animations: {
        print("statements have good indentation")
    },
    completion: { done in
        print("statements have good indentation")
    })

However, if the arguments are not broken over multiple lines it looks like this:

UIView.animate(withDuration: 12.0, animations: {
    print("statements have good indentation")
    }, completion: { done in // this shouldn't be indented
        print("statements have weird indentation")
})

Having the print statement at the same level as the closure's closing bracket makes it less clear that the closure has closed. At a glance a programmer may think that completion is an expression inside the first closure.

I expect it to look like this:

UIView.animate(withDuration: 12.0, animations: {
    print("statements have good indentation")
}, completion: { done in // this shouldn't be indented
    print("statements have weird indentation")
})

I'm also happy if it looks like this, although it's a little weird, it's at least consistent:

UIView.animate(withDuration: 12.0, animations: {
        print("statements have good indentation")
    }, completion: { done in // this shouldn't be indented
        print("statements have weird indentation")
    })

I expect indentation to approximately reflect the syntax tree, all arguments at the same level should get the same indentation. So sibling closures should get the same indentation on their closing bracket.

This is discussed in more detail here: #3754

@swift-ci
Copy link
Collaborator Author

swift-ci commented Nov 1, 2018

Comment by shingo (JIRA)

Please fix this.

Promise hard to read.

https://github.com/mxcl/PromiseKit

README.md say

firstly {
    when(fulfilled: fetchImage, fetchLocation)
}.done { image, location in
    self.imageView.image = image
    self.label.text = "\(location)"
}.ensure {
    UIApplication.shared.isNetworkActivityIndicatorVisible = false
}.catch { error in
    self.show(UIAlertController(for: error), sender: self)
}

But, Xcode

firstly {
    when(fulfilled: fetchImage, fetchLocation)
    }.done { image, location in
        self.imageView.image = image
        self.label.text = "\(location)"
    }.ensure {
        UIApplication.shared.isNetworkActivityIndicatorVisible = false
    }.catch { error in
        self.show(UIAlertController(for: error), sender: self)
}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant