module Ameba::AST::Util

Overview

Utility module for Ameba's rules.

Direct including types

Defined in:

ameba/ast/util.cr

Instance Method Summary

Instance Method Detail

def abort?(node) #

Returns true if node represents abort method call.


[View source]
def 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).


[View source]
def dynamic_literal?(node) : Bool #

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


[View source]
def exit?(node) #

Returns true if node represents exit method call.


[View source]
def 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).


[View source]
def 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).


[View source]
def literal?(node) : Bool #

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


[View source]
def loop?(node) #

Returns true if node represents a loop.


[View source]
def 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.


[View source]
def name_location(node) #

Returns nil if node does not contain a name.


[View source]
def name_size(node) #

Returns zero if node does not contain a name.


[View source]
def 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.


[View source]
def path_named?(node, name) : Bool #

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


[View source]
def raise?(node) #

Returns true if node represents raise method call.


[View source]
def source_between(loc, end_loc, code_lines) : String | Nil #

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


[View source]
def static_literal?(node) : Bool #

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


[View source]