-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Remove unnecessary early return in RSpec/ContextWording
cop
#1981
Conversation
I’m quite concerned if we had a method, and it was not fully covered with specs, and now we’re refactoring it to a node pattern where coverage is not calculated, can we say that it does the same thing with certainty? Node patterns support inline comments, but we rarely use that, and it’s not always useful. With all this, I think in this case a node pattern is inferior to a method. |
be4954b
to
d749bb7
Compare
allowed?
method for pattern validationRSpec/ContextWording
cop
@pirj It is certainly not a good choice to replace it with a node pattern for which coverage is not calculated. |
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.
Nice refactoring!
Great to see it’s getting us to 100% coverage
Another pair of eyes in case I’m missing something this early morning, @rubocop/rubocop-rspec ? |
Isn’t the reason we didn’t have complete spec coverage before that we never hit a case where |
@bquorning That spec is available here: |
Checks if `allowed_patterns` is empty, but looking at the implementation of `matches_allowed_pattern?`, it refers to it as `allowed_patterns.any?`, so `return false if allowed_patterns .empty?` is a completely unnecessary early return. https://github.com/rubocop/rubocop/blob/e7ccb0200d013d1c4b75b3face0dea0538620769/lib/rubocop/cop/mixin/allowed_pattern.rb#L29-L31 ``` def matches_allowed_pattern?(line) allowed_patterns.any? { |pattern| Regexp.new(pattern).match?(line) } end ```
Close this PR because it was found to operate differently from the current specification. |
Checks if
allowed_patterns
is empty, but looking at the implementation ofmatches_allowed_pattern?
, it refers to it asallowed_patterns.any?
, soreturn false if allowed_patterns .empty?
is a completely unnecessary early return.https://github.com/rubocop/rubocop/blob/e7ccb0200d013d1c4b75b3face0dea0538620769/lib/rubocop/cop/mixin/allowed_pattern.rb#L29-L31
also resolve: #1972
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).