Sha256: 1bc3dc8decf1e4c998d190309e94ed7d7cd0953315b1045f9b2296214e64b6f6

Contents?: true

Size: 652 Bytes

Versions: 20

Compression:

Stored size: 652 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for nested ternary op expressions.
      class NestedTernaryOperator < Cop
        MSG = 'Ternary operators must not be nested. Prefer `if`/`else` ' \
              'constructs instead.'

        def on_if(node)
          loc = node.loc

          # discard non-ternary ops
          return unless loc.respond_to?(:question)

          node.each_descendant(:if) do |nested_if_node|
            if nested_if_node.loc.respond_to?(:question)
              add_offense(nested_if_node, :expression)
            end
          end
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/nested_ternary_operator.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.35.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.35.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.34.2 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.34.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.34.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.33.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.32.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.32.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.31.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.30.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.30.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.29.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.29.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.28.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.27.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.27.0 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.26.1 lib/rubocop/cop/style/nested_ternary_operator.rb
rubocop-0.26.0 lib/rubocop/cop/style/nested_ternary_operator.rb