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
Add rule to add a line break after the assignment operator before a multi-line if
or switch
expressions
#253
Conversation
f59924b
to
89bdb47
Compare
…ti-line if or switch expressions.
89bdb47
to
a076f62
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! Thanks @calda .
@@ -900,6 +900,79 @@ _You can enable the following settings in Xcode by running [this script](resourc | |||
… | |||
} | |||
``` | |||
|
|||
</details> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
Co-authored-by: Michael Bachand <michael.bachand@airbnb.com>
let planet = | ||
if useFirst { mercury } else { neptune } | ||
let moonName = | ||
if let moon = planet.moon { moon.name } else { "none" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Summary
This PR proposes a new rule to add a line break after the assignment operator before a multi-line
if
orswitch
expression.Autocorrection for this rule is implemented in the
wrapMultilineConditionalAssignment
SwiftFormat rule, added in nicklockwood/SwiftFormat#1574.Reasoning
This makes it so that
if
andswitch
expressions always have the same "shape" as standardif
andswitch
statements, where:if
/switch
keyword is always the left-most token on a dedicated line of codeif
/switch
keyword.This is most consistent with the formatting of
if
/switch
statements in other contexts, and thus makes it easier to recognize that the code is using anif
orswitch
expression at a glance.This is independent of #250 and could be accepted even if we reject #250, but #250 depends on these changes given the discussion here.
Examples
Please react with 👍/👎 if you agree or disagree with this proposal.