Sha256: b62915290132020115a1bd84508a4e8836906b0ab50efec43f6be61c2e2c2680

Contents?: true

Size: 586 Bytes

Versions: 9

Compression:

Stored size: 586 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)
          _condition, _if_branch, else_branch = *node
          loc = node.loc

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rubocop-0.35.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.35.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.34.2 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.34.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.34.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.33.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.32.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.32.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.31.0 lib/rubocop/cop/style/multiline_ternary_operator.rb