-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Update switch_case_on_newline rule to allow returnless cases #5485
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
Update switch_case_on_newline rule to allow returnless cases #5485
Conversation
Generated by 🚫 Danger |
|
I wonder if this should really be bound to the |
|
@SimplyDanny That's a good remark 👍 |
…tch sift-syntax's definition of a switch expression
|
@SimplyDanny I used the rule defined by the Swift-Syntax's pull request introducing if/switch expressions to check wether the current switch case is enclosed in a statement or an expression. I found out that the following were not considered a switch expression tho: To make them be treated as switch expression I have to use an intermediate value to be assigned like so: I don't know if this is intended or not, because various websites consider these case as being switch expressions, I'll ask this question to the pull request referenced above, but to me the current SwiftLint rule is on the same track as the current Swift-Syntax implementation now 🙏 |
The parser alone cannot decide if a |
|
Hi @SimplyDanny, Thanks for your answer, I understand that you don't seem convinced that the proposed solution is suitable to allow for switch and if expressions as the syntax itself won't handle every cases. I'll close the Pull Request now, thank you for the exchange anyways 🙏 |
Since Swift 5.9, switch cases can return a value without having to explicitly use the
returnkeyword with the condition that they contain only a single line statement.With this evolution, we tend to see more and more switch cases written on a single line.
This pull request aims to offer a configuration point to the
switch_case_on_newlinerule so that it skip these specific cases, so that we can allow the following:but still preventing: