Sha256: 1acd6ed5bfcab155163b357d14ff13879597872e43da81787db6597b1a463179

Contents?: true

Size: 1.41 KB

Versions: 7048

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

module RuboCop
  module AST
    # Common functionality for nodes that have conditions:
    # `if`, `while`, `until`, `case`.
    # This currently doesn't include `when` nodes, because they have multiple
    # conditions, and need to be checked for that.
    module ConditionalNode
      # Checks whether the condition of the node is written on a single line.
      #
      # @return [Boolean] whether the condition is on a single line
      def single_line_condition?
        loc.keyword.line == condition.source_range.line
      end

      # Checks whether the condition of the node is written on more than
      # one line.
      #
      # @return [Boolean] whether the condition is on more than one line
      def multiline_condition?
        !single_line_condition?
      end

      # Returns the condition of the node. This works together with each node's
      # custom destructuring method to select the correct part of the node.
      #
      # @return [Node, nil] the condition of the node
      def condition
        node_parts[0]
      end

      # Returns the body associated with the condition. This works together with
      # each node's custom destructuring method to select the correct part of
      # the node.
      #
      # @note For `if` nodes, this is the truthy branch.
      #
      # @return [Node, nil] the body of the node
      def body
        node_parts[1]
      end
    end
  end
end

Version data entries

7,048 entries across 7,012 versions & 50 rubygems

Version Path
cybrid_api_bank_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_id_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_organization_ruby-0.123.132 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_bank_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_id_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_organization_ruby-0.123.131 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_bank_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_id_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_organization_ruby-0.123.129 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_bank_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_id_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_organization_ruby-0.123.127 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_bank_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_id_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_organization_ruby-0.123.126 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_bank_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_organization_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_id_ruby-0.123.125 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb
cybrid_api_bank_ruby-0.123.124 vendor/bundle/ruby/3.3.0/gems/rubocop-0.66.0/lib/rubocop/ast/node/mixin/conditional_node.rb