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

Problem with "Indent when as deep as case" #653

Closed
ggarnier opened this issue Dec 2, 2013 · 5 comments · Fixed by #660
Closed

Problem with "Indent when as deep as case" #653

ggarnier opened this issue Dec 2, 2013 · 5 comments · Fixed by #660
Assignees

Comments

@ggarnier
Copy link

ggarnier commented Dec 2, 2013

I have a case statement where the return value is assigned to a variable. I'm getting an "Indent when as deep as case" warning. This is the code:

output = case variable
when 'value1'
  'output1'
when 'value2'
  'output2'
else
  'output3'
end

The syntax Rubocop accepts is:

output = case variable
         when 'value1'
           'output1'
         when 'value2'
           'output2'
         else
           'output3'
         end
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 2, 2013

This is intentional and enforced for all similar expressions. You can change the code into:

output = 
  case variable
  when 'value1'
    'output1'
  when 'value2'
    'output2'
  else
    'output3'
  end

@ggarnier
Copy link
Author

ggarnier commented Dec 3, 2013

Shouldn't both syntaxes be accepted?

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 3, 2013

Perhaps. But definitely not at the same time.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 3, 2013

@jonas054 Would you like to tackle this?

@ghost ghost assigned jonas054 Dec 3, 2013
@jonas054
Copy link
Collaborator

jonas054 commented Dec 4, 2013

Yes. I've seen 4 styles that people use: they indent when 0 or 1 step (a step is two spaces), and they do it relative to case or relative to end. I think I'll add two parameters to accommodate these styles.

CaseIndentation:
  # Valid values are: case, end
  IndentWhenRelativeTo: case
  IndentOneStep: false

1 (default):

output = case variable
         when 'value1'
           'output1'
         else
           'output2'
         end

2:

output = case variable
when 'value1'
  'output1'
else
  'output2'
end

3:

output = case variable
           when 'value1'
             'output1'
           else
             'output2'
         end

4:

output = case variable
  when 'value1'
    'output1'
  else
    'output2'
end

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

Successfully merging a pull request may close this issue.

3 participants