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 #370] Fix an incorrect autocorrect for Performance/RedundantMatch #371

Conversation

ymap
Copy link
Contributor

@ymap ymap commented Sep 14, 2023

Fixes #370.

This PR fixes an incorrect autocorrect for Performance/RedundantMatch when expressions with lower precedence than =~ are used as an argument.


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.

@ymap ymap marked this pull request as ready for review September 14, 2023 01:26
Comment on lines 76 to 78
return requires_parentheses_for_call_like?(arg) if call_like?(arg)

false
Copy link
Member

Choose a reason for hiding this comment

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

Can you refactor?

Suggested change
return requires_parentheses_for_call_like?(arg) if call_like?(arg)
false
call_like?(arg) && requires_parentheses_for_call_like?(arg)

Comment on lines 82 to 85
return false if arg.parenthesized? || !arg.arguments?
return false if HIGHER_PRECEDENCE_OPERATOR_METHODS.include?(arg.method_name)

true
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
return false if arg.parenthesized? || !arg.arguments?
return false if HIGHER_PRECEDENCE_OPERATOR_METHODS.include?(arg.method_name)
true
return false if arg.parenthesized? || !arg.arguments?
!HIGHER_PRECEDENCE_OPERATOR_METHODS.include?(arg.method_name)

@ymap ymap force-pushed the fix_an_incorrect_autocorrect_for_performance_redundant_match branch from 4742c2a to 5e13cd1 Compare September 15, 2023 09:40
…dantMatch`

Fixes rubocop#370.

This PR fixes an incorrect autocorrect for `Performance/RedundantMatch`
when expressions with lower precedence than `=~` are used as an argument.
@ymap ymap force-pushed the fix_an_incorrect_autocorrect_for_performance_redundant_match branch from 5e13cd1 to 563e8f9 Compare September 15, 2023 09:41
@ymap
Copy link
Contributor Author

ymap commented Sep 15, 2023

@koic Thanks for the suggestions! Amended the changes.

@koic koic merged commit cde0912 into rubocop:master Sep 15, 2023
10 checks passed
@koic
Copy link
Member

koic commented Sep 15, 2023

Thanks!

@ymap ymap deleted the fix_an_incorrect_autocorrect_for_performance_redundant_match branch September 15, 2023 16:10
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.

Incorrect autocorrect for Performance/RedundantMatch cop
2 participants