Skip to content

Commit

Permalink
Better clarity on case-when indentation
Browse files Browse the repository at this point in the history
This replaces PR rubocop#422, and maintains a minimum of overall new lines
  • Loading branch information
NewAlexandria authored Mar 17, 2019
1 parent da535e0 commit 7116ec0
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,12 @@ Translations of the guide are available in the following languages:
puts 'Not again!'
when song.duration > 120
puts 'Too long!'
when Time.now.hour > 21
puts "It's too late"
when :minus_op, :minus_minus_op
stack.pop - stack.pop
when MyModule::SomeDomain::BETA_USERS, MyModule::SomeDomain::INTERNAL_RELEASE
stack.pop + stack.pop
when :int_literal, :some_complicate_explicit_name, :contains_musicians_with_arms, :str_interpolated
token.value
else
song.play
end
Expand All @@ -341,11 +345,26 @@ Translations of the guide are available in the following languages:
puts 'Too long!'
when Time.now.hour > 21
puts "It's too late"
when :minus_op, :minus_minus_op
stack.pop - stack.pop
when MyModule::SomeDomain::BETA_USERS,
MyModule::SomeDomain::INTERNAL_RELEASE
stack.pop + stack.pop
when :int_literal,
:some_complicate_explicit_name,
:contains_musicians_with_arms,
:str_interpolated
token.value
else
song.play
end
```

Put multiple when conditions on separate lines,
particularly where the conditions form long, complicated lines.
The 'bad' example also has the issue of causing the entire when line to
diff when only one of the conditions is changed or updated.

* <a name="indent-conditional-assignment"></a>
When assigning the result of a conditional expression to a variable,
preserve the usual alignment of its branches.
Expand Down

0 comments on commit 7116ec0

Please sign in to comment.