lib/rubocop/cop/style/class_methods.rb in rubocop-0.89.0 vs lib/rubocop/cop/style/class_methods.rb in rubocop-0.89.1
- old
+ new
@@ -18,11 +18,13 @@
# class SomeClass
# def self.class_method
# # ...
# end
# end
- class ClassMethods < Cop
+ class ClassMethods < Base
+ extend AutoCorrector
+
MSG = 'Use `self.%<method>s` instead of `%<class>s.%<method>s`.'
def on_class(node)
return unless node.body
@@ -34,26 +36,20 @@
end
end
end
alias on_module on_class
- def autocorrect(node)
- ->(corrector) { corrector.replace(node.loc.name, 'self') }
- end
-
private
def check_defs(name, node)
# check if the class/module name matches the definee for the defs node
return unless name == node.receiver
- add_offense(node.receiver, location: :name)
- end
+ message = format(MSG, method: node.method_name, class: name.source)
- def message(node)
- _, class_name = *node
-
- format(MSG, method: node.parent.method_name, class: class_name)
+ add_offense(node.receiver.loc.name, message: message) do |corrector|
+ corrector.replace(node.receiver, 'self')
+ end
end
end
end
end
end