-
Notifications
You must be signed in to change notification settings - Fork 637
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
Double-indent trailing closure bodies when using --closingparen same-line #667
Double-indent trailing closure bodies when using --closingparen same-line #667
Conversation
I'm not sure if it makes sense to tie this to the --closingparen argument, but I don't have a better idea right now. |
@calda would it be consistent with your style guide to indent the closing } as well for this scenario? i.e. self.method(
withParameter: 1,
otherParameter: 2) { [weak self] in
guard let error = error else { return }
print("and a trailing closure")
} |
I don't think we have an explicit preference for that. Both options seem fine to me personally (I'm not sure which I'd prefer if I had to pick one or the other) |
The latter is more consistent with how closures are handled in other scenarios, so I'd be more comfortable having that be the default behavior vs a double indent of just the body. |
I can make a follow-up PR that makes that the default, if you’d like. |
No, need, I just wanted to check it wouldn't render the feature unusable for you. Thanks 👍 |
@calda I ran into a case where this seemed like a bug (see #909) and I think I may need to tweak the rule, but I wanted to check with you first. We already discussed indenting the closing }, which I forgot to do before but may do now. But also, would it be consistent with your style guide if it only double-indented for cases where the parameters are wrapped using before-first? i.e. this would be double indented: self.method(
withParameter: 1,
otherParameter: 2) { [weak self] in
guard let error = error else { return }
print("and a trailing closure")
} but this would not: self.method(withParameter: 1,
otherParameter: 2) { [weak self] in
guard let error = error else { return }
print("and a trailing closure")
} I think this makes sense, since the purpose of the double indent (I assume) is to prevent the body lining up with the parameters, which isn't an issue in the second case. But let me know what you think. |
That makes sense to me! Our style guide only permits |
This PR updates the
indent
rule to double-indent trailing closure bodies when using--closingparen same-line
.indent
rule as a part of the Airbnb Swift Style Guide.This is now valid indentation when using
indent --indent 2 --closingparen same-line
:If you use
--closingparen balanced
(the default), the trailing closure body stays single-indented: