From a7e4119cbc5fd1a5feeae613110e501fccab2f37 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 11 Feb 2023 02:03:55 +0900 Subject: [PATCH] Make custom cop inherit `RuboCop::Cop::Base` Follow https://github.com/rubocop/rubocop/pull/7868. The legacy `RuboCop::Cop::Cop` API is soft deprecated and this PR makes custom cop inherit `RuboCop::Cop::Base` API instead. > maintain any RuboCop extensions, as the legacy API > will be removed in RuboCop 2.0. https://metaredux.com/posts/2020/10/21/rubocop-1-0.html I've confirmed that the following behavior is compatible: ```console $ bundle exec util/rubocop -r ./util/cops/deprecations --only Rubygems/Deprecations ``` --- util/cops/deprecations.rb | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/util/cops/deprecations.rb b/util/cops/deprecations.rb index 7f6cd8af68ca..5d2787505404 100644 --- a/util/cops/deprecations.rb +++ b/util/cops/deprecations.rb @@ -14,19 +14,12 @@ module Rubygems # # good # # the `deprecate` call is fully removed # - class Deprecations < Cop - def on_send(node) - _receiver, method_name, *args = *node - return unless method_name == :rubygems_deprecate || method_name == :rubygems_deprecate_command - - add_offense(node) - end + class Deprecations < Base + MSG = "Remove `%s` calls for the next major release." + RESTRICT_ON_SEND = %i[rubygems_deprecate rubygems_deprecate_command].freeze - private - - def message(node) - msg = "Remove `#{node.method_name}` calls for the next major release " - format(msg, method: node.method_name) + def on_send(node) + add_offense(node, message: format(MSG, method_name: node.method_name)) end end end