Case Statements Not Indenting
dustinhansen opened this issue · 1 comments
dustinhansen commented
Is there any way to make case statements indent properly? Most style guides now recommend this and rubocop barks at me that it's not indented properly. Is this possible?
case something
when this
do_something
when that
do_something_else
end
BeautifyRuby is putting the "when" clauses on the same link as "case".
pjmartorell commented
In Ruby Style Guide , which is the style followed by RuboCop, states the following:
- Indent
when
as deep ascase
. This is the style established in both
"The Ruby Programming Language" and "Programming Ruby".
[link]
# bad
case
when song.name == 'Misty'
puts 'Not again!'
when song.duration > 120
puts 'Too long!'
when Time.now.hour > 21
puts "It's too late"
else
song.play
end
# good
case
when song.name == 'Misty'
puts 'Not again!'
when song.duration > 120
puts 'Too long!'
when Time.now.hour > 21
puts "It's too late"
else
song.play
end
So indenting "when" clauses at the same deep as "case" is the correct way.