Class: RuboCop::Cop::Rubomatic::Style::DisallowedMethods
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Rubomatic::Style::DisallowedMethods
- Defined in:
- lib/rubocop/cop/rubomatic/style/disallowed_methods.rb
Constant Summary collapse
- MESSAGES =
In many cases, you can use a node matcher for matching node pattern. See github.com/rubocop/rubocop-ast/blob/master/lib/rubocop/ast/node_pattern.rb
For example
{ abort: 'Use `#raise` instead of `#abort`.', tap: 'Do not use `#tap`' }.freeze
- RESTRICT_ON_SEND =
‘on_send` will only be called if the method name is in this list
%i[abort tap].freeze
Instance Method Summary collapse
-
#on_send(node) ⇒ void
The main logic method of the cop.
- #using_abort?(node) ⇒ Object
- #using_tap?(node) ⇒ Object
Instance Method Details
#on_send(node) ⇒ void
This method returns an undefined value.
The main logic method of the cop
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/rubocop/cop/rubomatic/style/disallowed_methods.rb', line 34 def on_send(node) = if using_abort?(node) :abort elsif using_tap?(node) :tap end return if .nil? add_offense(node, message: MESSAGES.fetch()) end |
#using_abort?(node) ⇒ Object
21 22 23 |
# File 'lib/rubocop/cop/rubomatic/style/disallowed_methods.rb', line 21 def_node_matcher :using_abort?, <<~PATTERN (send nil? :abort ...) PATTERN |
#using_tap?(node) ⇒ Object
26 27 28 |
# File 'lib/rubocop/cop/rubomatic/style/disallowed_methods.rb', line 26 def_node_matcher :using_tap?, <<~PATTERN (send nil? :tap ...) PATTERN |