Sha256: 66c563edc794816ff792c241591813953ddf4ec142cf0c88c88ffa2431586257

Contents?: true

Size: 526 Bytes

Versions: 4

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

4 entries across 4 versions & 1 rubygems

Version Path
rubocop-0.22.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.21.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.20.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.20.0 lib/rubocop/cop/style/multiline_ternary_operator.rb