module Ameba::AST::Util
Overview
Utility module for Ameba's rules.
Direct including types
- Ameba::AST::Branchable
- Ameba::AST::FlowExpression
- Ameba::AST::FlowExpressionVisitor
- Ameba::Reportable
- Ameba::Rule::Lint::AmbiguousAssignment
- Ameba::Rule::Lint::ComparisonToBoolean
- Ameba::Rule::Lint::EmptyLoop
- Ameba::Rule::Lint::LiteralAssignmentsInExpressions
- Ameba::Rule::Lint::LiteralInCondition
- Ameba::Rule::Lint::LiteralInInterpolation
- Ameba::Rule::Lint::LiteralsComparison
- Ameba::Rule::Lint::NotNilAfterNoBang
- Ameba::Rule::Lint::RedundantStringCoercion
- Ameba::Rule::Naming::QueryBoolMethods
- Ameba::Rule::Performance::AnyAfterFilter
- Ameba::Rule::Performance::ChainedCallWithNoBang
- Ameba::Rule::Performance::CompactAfterMap
- Ameba::Rule::Performance::ExcessiveAllocations
- Ameba::Rule::Performance::FirstLastAfterFilter
- Ameba::Rule::Performance::FlattenAfterMap
- Ameba::Rule::Performance::MapInsteadOfBlock
- Ameba::Rule::Performance::MinMaxAfterMap
- Ameba::Rule::Performance::SizeAfterFilter
- Ameba::Rule::Style::GuardClause
- Ameba::Rule::Style::IsAFilter
- Ameba::Rule::Style::IsANil
- Ameba::Rule::Style::RedundantBegin
- Ameba::Rule::Style::RedundantNext
- Ameba::Rule::Style::RedundantReturn
- Ameba::Rule::Style::VerboseBlock
Defined in:
ameba/ast/util.crInstance Method Summary
-
#abort?(node)
Returns
true
if node representsabort
method call. -
#control_exp_code(node : Crystal::ControlExpression, code_lines)
Returns the exp code of a control expression.
-
#dynamic_literal?(node) : Bool
Returns
true
if currentnode
is a dynamic literal,false
otherwise. -
#exit?(node)
Returns
true
if node representsexit
method call. -
#flow_command?(node, in_loop)
Returns
true
if node is a flow command,false
otherwise. -
#flow_expression?(node, in_loop = false)
Returns
true
if node is a flow expression,false
if not. -
#literal?(node) : Bool
Returns
true
if currentnode
is a literal,false
otherwise. -
#loop?(node)
Returns
true
if node represents a loop. -
#name_end_location(node)
Returns
nil
if node does not contain a name. -
#name_location(node)
Returns
nil
if node does not contain a name. -
#name_size(node)
Returns zero if node does not contain a name.
-
#node_source(node, code_lines)
Returns a source code for the current node.
-
#path_named?(node, name) : Bool
Returns
true
if currentnode
is aCrystal::Path
matching given name,false
otherwise. -
#raise?(node)
Returns
true
if node representsraise
method call. -
#source_between(loc, end_loc, code_lines) : String | Nil
Returns the source code from loc to end_loc (inclusive).
-
#static_literal?(node) : Bool
Returns
true
if currentnode
is a static literal,false
otherwise.
Instance Method Detail
Returns the exp code of a control expression. Wraps implicit tuple literal with curly brackets (e.g. multi-return).
Returns true
if current node
is a dynamic literal, false
otherwise.
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).
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).
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.
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.
Returns true
if current node
is a Crystal::Path
matching given name, false
otherwise.
Returns the source code from loc to end_loc (inclusive).
Returns true
if current node
is a static literal, false
otherwise.