-
-
Notifications
You must be signed in to change notification settings - Fork 283
Add SupportedMethods configuration to RSpec/RedundantPredicateMatcher
cop
#2121
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
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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?
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. |
@bquorning @pirj I showed a different approach. This might be better. How is it? |
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 forbe_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 onlymatch
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:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.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:
VersionChanged: "<<next>>"
inconfig/default.yml
.