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.

@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?

…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.
Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

I’m uncertain about this, especially considering that the behaviour of the suggested match matcher is not necessarily incorrect even for objects that are not regexp/string/hash/array.

be_exist: exist
be_exists: exist
be_include: include
be_match: match
Copy link
Member

Choose a reason for hiding this comment

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

Will our users have to configure the cop by copying over all this except the replacements they want to skip?

@luke-hill
Copy link
Contributor

Could we not do some sort of check whereby we detect if the method has been defined by the user. I'm not sure of the ruby internals, but if we could detect "where" the method was defined then this becomes a bit simpler.

ydah added a commit that referenced this pull request Oct 6, 2025
ydah added a commit that referenced this pull request Oct 6, 2025
@ydah
Copy link
Member Author

ydah commented Oct 6, 2025

@bquorning @pirj I showed a different approach. This might be better. How is it?

@ydah ydah closed this Oct 6, 2025
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

4 participants