module

Ameba::AST::Util

Utility module for Ameba's rules.

Instance methods

abort?(node)

Returns true if node represents abort method call.

Source
control_exp_code(node : Crystal::ControlExpression, code_lines)

Returns the exp code of a control expression. Wraps implicit tuple literal with curly brackets (e.g. multi-return).

Source
dynamic_literal?(node) : Bool

Returns true if current node is a dynamic literal, false otherwise.

Source
each_inline_directive(source, &block : Crystal::Token, String, Array(String) -> _)

Yields each inline directive found in the source.

Source
exit?(node)

Returns true if node represents exit method call.

Source
flow_command?(node, in_loop)

Returns true if node is a flow command, false otherwise. Node represents a flow command if it is a control expression, or special call node that interrupts execution (i.e. raise, exit, abort).

Source
flow_expression?(node, in_loop = false)

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.

For example, this node is a flow expression, because each branch contains a flow command return:

if a > 0
  return :positive
elsif a < 0
  return :negative
else
  return :zero
end

This node is a not a flow expression:

if a > 0
  return :positive
end

That's because not all branches return(i.e. else is missing).

Source
has_arguments?(node) : Bool

Returns true if the node is a Crystal::Call with either node.block or node.block_arg set, false otherwise.

Source
has_block?(node) : Bool

Returns true if the node is a Crystal::Call with either node.block or node.block_arg set, false otherwise.

Source
has_short_block?(node, code_lines)

Returns true if node is a call with a short block version (&.foo?).

Source
heredoc?(node : Crystal::ASTNode, source : Source)

Returns true if node is a heredoc, false otherwise.

Source
literal?(node) : Bool

Returns true if current node is a literal, false otherwise.

Source
loop?(node)

Returns true if node represents a loop.

Source
name_end_location(node)

Returns nil if node does not contain a name.

NOTE: Use this instead of Crystal::Call#name_end_location to avoid an off-by-one error.

Source
name_location(node)

Returns nil if node does not contain a name.

Source
name_location_or(token : Crystal::Token, name, *, adjust_location_column_number = nil)
Source
name_location_or(node : Crystal::ASTNode, *, adjust_location_column_number = nil)
Source
name_size(node)

Returns zero if node does not contain a name.

Source
node_source(node, code_lines)

Returns a source code for the current node. This method uses node.location and node.end_location to determine and cut a piece of source of the node.

Source
nodoc?(node)

Returns true if node has a :nodoc: annotation as the first line.

Source
operator_method?(node)

Returns true if node represents operator method.

Source
operator_method_name?(name : String)

Returns true if name represents operator method.

Source
path_name(node : Crystal::Path, *, include_global = true) : String

Returns the path name of the path.

If include_global is true (default), the global prefix :: is included.

Source
path_named?(node, *names : String) : Bool

Returns true if current node is a Crystal::Path matching given name, false otherwise.

Source
raise?(node)

Returns true if node represents raise method call.

Source
setter_method?(node)

Returns true if node represents setter method.

Source
setter_method_name?(name : String)

Returns true if name represents setter method.

Source
short_block?(node, code_lines)

Returns true if node represents a short block version (&.foo?).

Source
source_between(loc, end_loc, code_lines) : String | Nil

Returns the source code from loc to end_loc (inclusive).

Source
static_literal?(node) : Bool

Returns true if current node is a static literal, false otherwise.

Source
suffix?(node)

Returns true if node is a suffix node (if / unless / rescue / ensure).

Source
takes_arguments?(node) : Bool

Returns true if the node is a Crystal::Def with either args, splat_index, or double_splat set, false otherwise.

Source