Sha256: fbde9935867b9fd129c7b458d64203348efd699a59b72ff400d75ed7fd590110
Contents?: true
Size: 1.56 KB
Versions: 15
Compression:
Stored size: 1.56 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 class_nodes(data).include?(receiver) next unless method_name == data[1] add_offense(node, :selector, format(MSG, 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 class_nodes(data).include?(receiver) next unless method_name == data[1] corrector.replace(node.loc.selector, data[2].to_s) end end end private def class_nodes(data) [s(:const, nil, data[0]), s(:const, s(:cbase), 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
15 entries across 15 versions & 2 rubygems