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

Enable Layout/EmptyLineAfterGuardClause cop #348

Merged
merged 1 commit into from
Jan 17, 2022

Conversation

sambostock
Copy link
Contributor

This enables the Layout/EmptyLineAfterGuardClause cop, which is autocorrectable.

From the documentation

# bad
def foo
  return if need_return?
  bar
end

# good
def foo
  return if need_return?

  bar
end

# good
def foo
  return if something?
  return if something_different?

  bar
end

# also good
def foo
  if something?
    do_something
    return if need_return?
  end
end

@rafaelfranca
Copy link
Member

How many violations for this cop do we have in core?

@sambostock
Copy link
Contributor Author

@rafaelfranca, 8,271 offenses detected, all auto-correctable though

@sambostock sambostock merged commit e10225a into main Jan 17, 2022
@sambostock sambostock deleted the enable-empty-line-after-guard-clause branch January 17, 2022 20:00
@@ -25,7 +25,7 @@ Layout/CaseIndentation:
EnforcedStyle: end

Layout/EmptyLineAfterGuardClause:
Enabled: false
Enabled: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick but for next time we can simply remove this entry from the config as this cop is enabled by default. We only need to explicitly enable true for recent cops that are still in a "pending" state.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I should have removed it and run the tests, which would have revealed the change to the full config.

@miry
Copy link
Contributor

miry commented Mar 11, 2022

I wonder how it would looks like for case. Example I have bar?, that is part of bar and now it looks like bar? is part of section quux.

def foo
  quux
  quux
  quux
  return if bar?

  bar
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 this pull request may close these issues.

None yet

7 participants