lib/rubocop/cop/style/class_methods.rb in rubocop-0.51.0 vs lib/rubocop/cop/style/class_methods.rb in rubocop-0.52.0

- old
+ new

@@ -8,22 +8,22 @@ # # @example # # bad # class SomeClass # def SomeClass.class_method - # ... + # # ... # end # end # # # good # class SomeClass # def self.class_method - # ... + # # ... # end # end class ClassMethods < Cop - MSG = 'Use `self.%s` instead of `%s.%s`.'.freeze + MSG = 'Use `self.%<method>s` instead of `%<class>s.%<method>s`.'.freeze def on_class(node) name, _superclass, body = *node check(name, body) end @@ -31,10 +31,14 @@ def on_module(node) name, body = *node check(name, body) end + def autocorrect(node) + ->(corrector) { corrector.replace(node.loc.name, 'self') } + end + private def check(name, node) return unless node @@ -54,14 +58,10 @@ add_offense(definee, location: :name, message: message(class_name, method_name)) end def message(class_name, method_name) - format(MSG, method_name, class_name, method_name) - end - - def autocorrect(node) - ->(corrector) { corrector.replace(node.loc.name, 'self') } + format(MSG, method: method_name, class: class_name) end end end end end