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

Fix false negative in Style/ArgumentsForwarding when a block is forwarded but other args aren't #12541

Merged
merged 2 commits into from Dec 19, 2023

Conversation

dvandersluis
Copy link
Member

The following code gets registered as a false negative by Style/ArgumentsForwarding

def foo(*args, &block)
  bar(*args, &block)
  baz(&block)
end

Which results in the following invalid autocorrection (&block is now longer defined):

def foo(...)
  bar(...)
  baz(&block)
end

This change fixes that case by considering block arguments when determining if forwarding is possible.

This had two side effects:

  1. The test for different argument names failed due to the block parameter now being considered when determining if there is an offense. To fix this, we now check that the rest and kwrest arguments have the same name.
  2. This revealed a few offenses in rubocop code where only a block argument should have been replaced with forwarding.

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@dvandersluis dvandersluis force-pushed the fix/arguments-forwarding branch 2 times, most recently from 0a41f4d to 03180e7 Compare December 14, 2023 20:03
@bbatsov bbatsov merged commit 1b3c31b into rubocop:master Dec 19, 2023
28 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 19, 2023

Looks good! Thanks for tackling this!

@mvz
Copy link
Contributor

mvz commented Jan 15, 2024

The suggested correction seems to change the method's arity, which could be the wrong thing to do.

@mvz
Copy link
Contributor

mvz commented Jan 15, 2024

See #12618.

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