Sha256: 0f10580dc002cc72fe6879d88a38c43a1916dd2f9d506edbb4fa5d3de7985405

Contents?: true

Size: 526 Bytes

Versions: 15

Compression:

Stored size: 526 Bytes

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for multi-line ternary op expressions.
      class MultilineTernaryOperator < Cop
        MSG = 'Avoid multi-line ?: (the ternary operator);' \
              ' use `if`/`unless` instead.'

        def on_if(node)
          loc = node.loc

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

          add_offense(node, :expression) if loc.line != loc.colon.line
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.30.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.30.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.29.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.29.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.28.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.27.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.27.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.26.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.26.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.25.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.24.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.24.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.23.0 lib/rubocop/cop/style/multiline_ternary_operator.rb