Sha256: 3752798476cc01ad7db78902e7f6d7470c148dabb6ffc145e1b546038d2a12f1

Contents?: true

Size: 595 Bytes

Versions: 8

Compression:

Stored size: 595 Bytes

Contents

# encoding: utf-8
# 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

8 entries across 8 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/nested_ternary_operator.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.43.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.42.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.41.2 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.41.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.41.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.40.0 lib/rubocop/cop/style/nested_ternary_operator.rb