Sha256: 34c55877fb7bf60319ff5ee0f3d6d3d5b3020244c2c13660037dc29e897d98c3

Contents?: true

Size: 749 Bytes

Versions: 3

Compression:

Stored size: 749 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)), s(:args, s(:arg, :_other))]

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-0.21.0 lib/rubocop/cop/style/op_method.rb
rubocop-0.20.1 lib/rubocop/cop/style/op_method.rb
rubocop-0.20.0 lib/rubocop/cop/style/op_method.rb