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

EndAlignment method chaining #346

Closed
lenntt opened this issue Jul 10, 2013 · 3 comments
Closed

EndAlignment method chaining #346

lenntt opened this issue Jul 10, 2013 · 3 comments
Labels

Comments

@lenntt
Copy link

lenntt commented Jul 10, 2013

I have some interesting code, that doesnt pass the EndAligntment checks (rubocop fails on the do..end blocks):

def foo(bar)
  bar.get_stuffs
      .select {|stuff| stuff.present?}
      .select {|stuff| stuff.attribute == 'whatever'}
      .reject do |stuff| 
        stuff.with_a_very_long_expression_that_doesnt_fit_the_line
      end.select do |stuff|
        stuff.another_very_long_expression_that_doesnt_fit_the_line
      end
      .select do |stuff|
        stuff.another_very_long_expression_that_doesnt_fit_the_line
      end
end

I've tried (as the example shows) both putting the .select on the same line and on the next line.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 10, 2013

@jonas054 I guess you should tackle this one as well.

@jonas054
Copy link
Collaborator

I'd actually like to pass the ball to @edzhelyov. The above code is a good example of the "start of the line where do is" idea that he brought up in #338. OK @edzhelyov?

BTW, even the mighty Emacs has trouble indenting the above code, and the result is less logical than how @SirLenz0rlot did it. It does pass rubocop's inspection though. Here it is:

def foo(bar)
  bar.get_stuffs
    .select {|stuff| stuff.present?}
    .select {|stuff| stuff.attribute == 'whatever'}
    .reject do |stuff| 
    stuff.with_a_very_long_expression_that_doesnt_fit_the_line
  end.select do |stuff|
    stuff.another_very_long_expression_that_doesnt_fit_the_line
  end
    .select do |stuff|
    stuff.another_very_long_expression_that_doesnt_fit_the_line
  end
end

Again, this is by no means better. I just wanted to show it as an example of how complex the problem is.

@jonas054
Copy link
Collaborator

jonas054 commented Aug 3, 2013

The solution for this issue has been removed because we don't want to encourage multiline chaining of blocks. The Ruby Style Guide says that multiline chaining is ugly.

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

3 participants