Sha256: 461d55f2b78e5ca8cb6caec70ca959dbbbd82312d1da8034a7b1dd26fdc1d1af

Contents?: true

Size: 639 Bytes

Versions: 2

Compression:

Stored size: 639 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Lint
      # This cop checks for comparison of something with itself.
      #
      # @example
      #
      #  x.top >= x.top
      class UselessComparison < Cop
        MSG = 'Comparison of something with itself detected.'

        OPS = %w(== === != < > <= >= <=>)

        def on_send(node)
          op = node.loc.selector.source

          if OPS.include?(op)
            receiver, _method, selector = *node

            if receiver == selector
              add_offence(:warning, node.loc.selector, MSG)
            end
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-0.11.1 lib/rubocop/cop/lint/useless_comparison.rb
rubocop-0.11.0 lib/rubocop/cop/lint/useless_comparison.rb