Skip to content

Commit

Permalink
Make custom cop inherit RuboCop::Cop::Base
Browse files Browse the repository at this point in the history
Follow rubocop/rubocop#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
```
  • Loading branch information
koic committed Feb 10, 2023
1 parent a246c5e commit a7e4119
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions util/cops/deprecations.rb
Expand Up @@ -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 `%<method_name>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
Expand Down

0 comments on commit a7e4119

Please sign in to comment.