Skip to content

Commit

Permalink
Simplify and improve definition for def_modifier.
Browse files Browse the repository at this point in the history
Stricter check (used to check any child, including the receiver of the `send`)
  • Loading branch information
marcandre committed Mar 8, 2021
1 parent 5e0feb7 commit 89634c6
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Expand Up @@ -165,16 +165,17 @@ def arithmetic_operation?
ARITHMETIC_OPERATORS.include?(method_name)
end

# Checks if this node is part of a chain of `def` modifiers.
# @!method def_modifier?(node = self)
# Checks if this node is part of a chain of `def` or `defs` modifiers.
#
# @example
#
# private def foo; end
#
# @return [Boolean] whether the dispatched method is a `def` modifier
def def_modifier?
adjacent_def_modifier? || each_child_node(:send).any?(&:def_modifier?)
end
# @return [Boolean]
def_node_matcher :def_modifier?, <<~PATTERN
(send nil? _ {def defs #def_modifier?})
PATTERN

# Checks whether this is a lambda. Some versions of parser parses
# non-literal lambdas as a method send.
Expand Down

0 comments on commit 89634c6

Please sign in to comment.