Sha256: 9af7dd183a8f4e1295e395095924abf8441043f7a032589e4facc1291ff7cfcb
Contents?: true
Size: 1.47 KB
Versions: 2
Compression:
Stored size: 1.47 KB
Contents
# encoding: utf-8 module Rubocop module Cop module Lint # This cop checks for uses of the deprecated class method usages. class DeprecatedClassMethods < Cop include AST::Sexp MSG = '%s is deprecated in favor of %s.' DEPRECATED_METHODS = [ [:File, :exists?, :exist?], [:Dir, :exists?, :exist?] ] def on_send(node) receiver, method_name, *_args = *node DEPRECATED_METHODS.each do |data| next unless receiver == class_node(data) next unless method_name == data[1] add_offense(node, :selector, MSG.format(deprecated_method(data), replacement_method(data))) end end def autocorrect(node) @corrections << lambda do |corrector| receiver, method_name, *_args = *node DEPRECATED_METHODS.each do |data| next unless receiver == class_node(data) next unless method_name == data[1] corrector.replace(node.loc.selector, data[2].to_s) end end end private def class_node(data) s(:const, nil, data[0]) end def deprecated_method(data) format('%s.%s', data[0], data[1]) end def replacement_method(data) format('%s.%s', data[0], data[2]) end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rubocop-0.19.1 | lib/rubocop/cop/lint/deprecated_class_methods.rb |
rubocop-0.19.0 | lib/rubocop/cop/lint/deprecated_class_methods.rb |