module
Ameba::AST::Util
Overview
Utility module for Ameba's rules.
Extended Modules
Direct including types
- Ameba::AST::ElseIfAwareNodeVisitor
- Ameba::AST::FlowExpression
- Ameba::AST::FlowExpressionVisitor
- Ameba::AST::ReachingDefinitionAnalyzer
- Ameba::Reportable
- Ameba::Rule::Documentation::Admonition
- Ameba::Rule::Lint::AmbiguousAssignment
- Ameba::Rule::Lint::BadDirective
- Ameba::Rule::Lint::ComparisonToBoolean
- Ameba::Rule::Lint::DebuggerStatement
- Ameba::Rule::Lint::DeprecatedRule
- Ameba::Rule::Lint::DuplicateBranch
- Ameba::Rule::Lint::EmptyLoop
- Ameba::Rule::Lint::LiteralAssignmentsInExpressions
- Ameba::Rule::Lint::LiteralInCondition
- Ameba::Rule::Lint::LiteralInInterpolation
- Ameba::Rule::Lint::LiteralsComparison
- Ameba::Rule::Lint::NonExistentRule
- Ameba::Rule::Lint::NotNil
- Ameba::Rule::Lint::NotNilAfterNoBang
- Ameba::Rule::Lint::RedundantStringCoercion
- Ameba::Rule::Lint::RequireParentheses
- Ameba::Rule::Lint::SharedVarInFiber
- Ameba::Rule::Lint::SignalTrap
- Ameba::Rule::Lint::SpecEqWithBoolOrNilLiteral
- Ameba::Rule::Lint::SpecFocus
- Ameba::Rule::Lint::TopLevelOperatorDefinition
- Ameba::Rule::Lint::UnneededDisableDirective
- Ameba::Rule::Lint::UnusedBlockArgument
- Ameba::Rule::Lint::UnusedRescueVariable
- Ameba::Rule::Lint::VoidOutsideLib
- Ameba::Rule::Lint::WhitespaceAroundMacroExpression
- Ameba::Rule::Naming::AccessorMethodName
- Ameba::Rule::Naming::BinaryOperatorParameterName
- Ameba::Rule::Naming::QueryBoolMethods
- Ameba::Rule::Naming::RescuedExceptionsVariableName
- Ameba::Rule::Performance::AnyAfterFilter
- Ameba::Rule::Performance::AnyInsteadOfEmpty
- Ameba::Rule::Performance::AnyInsteadOfPresent
- 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::Performance::TimesMap
- Ameba::Rule::Style::CallParentheses
- Ameba::Rule::Style::GuardClause
- Ameba::Rule::Style::HeredocEscape
- Ameba::Rule::Style::HeredocIndent
- Ameba::Rule::Style::IsAFilter
- Ameba::Rule::Style::IsANil
- Ameba::Rule::Style::LargeNumbers
- Ameba::Rule::Style::MultilineCurlyBlock
- Ameba::Rule::Style::ParenthesesAroundCondition
- Ameba::Rule::Style::RedundantBegin
- Ameba::Rule::Style::RedundantNext
- Ameba::Rule::Style::RedundantNilInControlExpression
- Ameba::Rule::Style::RedundantReturn
- Ameba::Rule::Style::RedundantSelf
- Ameba::Rule::Style::VerboseBlock
- Ameba::Rule::Style::VerboseNilType
- Ameba::Rule::Typing::MethodParameterTypeRestriction
- Ameba::Rule::Typing::MethodReturnTypeRestriction
Defined in:
ameba/ast/util.crInstance Method Summary
-
#abort?(node)
Returns
trueif node representsabortmethod call. -
#control_exp_code(node : Crystal::ControlExpression, code_lines)
Returns the exp code of a control expression.
-
#dynamic_literal?(node) : Bool
Returns
trueif currentnodeis a dynamic literal,falseotherwise. -
#each_inline_directive(source, &block : Crystal::Token, String, Array(String) -> _)
Yields each inline directive found in the source.
-
#exit?(node)
Returns
trueif node representsexitmethod call. -
#flow_command?(node, in_loop)
Returns
trueif node is a flow command,falseotherwise. -
#flow_expression?(node, in_loop = false)
Returns
trueif node is a flow expression,falseif not. -
#has_arguments?(node) : Bool
Returns
trueif the node is aCrystal::Callwith eithernode.blockornode.block_argset,falseotherwise. -
#has_block?(node) : Bool
Returns
trueif the node is aCrystal::Callwith eithernode.blockornode.block_argset,falseotherwise. -
#has_short_block?(node, code_lines)
Returns
trueif node is a call with a short block version (&.foo?). -
#heredoc?(node : Crystal::ASTNode, source : Source)
Returns
trueif node is a heredoc,falseotherwise. -
#literal?(node) : Bool
Returns
trueif currentnodeis a literal,falseotherwise. -
#loop?(node)
Returns
trueif node represents a loop. -
#name_end_location(node)
Returns
nilif node does not contain a name. -
#name_location(node)
Returns
nilif node does not contain a name. - #name_location_or(token : Crystal::Token, name, *, adjust_location_column_number = nil)
- #name_location_or(node : Crystal::ASTNode, *, adjust_location_column_number = nil)
-
#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.
-
#nodoc?(node)
Returns
trueif node has a:nodoc:annotation as the first line. -
#operator_method?(node)
Returns
trueif node represents operator method. -
#operator_method_name?(name : String)
Returns
trueif name represents operator method. -
#path_name(node : Crystal::Path, *, include_global = true) : String
Returns the path name of the path.
-
#path_named?(node, *names : String) : Bool
Returns
trueif currentnodeis aCrystal::Pathmatching given name,falseotherwise. -
#raise?(node)
Returns
trueif node representsraisemethod call. -
#setter_method?(node)
Returns
trueif node represents setter method. -
#setter_method_name?(name : String)
Returns
trueif name represents setter method. -
#short_block?(node, code_lines)
Returns
trueif node represents a short block version (&.foo?). -
#source_between(loc, end_loc, code_lines) : String | Nil
Returns the source code from loc to end_loc (inclusive).
-
#static_literal?(node) : Bool
Returns
trueif currentnodeis a static literal,falseotherwise. -
#suffix?(node)
Returns
trueif node is a suffix node (if/unless/rescue/ensure). -
#takes_arguments?(node) : Bool
Returns
trueif the node is aCrystal::Defwith eitherargs,splat_index, ordouble_splatset,falseotherwise.
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.
Yields each inline directive found in the source.
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 true if the node is a Crystal::Call
with either node.block or node.block_arg set, false otherwise.
Returns true if the node is a Crystal::Call
with either node.block or node.block_arg set, false otherwise.
Returns true if node is a call with a short block version (&.foo?).
Returns true if node is a heredoc, false otherwise.
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 the path name of the path.
If include_global is true (default), the global prefix :: is included.
Returns true if current node is a Crystal::Path
matching given name, false otherwise.
Returns true if node represents a short block version (&.foo?).
Returns the source code from loc to end_loc (inclusive).
Returns true if current node is a static literal, false otherwise.
Returns true if the node is a Crystal::Def
with either args, splat_index, or double_splat set,
false otherwise.