Sha256: aac73045fe314da81a9a9232b5d7f5a6c2b68647c4a0dd3ba90bb714646f6a36

Contents?: true

Size: 742 Bytes

Versions: 2

Compression:

Stored size: 742 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    module Style
      # This cop makes sure that certain operator methods have their sole
      # parameter named *other*.
      class OpMethod < Cop
        MSG = 'When defining the %s operator, name its argument *other*.'

        BLACKLISTED = [:+@, :-@, :[], :[]=, :<<]

        TARGET_ARGS = s(:args, s(:arg, :other))

        def on_def(node)
          name, args, _body = *node

          if name !~ /\A\w/ && !BLACKLISTED.include?(name) &&
              args.children.size == 1 && args != TARGET_ARGS
            add_offence(:convention, args.children[0].loc.expression,
                        sprintf(MSG, name))
          end

          super
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
rubocop-0.9.1 lib/rubocop/cop/style/op_method.rb
sabat-rubocop-0.9.0 lib/rubocop/cop/style/op_method.rb