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

Guard clauses on multi-line statements #3570

Closed
booch opened this issue Oct 4, 2016 · 5 comments
Closed

Guard clauses on multi-line statements #3570

booch opened this issue Oct 4, 2016 · 5 comments

Comments

@booch
Copy link

booch commented Oct 4, 2016

In doing a code review, I came across something like the following:

      foo[:bar] = {
        # Several more lines
      } unless baz.nil?

I was rather surprised that RuboCop didn't flag that. Guard clauses are great, but if the guard clause is so far away from the beginning of the statement, it gets too confusing. This seems like a cop worth adding. (And I suppose there should be a corresponding change to the Ruby style guide.)

@bbatsov
Copy link
Collaborator

bbatsov commented Oct 4, 2016

Agreed.

@palkan
Copy link
Contributor

palkan commented Oct 12, 2016

if the guard clause is so far away from the beginning of the statement

How many lines are "so far away"? I think, >1. Or should it be configurable?

@Drenmi
Copy link
Collaborator

Drenmi commented Oct 12, 2016

How many lines are "so far away"? I think, >1. Or should it be configurable?

+1 for "more than one." I think multiline is the most unambiguous and least arbitrary condition.

@tessi
Copy link
Contributor

tessi commented Oct 15, 2016

I'm 👍 for that change and startet with proposing that advise to the styleguide. As I'm new to rubocop, I am not sure yet how to implement this best in rubocop. We'll see if I can manage to follow up with a PR.

@tessi
Copy link
Contributor

tessi commented Oct 17, 2016

There is a PR now (#3636). I'd be happy for some reviews :)

bbatsov added a commit that referenced this issue Oct 24, 2016
…ti-line-statements

[Fix #3570] avoid if-modifiers on multi-line statements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants