Skip to content

Commit 7116ec0

Browse files
Better clarity on case-when indentation
This replaces PR rubocop#422, and maintains a minimum of overall new lines
1 parent da535e0 commit 7116ec0

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

README.md

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,12 @@ Translations of the guide are available in the following languages:
327327
puts 'Not again!'
328328
when song.duration > 120
329329
puts 'Too long!'
330-
when Time.now.hour > 21
331-
puts "It's too late"
330+
when :minus_op, :minus_minus_op
331+
stack.pop - stack.pop
332+
when MyModule::SomeDomain::BETA_USERS, MyModule::SomeDomain::INTERNAL_RELEASE
333+
stack.pop + stack.pop
334+
when :int_literal, :some_complicate_explicit_name, :contains_musicians_with_arms, :str_interpolated
335+
token.value
332336
else
333337
song.play
334338
end
@@ -341,11 +345,26 @@ Translations of the guide are available in the following languages:
341345
puts 'Too long!'
342346
when Time.now.hour > 21
343347
puts "It's too late"
348+
when :minus_op, :minus_minus_op
349+
stack.pop - stack.pop
350+
when MyModule::SomeDomain::BETA_USERS,
351+
MyModule::SomeDomain::INTERNAL_RELEASE
352+
stack.pop + stack.pop
353+
when :int_literal,
354+
:some_complicate_explicit_name,
355+
:contains_musicians_with_arms,
356+
:str_interpolated
357+
token.value
344358
else
345359
song.play
346360
end
347361
```
348362

363+
Put multiple when conditions on separate lines,
364+
particularly where the conditions form long, complicated lines.
365+
The 'bad' example also has the issue of causing the entire when line to
366+
diff when only one of the conditions is changed or updated.
367+
349368
* <a name="indent-conditional-assignment"></a>
350369
When assigning the result of a conditional expression to a variable,
351370
preserve the usual alignment of its branches.

0 commit comments

Comments
 (0)