Sha256: aeab6ebb98ea47154dd7b82a28390715959c25e55ba9bfc2c2b98f6be88582a9

Contents?: true

Size: 629 Bytes

Versions: 2

Compression:

Stored size: 629 Bytes

Contents

module RuboCop
  module Cop
    module Ipepe
      class TernaryOperator < ::RuboCop::Cop::Base
        extend AutoCorrector

        MSG = "Use `if` instead of ternary operator.".freeze

        def on_if(node)
          return unless node.ternary?

          add_offense(node) do |corrector|
            corrector.replace(
              node,
              [
                "if #{node.condition.source}",
                node.if_branch.source,
                "else",
                node.else_branch.source,
                "end"
              ].join("\n")
            )
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-ipepe-0.2.5 lib/rubocop/cop/ipepe/ternary_operator.rb
rubocop-ipepe-0.2.0 lib/rubocop/cop/ipepe/ternary_operator.rb