Sha256: 10229550f77181b24e28bdffe695df5a65a39d2ac12d12aeda043eca80230dc9

Contents?: true

Size: 581 Bytes

Versions: 1

Compression:

Stored size: 581 Bytes

Contents

# encoding: utf-8

module Rubocop
  module Cop
    class OpMethod < Cop
      ERROR_MESSAGE = 'When defining the %s operator, name its argument other.'

      def inspect(file, source, tokens, sexp)
        each(:def, sexp) do |s|
          if s[1][0] == :@op && !%w([] []= <<).include?(s[1][1])
            param = s[2][1][1][0]

            unless param[1] == 'other'
              add_offence(:convention,
                          param[2].lineno,
                          sprintf(ERROR_MESSAGE, s[1][1]))
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-0.6.0 lib/rubocop/cop/op_method.rb