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

Support autocorrection for Lint/EnsureReturn #7934

Merged

Conversation

koic
Copy link
Member

@koic koic commented May 6, 2020

This PR supports autocorrection for Lint/EnsureReturn.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

Copy link
Collaborator

@bbatsov bbatsov left a comment

Choose a reason for hiding this comment

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

Looks good!

This PR supports autocorrection for `Lint/EnsureReturn`.
@koic koic force-pushed the support_autocorrect_for_lint_ensure_return branch from 987ecec to 813ff4b Compare May 10, 2020 12:25
@koic koic merged commit 6329595 into rubocop:master May 10, 2020
@koic koic deleted the support_autocorrect_for_lint_ensure_return branch May 10, 2020 13:03
@marcandre
Copy link
Contributor

Sadly, these autocorrections are not producing equivalent code. Removing the return like this can change the control flow within the ensure block:

ensure
  return foo if condition
  do_something_else
# can not be corrected to
ensure
  foo if condition
  do_something_else

More importantly, even when there are no exceptions raised any autocorrection changes the return value (as the result of the ensure block is ignored)

This autocorrection could also swallow user comments.

I don't know why, but this PR also stopped flagging returns with multiple values, but the argument against return in ensure is the same.

I'm reverting this in #8388

marcandre added a commit to marcandre/rubocop that referenced this pull request Jul 23, 2020
… multi-value returns

It is not possible to autocorrect a `return` in an `ensure`, as not only does it
modify control flow without the ensure block, it also overrides the normal return
value

This reverts rubocop#7934
marcandre added a commit that referenced this pull request Jul 23, 2020
…value returns

It is not possible to autocorrect a `return` in an `ensure`, as not only does it
modify control flow without the ensure block, it also overrides the normal return
value

This reverts #7934
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

3 participants