diff --git a/CHANGELOG.md b/CHANGELOG.md index 33747b2dd..f96ca1a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Master (Unreleased) * Remove deprecated class `::RuboCop::Cop::RSpec::Cop`. ([@bquorning][]) +* Retire `RSpec/InvalidPredicateMatcher` cop. ([@pirj][]) ## 2.0.0.pre (2020-10-22) diff --git a/config/default.yml b/config/default.yml index d3c3809dd..240e8fb63 100644 --- a/config/default.yml +++ b/config/default.yml @@ -315,12 +315,6 @@ RSpec/InstanceVariable: VersionChanged: '1.7' StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable -RSpec/InvalidPredicateMatcher: - Description: Checks invalid usage for predicate matcher. - Enabled: true - VersionAdded: '1.16' - StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InvalidPredicateMatcher - RSpec/ItBehavesLike: Description: Checks that only one `it_behaves_like` style is used. Enabled: true diff --git a/docs/modules/ROOT/pages/cops.adoc b/docs/modules/ROOT/pages/cops.adoc index 002fffa62..4330d141f 100644 --- a/docs/modules/ROOT/pages/cops.adoc +++ b/docs/modules/ROOT/pages/cops.adoc @@ -40,7 +40,6 @@ * xref:cops_rspec.adoc#rspecimplicitsubject[RSpec/ImplicitSubject] * xref:cops_rspec.adoc#rspecinstancespy[RSpec/InstanceSpy] * xref:cops_rspec.adoc#rspecinstancevariable[RSpec/InstanceVariable] -* xref:cops_rspec.adoc#rspecinvalidpredicatematcher[RSpec/InvalidPredicateMatcher] * xref:cops_rspec.adoc#rspecitbehaveslike[RSpec/ItBehavesLike] * xref:cops_rspec.adoc#rspeciteratedexpectation[RSpec/IteratedExpectation] * xref:cops_rspec.adoc#rspecleadingsubject[RSpec/LeadingSubject] diff --git a/docs/modules/ROOT/pages/cops_rspec.adoc b/docs/modules/ROOT/pages/cops_rspec.adoc index f14ccce99..b83ca747a 100644 --- a/docs/modules/ROOT/pages/cops_rspec.adoc +++ b/docs/modules/ROOT/pages/cops_rspec.adoc @@ -1984,38 +1984,6 @@ end * https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InstanceVariable -== RSpec/InvalidPredicateMatcher - -|=== -| Enabled by default | Safe | Supports autocorrection | VersionAdded | VersionChanged - -| Enabled -| Yes -| No -| 1.16 -| - -|=== - -Checks invalid usage for predicate matcher. - -Predicate matcher does not need a question. -This cop checks an unnecessary question in predicate matcher. - -=== Examples - -[source,ruby] ----- -# bad -expect(foo).to be_something? - -# good -expect(foo).to be_something ----- - -=== References - -* https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/InvalidPredicateMatcher - == RSpec/ItBehavesLike |=== diff --git a/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb b/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb deleted file mode 100644 index 018b5c9ff..000000000 --- a/lib/rubocop/cop/rspec/invalid_predicate_matcher.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -module RuboCop - module Cop - module RSpec - # Checks invalid usage for predicate matcher. - # - # Predicate matcher does not need a question. - # This cop checks an unnecessary question in predicate matcher. - # - # @example - # - # # bad - # expect(foo).to be_something? - # - # # good - # expect(foo).to be_something - class InvalidPredicateMatcher < Base - MSG = 'Omit `?` from `%s`.' - - def_node_matcher :invalid_predicate_matcher?, <<-PATTERN - (send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?)) - PATTERN - - def on_send(node) - invalid_predicate_matcher?(node) do |predicate| - add_offense(predicate, - message: format(MSG, matcher: predicate.method_name)) - end - end - - private - - def predicate?(name) - name = name.to_s - name.start_with?('be_', 'have_') && name.end_with?('?') - end - end - end - end -end diff --git a/lib/rubocop/cop/rspec_cops.rb b/lib/rubocop/cop/rspec_cops.rb index 22599a760..1de7e025d 100644 --- a/lib/rubocop/cop/rspec_cops.rb +++ b/lib/rubocop/cop/rspec_cops.rb @@ -52,7 +52,6 @@ require_relative 'rspec/implicit_subject' require_relative 'rspec/instance_spy' require_relative 'rspec/instance_variable' -require_relative 'rspec/invalid_predicate_matcher' require_relative 'rspec/it_behaves_like' require_relative 'rspec/iterated_expectation' require_relative 'rspec/leading_subject' diff --git a/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb b/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb deleted file mode 100644 index 19715e16a..000000000 --- a/spec/rubocop/cop/rspec/invalid_predicate_matcher_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true - -RSpec.describe RuboCop::Cop::RSpec::InvalidPredicateMatcher do - subject(:cop) { described_class.new } - - it 'registers an offense for double question' do - expect_offense(<<-RUBY) - expect(foo).to be_something? - ^^^^^^^^^^^^^ Omit `?` from `be_something?`. - RUBY - end - - it 'registers an offense for double question with `not_to`' do - expect_offense(<<-RUBY) - expect(foo).not_to be_something? - ^^^^^^^^^^^^^ Omit `?` from `be_something?`. - RUBY - end - - it 'registers an offense for double question with `to_not`' do - expect_offense(<<-RUBY) - expect(foo).to_not be_something? - ^^^^^^^^^^^^^ Omit `?` from `be_something?`. - RUBY - end - - it 'registers an offense for double question with `have_something?`' do - expect_offense(<<-RUBY) - expect(foo).to have_something? - ^^^^^^^^^^^^^^^ Omit `?` from `have_something?`. - RUBY - end - - it 'accepts valid predicate matcher' do - expect_no_offenses(<<-RUBY) - expect(foo).to be_something - RUBY - end -end