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 positives for Style/OperatorMethodCall with named forwarding #13224

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

Earlopain
Copy link
Contributor

These cases are syntax errors as well, in addition to anonymous 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.

@@ -0,0 +1 @@
* [#13218](https://github.com/rubocop/rubocop/pull/13218): Fix false positives for `Style/OperatorMethodCall` with named forwarding. ([@earlopain][])
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* [#13218](https://github.com/rubocop/rubocop/pull/13218): Fix false positives for `Style/OperatorMethodCall` with named forwarding. ([@earlopain][])
* [#13224](https://github.com/rubocop/rubocop/pull/13224): Fix false positives for `Style/OperatorMethodCall` with named forwarding. ([@earlopain][])

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙄 I really want this checked in CI, somehow

@Earlopain Earlopain force-pushed the operator-method-forwarding branch from fcea24d to 135dad1 Compare September 11, 2024 18:11
Comment on lines 57 to 59
return DISALLOWED_ARG_TYPES.include?(argument.children.first&.type) if argument.hash_type?

argument.block_pass_type? && argument.source == '&'
DISALLOWED_ARG_TYPES.include?(argument.type)
Copy link
Member

Choose a reason for hiding this comment

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

It seems that the duplication with DISALLOWED_ARG_TYPES.include? below can be eliminated. However, the combination of the method name forwarding? and the constant name DISALLOWED_ARG_TYPES might still be a bit unclear.

         def forwarding?(argument)
           type = argument.hash_type? ? argument.children.first&.type : argument.type

           DISALLOWED_ARG_TYPES.include?(type)
         end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice suggestion, I like it. Renamed things a bit, so hopefully its clearer now

@Earlopain Earlopain force-pushed the operator-method-forwarding branch from 135dad1 to 8ea68f0 Compare September 11, 2024 20:01
def anonymous_forwarding?(argument)
return true if argument.forwarded_args_type? || argument.forwarded_restarg_type?
return true if argument.hash_type? && argument.children.first&.forwarded_kwrestarg_type?
def disallow_argument?(argument)
Copy link
Member

Choose a reason for hiding this comment

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

Hm, disallow_argument? might be a bit ambiguous. What do you think about the names invalid_syntax_argument? method and INVALID_SYNTAX_ARG_TYPES constant?

Suggested change
def disallow_argument?(argument)
def invalid_syntax_argument?(argument)

Or malformed_argument? and MALFORMED_ARG_TYPES, etc...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

invalid_syntax_argument sounds fine

These cases are syntax errors as well, in addition to anonymous forwarding
@Earlopain Earlopain force-pushed the operator-method-forwarding branch from 8ea68f0 to 9a97142 Compare September 12, 2024 16:10
@koic koic merged commit 9e6c529 into rubocop:master Sep 12, 2024
22 checks passed
@Earlopain Earlopain deleted the operator-method-forwarding branch September 13, 2024 12:37
Earlopain added a commit to Earlopain/rubocop that referenced this pull request Sep 13, 2024
Issues found with this:
* rubocop#13211
* rubocop#13215
* rubocop#13216
* rubocop#13219
* rubocop#13224
* rubocop#13225

I checked some repos in the rubocop org and they seem to not be affected by this change
bbatsov pushed a commit that referenced this pull request Sep 13, 2024
Issues found with this:
* #13211
* #13215
* #13216
* #13219
* #13224
* #13225

I checked some repos in the rubocop org and they seem to not be affected by this change
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.

2 participants