Skip to content

Conversation

ydah
Copy link
Member

@ydah ydah commented Oct 2, 2025

This PR add SupportedMethods configuration to RSpec/RedundantPredicateMatcher cop.
Fixes: #2012

This change involves trade-offs. Previously, we could specify replaceable method names in a hard-coded manner, which allowed us to use RESTRICT_ON_SEND. However, now that the decision is based on values set in the config, RESTRICT_ON_SEND can no longer be used. Additionally, since be_all requires special internal processing, it's difficult to create this cop generically with Config, leaving special handling for be_all inside the implementation.

However, this change enables the ResultPredictedMatcher cop to determine which cops trigger violations through Config. For example, when using Cucumber, this allows you to exclude only match from violations. As mentioned earlier though, this change involves trade-offs, so if these trade-offs are unacceptable, we need to discard this change. I think it's fine to discard it if necessary.


Before submitting the PR make sure the following are checked:

  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Updated documentation.
  • Added an entry to the CHANGELOG.md if the new code introduces user-observable changes.
  • The build (bundle exec rake) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).

If you have modified an existing cop's configuration options:

  • Set VersionChanged: "<<next>>" in config/default.yml.

…r` cop

This PR add SupportedMethods configuration to `RSpec/RedundantPredicateMatcher` cop.
Fixes: #2012

This change involves trade-offs. Previously, we could specify replaceable method names in a hard-coded manner, which allowed us to use RESTRICT_ON_SEND. However, now that the decision is based on values set in the config, RESTRICT_ON_SEND can no longer be used. Additionally, since `be_all` requires special internal processing, it's difficult to create this cop generically with Config, leaving special handling for `be_all` inside the implementation.

However, this change enables the `ResultPredictedMatcher` cop to determine which cops trigger violations through Config. For example, when using Cucumber, this allows you to exclude only `match` from violations. As mentioned earlier though, this change involves trade-offs, so if these trade-offs are unacceptable, we need to discard this change. I think it's fine to discard it if necessary.
@ydah ydah requested a review from a team as a code owner October 2, 2025 16:31
Copy link
Collaborator

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

I think the tradeoffs are fair. Should we ask @pirj to review too?

def on_send(node)
return if node.parent.block_type? || node.arguments.empty?
return unless replaceable_arguments?(node)
return unless !node.parent&.block_type? && !node.arguments.empty?
Copy link
Collaborator

Choose a reason for hiding this comment

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

I find this line much harder to read than the original line. We could even change it to

return if node.parent.block_type?
return if node.arguments.empty?

However you added a &. so there’s special handling if node.parent.nil?

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.

RedundantPredicateMatcher is not a safe autocorrect
2 participants