-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Multi condition case when #422
Conversation
I believe you should update your PR considering the rule "Indent when as deep as case" # good
case token
when :star_op
stack.pop * stack.pop
when :slash_op
stack.pop / stack.pop
when :minus_op
also_calculate_that
stack.pop - stack.pop
when :plus_op,
:plus_plus_op
stack.pop + stack.pop
when :int_literal
token.value
end |
The suggested rule is pretty subjective IMO - I don't see any notable readability improvements. I should also point out I've never seen it in the wild and I've been programming in Ruby for quite a while. |
@bbatsov what is your suggestion for |
Break them up as suggested here, of course. My problem with this PR is that it suggests doing this all the time. |
As for me it's an obvious way to split conditions as suggested here but I believe that style guide must be explicit. We can add this rule with the note that it should only be used when conditions doesn't fit in one line. What do you think? |
Fine by me. |
2aee498
to
c68632c
Compare
I've pushed an update to correct the indentation mistake. I also tried to be more clear with in the wild situations that I've seen the need for this. I've actually been at more than one company that needed this formatting in the codebase. I think it's lovely to imagine that every team is going to be agile and lean enough to get onboard with refactoring that can demonstrably improve maintainability. Sadly many orgs have complicated dependencies and Dilbert-grade managers. This part of the style guide helps in these situations. I changed the examples to be permissive of short condition-groups that can stack and remain readable immediately — which I hope allays the concerns raised by those who do not often encounter the situation. |
Why there're so many changes in PR? I believe you should include only multi condition changes in this PR. Could you explain it? |
Could you cherry-pick these commits and squash them? I think it will help to merge this PR sooner. |
c68632c
to
7c53f82
Compare
there we go 👍 |
@@ -326,6 +326,56 @@ Translations of the guide are available in the following languages: | |||
end | |||
``` | |||
|
|||
<a name="multi-condition-case-when"></a> | |||
* put multiple when conditions on separate lines |
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.
According to other rules in the guide:
- The sentence must be capitalized and end with a dot.
- Good and bad examples usually combined into single code snippet.
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.
sure
7c53f82
to
2186b71
Compare
I've updated the
|
Is there more I can do to make this conformant with the ideals of this repo? |
This replaces PR rubocop#422, and maintains a minimum of overall new lines
Replaced by #741 |
Depends on Chanel #9
Following-up from the PR on
When/Then
blockThere is no demonstration to confirm how to format when multiple conditions should result in the same action. I propose this:
Though better control of primary domain references should be exercised, this style offers a solution for some 'in the wild' situations. It reads better than:
Where the 'bad' example also has the issue of cause the entire when line to diff when one of the conditions is changed or updated.
I know that some people love long lines, but I suggest that a newline is an easier-to-cognized demarcation of conditions, rathe than a comma