Sha256: 2c9bf158399521d5aa8464908ae3b52ed9f0d04f9a4d0e9c3d0a5b390fb1938b

Contents?: true

Size: 604 Bytes

Versions: 7

Compression:

Stored size: 604 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module RuboCop
  module Cop
    module Style
      # This cop checks for multi-line ternary op expressions.
      class MultilineTernaryOperator < Cop
        include IfNode

        MSG = 'Avoid multi-line ternary operators, ' \
              'use `if` or `unless` instead.'.freeze

        def on_if(node)
          _condition, _if_branch, else_branch = *node

          return unless ternary?(node)

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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
fluent-plugin-detect-memb-exceptions-0.0.2 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
fluent-plugin-detect-memb-exceptions-0.0.1 vendor/bundle/ruby/2.0.0/gems/rubocop-0.42.0/lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.42.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.41.2 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.41.1 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.41.0 lib/rubocop/cop/style/multiline_ternary_operator.rb
rubocop-0.40.0 lib/rubocop/cop/style/multiline_ternary_operator.rb