Sha256: 6c711f9b87a434bd731970a932cb4981ca013fbe93dd4cadb9aa5aef9b9f9f5b

Contents?: true

Size: 717 Bytes

Versions: 6832

Compression:

Stored size: 717 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for nested ternary op expressions.
      #
      # @example
      #   # bad
      #   a ? (b ? b1 : b2) : a2
      #
      #   # good
      #   if a
      #     b ? b1 : b2
      #   else
      #     a2
      #   end
      class NestedTernaryOperator < Cop
        MSG = 'Ternary operators must not be nested. Prefer `if` or `else` ' \
              'constructs instead.'.freeze

        def on_if(node)
          return unless node.ternary?

          node.each_descendant(:if).select(&:ternary?).each do |nested_ternary|
            add_offense(nested_ternary)
          end
        end
      end
    end
  end
end

Version data entries

6,832 entries across 6,826 versions & 26 rubygems

Version Path
talon_one-2.0.0 vendor/bundle/ruby/2.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/nested_ternary_operator.rb
dadapush_client-1.0.1 vendor/bundle/ruby/2.3.0/gems/rubocop-0.66.0/lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.68.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.68.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.67.2 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.67.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.67.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.66.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.65.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.64.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.63.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.63.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.62.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.61.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.61.0 lib/rubocop/cop/style/nested_ternary_operator.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/nested_ternary_operator.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/nested_ternary_operator.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/nested_ternary_operator.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/rubocop-0.60.0/lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.60.0 lib/rubocop/cop/style/nested_ternary_operator.rb