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

Check indentation of conditionals spanning multiple lines #1321

Closed
bquorning opened this issue Sep 2, 2014 · 9 comments
Closed

Check indentation of conditionals spanning multiple lines #1321

bquorning opened this issue Sep 2, 2014 · 9 comments
Assignees

Comments

@bquorning
Copy link
Contributor

When breaking a line into multiple lines, we should check the indentation of the all lines, not just the first one.

# nodoc
class Foo
  # Offending indentation detected.
  def bar
     something ||
       something_else
  end

  # No offense detected?
  def bar
    something +
    something_else
  end

  # No offense detected?
  def bar
    something
     .something_else
  end

  # Correctly indented
  def bar
    something &&
      something_else
  end

  # No offense detected?
  def bar
    something *
       something_else
  end
end
@bbatsov
Copy link
Collaborator

bbatsov commented Sep 12, 2014

Sounds like a task for the mighty @jonas054 :-)

@jonas054 jonas054 self-assigned this Sep 12, 2014
@jonas054
Copy link
Collaborator

😊 Alright.

@jonas054
Copy link
Collaborator

I'm slowly working towards a solution, just so you know. 😄 There are quite a few cases to consider.

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 23, 2014

@jonas054 You should also consider cases like:

if something &&
   something_else

Ideally, something and something_else should be vertically aligned. Same goes for other operators in similar contexts.

@bquorning
Copy link
Contributor Author

Ideally, something and something_else should be vertically aligned.

I’d vote for consistent 2-space indentation anytime:

if something &&
  something_else

elsif something &&
  something_else

while something &&
  something_else

until something &&
  something_else

unless something &&
  something_else

Maybe it should be a configuration option?

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 23, 2014

I’d vote for consistent 2-space indentation anytime:

This obscures that you're actually continuing the condition, not the if. If it's 2-space indentation - your examples should look like this (or at least I think so):

if something &&
     something_else

Maybe it should be a configuration option?

I'm fine with that, as long as vertical alignment is the default.

@jonas054
Copy link
Collaborator

@bquorning 👍 on configuration option.

@bbatsov Your vertical alignment idea looks pretty good. It's just that it's not how emacs indents it (maybe you have a better ruby-mode than I do). And it's not the style we've used in our own code. Are you sure you want to make it the default?

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 23, 2014

It's just that it's not how emacs indents it (maybe you have a better ruby-mode than I do).

This was changed in 24.4.

And it's not the style we've used in our own code. Are you sure you want to make it the default?

In the beginning I was still using Emacs 24.3. :-) Yeah, seems like a pretty good default to me (and it's consistent with what you get in the presence of parens.

@jonas054
Copy link
Collaborator

Good! That settles it. I'll get working.

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

3 participants