Skip to content
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

Case Statements Not Indenting #90

Open
dustinhansen opened this issue Jun 16, 2015 · 1 comment
Open

Case Statements Not Indenting #90

dustinhansen opened this issue Jun 16, 2015 · 1 comment

Comments

@dustinhansen
Copy link

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
Copy link

In Ruby Style Guide , which is the style followed by RuboCop, states the following:

  • Indent when as deep as case. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants