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

Feature request: empty line after early return #5376

Closed
Darhazer opened this issue Jan 2, 2018 · 2 comments
Closed

Feature request: empty line after early return #5376

Darhazer opened this issue Jan 2, 2018 · 2 comments

Comments

@Darhazer
Copy link
Member

Darhazer commented Jan 2, 2018

It would be nice to have a cop that enforces consistent usage of empty lines after early returns.
Example:

 def on_block(node)
  return unless style == :method_call
  add_offense(node) if expect_change_with_block?(node)
end

Here the cop would require adding a blank line after the return.

Note: it's possible tho have multiple consecutive return statements with different conditions. In that case I would suggest adding the blank line after the last return.

@bbatsov
Copy link
Collaborator

bbatsov commented Jan 2, 2018

Yeah, that makes perfect sense to me. It's an extremely common style of coding, practiced by myself as well.

@Drenmi
Copy link
Collaborator

Drenmi commented Jan 2, 2018

I have had this on my list for a while, but I imagine an EmptyLinesAroundGuardClause, which would cover things like next as well. 🙂

koic added a commit to koic/rubocop that referenced this issue Jan 30, 2018
Follow up of rubocop#5376 and rubocop#5522.

The full fix is left to autocorrect after rubocop#5522 is implemented.
This PR is updating template string and document which are not modified by autocorrect.

Since the template becomes baseline of code, This PR changed it ahead of time.
@koic koic mentioned this issue Jan 30, 2018
8 tasks
bbatsov pushed a commit that referenced this issue Jan 30, 2018
Follow up of #5376 and #5522.

The full fix is left to autocorrect after #5522 is implemented.
This PR is updating template string and document which are not modified by autocorrect.

Since the template becomes baseline of code, This PR changed it ahead of time.
unkmas added a commit to unkmas/rubocop that referenced this issue Feb 27, 2018
unkmas added a commit to unkmas/rubocop that referenced this issue Feb 27, 2018
unkmas added a commit to unkmas/rubocop that referenced this issue Feb 27, 2018
koic added a commit to koic/rubocop that referenced this issue Aug 30, 2018
This PR enables `Layout/EmptyLineAfterGuardClause` cop by default.

This cop has been introduced by rubocop#5522, with setting that is
disabled by default. After that, I improved this cop by
rubocop#5679, rubocop#5700, rubocop#5720, and rubocop#5760.

I think that this cop can be enabled by default as the background
of the issue rubocop#5376.

And this PR applies auto-correction using this cop.
bbatsov pushed a commit that referenced this issue Aug 30, 2018
This PR enables `Layout/EmptyLineAfterGuardClause` cop by default.

This cop has been introduced by #5522, with setting that is
disabled by default. After that, I improved this cop by
#5679, #5700, #5720, and #5760.

I think that this cop can be enabled by default as the background
of the issue #5376.

And this PR applies auto-correction using this cop.
snh added a commit to github/pages-health-check that referenced this issue Sep 20, 2018
Layout/EmptyLineAfterGuardClause: Add empty line after guard clause. 
rubocop/rubocop#5376
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

3 participants