Class: RuboCop::Cop::InternalAffairs::RequireRestrictOnSend
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::InternalAffairs::RequireRestrictOnSend
- Defined in:
- lib/rubocop/cop/internal_affairs/require_restrict_on_send.rb
Overview
Check for missing ‘RESTRICT_ON_SEND`.
NOTE: This works for us because we do not write cops that investigate every send node. Upstream Rubocop chose not to implement this as there are many cops in Core that investigate every node.
Constant Summary collapse
- MSG =
"Missing `RESTRICT_ON_SEND` declaration when using `on_send` or `after_send`."
Instance Method Summary collapse
- #cop_class_def(node) ⇒ Object
- #defined_send_callback?(node) ⇒ Object
- #on_class(node) ⇒ Object
- #restrict_on_send?(node) ⇒ Object
Instance Method Details
#cop_class_def(node) ⇒ Object
45 46 47 48 49 |
# File 'lib/rubocop/cop/internal_affairs/require_restrict_on_send.rb', line 45 def_node_matcher :cop_class_def, <<~PATTERN (class _ (const {nil? (const nil? :Cop) (const (const {cbase nil?} :RuboCop) :Cop)} {:Base :Cop}) ...) PATTERN |
#defined_send_callback?(node) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/rubocop/cop/internal_affairs/require_restrict_on_send.rb', line 30 def_node_search :defined_send_callback?, <<~PATTERN { (def {:on_send :after_send} ...) (alias (sym {:on_send :after_send}) _source ...) (send nil? :alias_method {(sym {:on_send :after_send}) (str {"on_send" "after_send"})} _source ...) } PATTERN |
#on_class(node) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'lib/rubocop/cop/internal_affairs/require_restrict_on_send.rb', line 51 def on_class(node) return if restrict_on_send?(node) # requirement met return unless defined_send_callback?(node) return unless cop_class_def(node) add_offense(node) end |
#restrict_on_send?(node) ⇒ Object
39 40 41 |
# File 'lib/rubocop/cop/internal_affairs/require_restrict_on_send.rb', line 39 def_node_search :restrict_on_send?, <<~PATTERN (casgn nil? :RESTRICT_ON_SEND ...) PATTERN |