Module: RuboCop::Cop::IfNode
- Included in:
- Lint::EndAlignment, Lint::RequireParentheses, Metrics::BlockNesting, Metrics::PerceivedComplexity, OnNormalIfUnless, StatementModifier, Style::GuardClause, Style::IndentationWidth, Style::MultilineIfThen, Style::Next, Style::ParenthesesAroundCondition, Style::SpaceAfterColon
- 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
- #modifier_if?(node) ⇒ Boolean
- #ternary_op?(node) ⇒ Boolean
Instance Method Details
#elsif?(node) ⇒ Boolean
17 18 19 20 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 17 def elsif?(node) node.loc.respond_to?(:keyword) && node.loc.keyword && node.loc.keyword.is?('elsif') end |
#if_else?(node) ⇒ Boolean
22 23 24 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 22 def if_else?(node) node.loc.respond_to?(:else) && node.loc.else end |
#modifier_if?(node) ⇒ Boolean
7 8 9 10 11 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 7 def modifier_if?(node) node.loc.respond_to?(:keyword) && %w(if unless).include?(node.loc.keyword.source) && node.loc.respond_to?(:end) && node.loc.end.nil? end |
#ternary_op?(node) ⇒ Boolean
13 14 15 |
# File 'lib/rubocop/cop/mixin/if_node.rb', line 13 def ternary_op?(node) node.loc.respond_to?(:question) end |