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

Style/OperatorMethodCall incorrectly flags module methods #11107

Closed
CodingAnarchy opened this issue Oct 22, 2022 · 0 comments · Fixed by #11108
Closed

Style/OperatorMethodCall incorrectly flags module methods #11107

CodingAnarchy opened this issue Oct 22, 2022 · 0 comments · Fixed by #11108
Labels

Comments

@CodingAnarchy
Copy link

Style/OperatorMethodCall incorrectly flags cases where the call is from a module or a class method, rather than the instance method that is normally associated with the operator.

E.g. Sequel.- produces an object that is used for generating an SQL query, and does not perform the operator, while foo - bar calls the instance method foo#-.


Expected behavior

This cop should be considered as unsafe for auto-correction, or should ignore non-instance method cases.

Actual behavior

Sequel.- was autocorrected to Sequel -, which then produced errors on load as the Ruby syntax is interpreted as invalid.

Steps to reproduce the problem

Use a module or class method for an operator, and have the corrector modify this to an invalid syntax.

In our case, Sequel.-(foo, bar) was converted to Sequel -(foo, bar) which broke the Ruby interpreter when trying to parse that code.

RuboCop version

$ [bundle exec] rubocop -V
1.37.0 (using Parser 3.1.2.1, rubocop-ast 1.23.0, running on ruby 3.1.2) [arm64-darwin21]
  - rubocop-performance 1.15.0
  - rubocop-rails 2.17.0
  - rubocop-sorbet 0.6.11
@CodingAnarchy CodingAnarchy changed the title Style/OperatorMethodCall incorrectly flags non-instance methods (which are not operators) Style/OperatorMethodCall incorrectly flags module methods Oct 22, 2022
@koic koic added the bug label Oct 22, 2022
koic added a commit to koic/rubocop that referenced this issue Oct 22, 2022
Fixes rubocop#11107.

This PR fixes a false positive for `Style/OperatorMethodCall`
when a constant receiver uses an operator method.
bbatsov pushed a commit that referenced this issue Oct 22, 2022
Fixes #11107.

This PR fixes a false positive for `Style/OperatorMethodCall`
when a constant receiver uses an operator method.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants