Sha256: 90759ac3990210cc80af6bfcc4b3587ad6f5fd142ef291ffc38c5426d2b621ad

Contents?: true

Size: 631 Bytes

Versions: 3

Compression:

Stored size: 631 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class AndOr < Cop
      MSG = 'Use %s instead of %s.'

      OPS = { 'and' => '&&', 'or' => '||' }

      def on_and(node)
        process_logical_op(node)

        super
      end

      def on_or(node)
        process_logical_op(node)

        super
      end

      private

      def process_logical_op(node)
        op = node.loc.operator.source
        op_type = node.type.to_s

        if op == op_type
          add_offence(:convention,
                      node.loc.operator.line,
                      sprintf(MSG, OPS[op], op))
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.8.3 lib/rubocop/cop/and_or.rb
rubocop-0.8.2 lib/rubocop/cop/and_or.rb
rubocop-0.8.1 lib/rubocop/cop/and_or.rb