Class: Rubocop::Cop::InternalAffairs::DeprecateCopHelper

Inherits:
RuboCop::Cop::Base
  • Object
show all
Defined in:
lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb

Overview

Cop that denies the use of CopHelper.

Examples:

# bad
include CopHelper

inspect_source(<<~RUBY)
  #....
RUBY

# good
expect_offense(<<~RUBY)
  # ....
RUBY

Constant Summary collapse

MSG =
'Do not use `CopHelper` or methods from it, use improved patterns described in https://www.rubydoc.info/gems/rubocop/RuboCop/RSpec/ExpectOffense'

Instance Method Summary collapse

Instance Method Details

#cop_helper(node) ⇒ Object



23
24
25
26
# File 'lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb', line 23

def_node_matcher :cop_helper, <<~PATTERN
  (send nil? ${:include :extend :prepend}
    (const _ {:CopHelper}))
PATTERN

#cop_helper_method(node) ⇒ Object



29
30
31
# File 'lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb', line 29

def_node_search :cop_helper_method, <<~PATTERN
  (send nil? {:inspect_source :inspect_source_file :parse_source :autocorrect_source_file :autocorrect_source :_investigate} ...)
PATTERN

#cop_helper_method_on_instance(node) ⇒ Object



34
35
36
# File 'lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb', line 34

def_node_search :cop_helper_method_on_instance, <<~PATTERN
  (send (send nil? _) {:messages :highlights :offenses} ...)
PATTERN

#on_send(node) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rubocop/cop/internal_affairs/deprecate_cop_helper.rb', line 38

def on_send(node)
  cop_helper(node) do
    add_offense(node)
  end

  cop_helper_method(node) do
    add_offense(node)
  end

  cop_helper_method_on_instance(node) do
    add_offense(node)
  end
end