-
Notifications
You must be signed in to change notification settings - Fork 250
Convert UseLetInEveryBoundCaseVariable
to be a formatter
#926
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
Conversation
if case let x as SomeType = someValue {} | ||
""", | ||
input: """ | ||
if case 1️⃣let .labeled(label, value) = DataPoint.labeled("hello", 100) {} |
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.
thoughts on adding a test for case .labeled(let label, var value)
we should avoid flagging this pattern
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.
I think the existing tests (the next two lines after this) cover that pattern, where binding keywords are already used adjacent to the bound variables.
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, thanks! I was trying to remember if there was a specific reason that we didn't make this a rewriter previously (i.e., concerns whether there would be cases where the automatic fix would break something), but nothing comes to mind.
@ahoppen Do we need to do anything with the API breakage check failure? The rule implementations themselves are obviously not external API and are only public as @_spi
.
Fixed the issue with re-wrapping subsequent case items in the latest commit – I was accidentally preserving the leading whitespace on the |
Uses the existing logic for determining whether a binding can be moved into a tuple or function call context, and then rewrites the tuple element list or argument list to including the binding keyword. Additionally, improves the diagnostic by using the binding specifier in the source code (i.e. `let` vs `var`).
a70ac62
to
bc0530c
Compare
Not an issue with this PR at all, but commenting for posterity: Those required changes to Once we drop support for 5.8, I guess we can change a lot of those SPIs to |
Uses the existing logic for determining whether a binding can be moved into a tuple or function call context, and then rewrites the tuple element list or argument list to including the binding keyword. Additionally, improves the diagnostic by using the binding specifier in the source code (i.e.
let
vsvar
).This change enables
swift format
to rewrite case statements like the following:Everything looks great for the initial case item in a switch, but for subsequent items under the same
case
statement, the rewritten syntax kind of gets exploded onto multiple lines. Is this a behavior that anyone recognizes? Am I just missing a parameter to tell it not to do this?