Sha256: 699b0ff4d5fe5e7900dc1a89efb0b88dabcf16915e62d98726085e3880ea123f

Contents?: true

Size: 761 Bytes

Versions: 54

Compression:

Stored size: 761 Bytes

Contents

# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for multi-line ternary op expressions.
      #
      # @example
      #   # bad
      #   a = cond ?
      #     b : c
      #   a = cond ? b :
      #       c
      #   a = cond ?
      #       b :
      #       c
      #
      #   # good
      #   a = cond ? b : c
      #   a =
      #     if cond
      #       b
      #     else
      #       c
      #     end
      class MultilineTernaryOperator < Cop
        MSG = 'Avoid multi-line ternary operators, ' \
              'use `if` or `unless` instead.'

        def on_if(node)
          return unless node.ternary? && node.multiline?

          add_offense(node)
        end
      end
    end
  end
end

Version data entries

54 entries across 35 versions & 5 rubygems

Version Path
grape-extra_validators-2.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
files.com-1.0.1 vendor/bundle/ruby/2.5.0/gems/rubocop-0.85.1/lib/rubocop/cop/style/multiline_ternary_operator.rb
rbhint-0.85.1.rc1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.85.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rbhint-0.8.5.rc1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.85.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.84.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.83.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.82.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.81.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.80.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.80.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.4.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
grape-extra_validators-1.0.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.79.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.79.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.78.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.76.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.74.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.77.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
zuora_connect_ui-0.10.0 vendor/ruby/2.6.0/gems/rubocop-0.75.0/lib/rubocop/cop/style/multiline_ternary_operator.rb