Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'rubocop/cop/rspec/any_instance_of.rb')
-rw-r--r--rubocop/cop/rspec/any_instance_of.rb29
1 files changed, 14 insertions, 15 deletions
diff --git a/rubocop/cop/rspec/any_instance_of.rb b/rubocop/cop/rspec/any_instance_of.rb
index a939af36c13..e1cacfebfd3 100644
--- a/rubocop/cop/rspec/any_instance_of.rb
+++ b/rubocop/cop/rspec/any_instance_of.rb
@@ -24,7 +24,9 @@ module RuboCop
# expect(instance).to receive(:invalidate_issue_cache_counts)
# end
#
- class AnyInstanceOf < RuboCop::Cop::Cop
+ class AnyInstanceOf < RuboCop::Cop::Base
+ extend RuboCop::Cop::AutoCorrector
+
MESSAGE_EXPECT = 'Do not use `expect_any_instance_of` method, use `expect_next_instance_of` instead.'
MESSAGE_ALLOW = 'Do not use `allow_any_instance_of` method, use `allow_next_instance_of` instead.'
@@ -37,22 +39,19 @@ module RuboCop
def on_send(node)
if expect_any_instance_of?(node)
- add_offense(node, location: :expression, message: MESSAGE_EXPECT)
+ add_offense(node, message: MESSAGE_EXPECT) do |corrector|
+ corrector.replace(
+ node.loc.expression,
+ replacement_any_instance_of(node, 'expect')
+ )
+ end
elsif allow_any_instance_of?(node)
- add_offense(node, location: :expression, message: MESSAGE_ALLOW)
- end
- end
-
- def autocorrect(node)
- replacement =
- if expect_any_instance_of?(node)
- replacement_any_instance_of(node, 'expect')
- elsif allow_any_instance_of?(node)
- replacement_any_instance_of(node, 'allow')
+ add_offense(node, message: MESSAGE_ALLOW) do |corrector|
+ corrector.replace(
+ node.loc.expression,
+ replacement_any_instance_of(node, 'allow')
+ )
end
-
- lambda do |corrector|
- corrector.replace(node.loc.expression, replacement)
end
end