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

Style/CaseIndentation doesn't recognize single-line case statements. #4128

Closed
jayhendren opened this issue Mar 15, 2017 · 2 comments
Closed
Labels

Comments

@jayhendren
Copy link

Expected behavior

I expect the following code to pass Rubocop:

def mock_node(group, policy, number)
  net = case group; when 'dev' then 1; when 'prod' then 2; else 0; end 
  subnet = case policy; when 'varn' then 1; when 'web' then 2; else 0; end 
  # more method body here
end

Actual behavior

The above code fails, since Rubocop appears to expect all case statements to span multiple lines:

$ rubocop -fs  
== my_file.rb ==
C:  6: 25: Indent when as deep as case.
C:  6: 44: Indent when as deep as case.
C:  7: 29: Indent when as deep as case.
C:  7: 49: Indent when as deep as case.

[snip]

RuboCop version

0.46.0 (using Parser 2.3.3.1, running on ruby 2.3.1 x86_64-linux)
@jayhendren jayhendren changed the title "Indent when as deep as case" doesn't recognize single-line case statements. Style/CaseIndentation doesn't recognize single-line case statements. Mar 15, 2017
@bbatsov bbatsov added the bug label Mar 16, 2017
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 16, 2017

Good catch! Guess this illustrates how uncommon are those in practice.

I find those very hard to read, so I'd suggest also adding some cop to detect them. :-)

@jayhendren
Copy link
Author

Yeah, something like net = {'dev' => 1, 'prod' => 2}.fetch(group, 0) would probably work just as well in this scenario. Personally, I have no strong opinions on whether or not that style is easier to read.

Drenmi added a commit to Drenmi/rubocop that referenced this issue Mar 22, 2017
…enses on single line case statements

This cop would register indentation offenses on single-line case
statements. This change fixes that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants