Sha256: 02778045d2e2c4d5531bcdb12c4953c779d491b5227e03e0351a45ce42e864b5

Contents?: true

Size: 718 Bytes

Versions: 7

Compression:

Stored size: 718 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
          return unless 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

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubyjobbuilderdsl-0.0.2 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/op_method.rb
rubyjobbuilderdsl-0.0.1 vendor/bundle/ruby/2.1.0/gems/rubocop-0.26.0/lib/rubocop/cop/style/op_method.rb
rubocop-0.26.0 lib/rubocop/cop/style/op_method.rb
rubocop-0.25.0 lib/rubocop/cop/style/op_method.rb
rubocop-0.24.1 lib/rubocop/cop/style/op_method.rb
rubocop-0.24.0 lib/rubocop/cop/style/op_method.rb
rubocop-0.23.0 lib/rubocop/cop/style/op_method.rb