Sha256: 6db7098bef84a72e60f2d84a1d75abf7d55b0caa47c35e58075153b2411a9bc4

Contents?: true

Size: 1.03 KB

Versions: 8

Compression:

Stored size: 1.03 KB

Contents

# encoding: utf-8

module RuboCop
  module Cop
    module Style
      # This cop checks for uses of the deprecated methods Hash#has_key?
      # and Hash#has_value?
      class DeprecatedHashMethods < Cop
        MSG = '`Hash#%s` is deprecated in favor of `Hash#%s`.'

        DEPRECATED_METHODS = [:has_key?, :has_value?]

        def on_send(node)
          _receiver, method_name, *args = *node
          return unless args.size == 1 &&
            DEPRECATED_METHODS.include?(method_name)

          add_offense(node, :selector,
                      format(MSG,
                             method_name,
                             proper_method_name(method_name)))
        end

        def autocorrect(node)
          @corrections << lambda do |corrector|
            corrector.replace(node.loc.selector,
                              proper_method_name(node.loc.selector.source))
          end
        end

        private

        def proper_method_name(method_name)
          method_name.to_s.sub(/has_/, '')
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

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