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

Add new RSpec/RedundantPredicateMatcher cop #1694

Merged
merged 1 commit into from
Dec 10, 2023
Merged

Conversation

ydah
Copy link
Member

@ydah ydah commented Aug 12, 2023

Fix: #1689


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 created a new cop:

  • Added the new cop to config/default.yml.
  • The cop is configured as Enabled: pending in config/default.yml.
  • The cop is configured as Enabled: true in .rubocop.yml.
  • The cop documents examples of good and bad code.
  • The tests assert both that bad code is reported and that good code is not reported.
  • Set VersionAdded: "<<next>>" in default/config.yml.

@ydah ydah changed the title Add new RSpec/BuiltinMatcher cop Add new RSpec/RedundantPredicateMatcher cop Aug 14, 2023
@ydah ydah requested a review from pirj August 14, 2023 07:17
@ydah ydah force-pushed the add-builtin-matcher branch 2 times, most recently from 381ed44 to 43a0666 Compare August 25, 2023 14:53
@ydah ydah requested a review from pirj August 25, 2023 14:57
@ydah ydah force-pushed the add-builtin-matcher branch 4 times, most recently from ea4c936 to ceea042 Compare October 2, 2023 15:16
@ydah ydah requested a review from pirj October 2, 2023 15:16
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.

Fantastic! Thank you!

@pirj
Copy link
Member

pirj commented Oct 3, 2023

Broke on:

      expect(json[:submissions]).to be_all do |ss|
        ss.key?("submission_history") && ss["submission_history"].empty?
      end

with:

undefined method `send_type?' for nil:NilClass
/Users/pirj/source/rubocop-rspec/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb:47:in `replacable_arguments?'
/Users/pirj/source/rubocop-rspec/lib/rubocop/cop/rspec/redundant_predicate_matcher.rb:27:in `on_send'

Wondering why if node.parent.block_type? didn't work 🤔

@pirj
Copy link
Member

pirj commented Oct 3, 2023

Otherwise:

57497 files inspected, 883 offenses detected, 742 offenses autocorrectable

🎉

False positive? match takes a mandatory argument.

/Users/pirj/source/real-world-rspec/gitlabhq/spec/lib/gitlab/zoom_link_extractor_spec.rb:30:58: C: [Correctable] RSpec/RedundantPredicateMatcher: Use match instead of be_match.
        expect(described_class.new('issue text')).not_to be_match
                                                         ^^^^^^^^
module Gitlab
  class ZoomLinkExtractor
    # ...
    def match?
      ZOOM_REGEXP.match?(@text)
    end

Notes for future cops:

expect(json.count).to be_equal 1
expect(json[0]["group_submissions"]).to be_equal nil
expect(effective_paths.size).to be_eql(1)

@ydah ydah force-pushed the add-builtin-matcher branch 2 times, most recently from f619d04 to 398ce54 Compare December 6, 2023 11:17
@ydah ydah requested a review from pirj December 6, 2023 11:17
@ydah
Copy link
Member Author

ydah commented Dec 6, 2023

Sorry for the delay. I updated this PR with the following corrections:
#1694 (comment)
#1694 (comment)

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.

Thank you!

CHANGELOG.md Outdated Show resolved Hide resolved
@ydah ydah merged commit 6a21ef4 into master Dec 10, 2023
22 checks passed
@ydah ydah deleted the add-builtin-matcher branch December 10, 2023 08:43
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.

Cop idea: Replace be_exist and be_exists matchers with the exist built-in matcher
2 participants