Module: RuboCop::Cop::IfNode
- Extended by:
- NodePattern::Macros
- Included in:
- Lint::ConditionPosition, Lint::ElseLayout, Lint::EndAlignment, Lint::RequireParentheses, Metrics::BlockNesting, Metrics::PerceivedComplexity, NegativeConditional, OnNormalIfUnless, StatementModifier, Style::ConditionalAssignment, Style::ElseAlignment, Style::GuardClause, Style::IdenticalConditionalBranches, Style::IfInsideElse, Style::IfUnlessModifier, Style::IndentationWidth, Style::MultilineIfThen, Style::MultilineTernaryOperator, Style::NestedModifier, Style::NestedTernaryOperator, Style::Next, Style::Not, Style::ParallelAssignment, Style::ParenthesesAroundCondition, Style::SpaceAfterColon, Style::SpaceAroundOperators, Style::TernaryParentheses
- Defined in:
- lib/rubocop/cop/mixin/if_node.rb
Overview
Common functionality for checking if nodes.
Instance Method Summary collapse
- #elsif?(node) ⇒ Boolean
- #if_else?(node) ⇒ Boolean
- #if_node_parts(node) ⇒ Object
- #modifier_if?(node) ⇒ Boolean
- #ternary?(node) ⇒ Boolean
Methods included from NodePattern::Macros
def_node_matcher, def_node_search, node_search, node_search_all, node_search_body, node_search_first
Instance Method Details
#elsif?(node) ⇒ Boolean
19 20 21 22 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 19 def elsif?(node) node.loc.respond_to?(:keyword) && node.loc.keyword && node.loc.keyword.is?('elsif') end |
#if_else?(node) ⇒ Boolean
24 25 26 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 24 def if_else?(node) node.loc.respond_to?(:else) && node.loc.else end |
#if_node_parts(node) ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 28 def if_node_parts(node) case node.loc.keyword.source when 'if', 'elsif' then condition, body, else_clause = *node when 'unless' then condition, else_clause, body = *node else condition, body = *node end [condition, body, else_clause] end |
#modifier_if?(node) ⇒ Boolean
14 15 16 17 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 14 def modifier_if?(node) node.loc.respond_to?(:keyword) && %w(if unless).include?(node.loc.keyword.source) && node.modifier_form? end |
#ternary?(node) ⇒ Boolean
10 11 12 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 10 def ternary?(node) node.loc.respond_to?(:question) end |