Sha256: 0066bd73962d0b86d8a6993f7dfc1d8f27172d31ef0598acb1613ee1a1939509

Contents?: true

Size: 577 Bytes

Versions: 11

Compression:

Stored size: 577 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for nested ternary op expressions.
      class NestedTernaryOperator < Cop
        include IfNode

        MSG = 'Ternary operators must not be nested. Prefer `if` or `else` ' \
              'constructs instead.'.freeze

        def on_if(node)
          return unless ternary?(node)

          node.each_descendant(:if) do |nested_if_node|
            add_offense(nested_if_node, :expression) if ternary?(nested_if_node)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
dirwatch-0.0.9 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/nested_ternary_operator.rb
dirwatch-0.0.8 vendor/bundle/ruby/2.5.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/nested_ternary_operator.rb
dirwatch-0.0.6 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/nested_ternary_operator.rb
dirwatch-0.0.5 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/nested_ternary_operator.rb
dirwatch-0.0.4 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/nested_ternary_operator.rb
dirwatch-0.0.3 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/nested_ternary_operator.rb
dirwatch-0.0.2 vendor/bundle/ruby/2.3.0/gems/rubocop-0.46.0/lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.46.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.45.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.44.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.44.0 lib/rubocop/cop/style/nested_ternary_operator.rb