Tweak comments in AST::Util

This commit is contained in:
Sijawusz Pur Rahnama 2022-11-15 17:41:53 +01:00
parent 2fb37da80f
commit 76a4209706

View file

@ -91,7 +91,7 @@ module Ameba::AST::Util
node_lines.join('\n') node_lines.join('\n')
end end
# Returns true if node is a flow command, false - otherwise. # Returns `true` if node is a flow command, `false` otherwise.
# Node represents a flow command if it is a control expression, # Node represents a flow command if it is a control expression,
# or special call node that interrupts execution (i.e. raise, exit, abort). # or special call node that interrupts execution (i.e. raise, exit, abort).
def flow_command?(node, in_loop) def flow_command?(node, in_loop)
@ -107,7 +107,7 @@ module Ameba::AST::Util
end end
end end
# Returns true if node is a flow expression, false if not. # Returns `true` if node is a flow expression, `false` if not.
# Node represents a flow expression if it is full-filled by a flow command. # Node represents a flow expression if it is full-filled by a flow command.
# #
# For example, this node is a flow expression, because each branch contains # For example, this node is a flow expression, because each branch contains
@ -159,25 +159,25 @@ module Ameba::AST::Util
nodes.all? { |exp| flow_expression? exp, in_loop } nodes.all? { |exp| flow_expression? exp, in_loop }
end end
# Returns true if node represents `raise` method call. # Returns `true` if node represents `raise` method call.
def raise?(node) def raise?(node)
node.is_a?(Crystal::Call) && node.is_a?(Crystal::Call) &&
node.name == "raise" && node.args.size == 1 && node.obj.nil? node.name == "raise" && node.args.size == 1 && node.obj.nil?
end end
# Returns true if node represents `exit` method call. # Returns `true` if node represents `exit` method call.
def exit?(node) def exit?(node)
node.is_a?(Crystal::Call) && node.is_a?(Crystal::Call) &&
node.name == "exit" && node.args.size <= 1 && node.obj.nil? node.name == "exit" && node.args.size <= 1 && node.obj.nil?
end end
# Returns true if node represents `abort` method call. # Returns `true` if node represents `abort` method call.
def abort?(node) def abort?(node)
node.is_a?(Crystal::Call) && node.is_a?(Crystal::Call) &&
node.name == "abort" && node.args.size <= 2 && node.obj.nil? node.name == "abort" && node.args.size <= 2 && node.obj.nil?
end end
# Returns true if node represents a loop. # Returns `true` if node represents a loop.
def loop?(node) def loop?(node)
case node case node
when Crystal::While, Crystal::Until when Crystal::While, Crystal::Until