Sha256: a702f01685a35a13f0647813d2f8004a9dc59cac01d6c62d6cab5060fda18113

Contents?: true

Size: 685 Bytes

Versions: 1

Compression:

Stored size: 685 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    # 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

Version data entries

1 entries across 1 versions & 1 rubygems

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