Skip to content

Commit

Permalink
Merge pull request rubocop#13253 from Earlopain/cop-cop-deprecation-w…
Browse files Browse the repository at this point in the history
…arning

Emit a deprecation when custom cops inherit from `RuboCop::Cop::Cop`
  • Loading branch information
koic committed Sep 21, 2024
2 parents c51b398 + 021b236 commit cabd576
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/change_deprecation_for_cop_cop_cops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [#13253](https://github.com/rubocop/rubocop/pull/13253): Emit a deprecation when custom cops inherit from `RuboCop::Cop::Cop`. ([@earlopain][])
8 changes: 8 additions & 0 deletions lib/rubocop/cop/cop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ def call(corrector)
end
end

def self.inherited(_subclass)
super
warn Rainbow(<<~WARNING).yellow, uplevel: 1
Inheriting from `RuboCop::Cop::Cop` is deprecated. Use `RuboCop::Cop::Base` instead.
For more information, see https://docs.rubocop.org/rubocop/v1_upgrade_notes.html.
WARNING
end

def self.support_autocorrect?
method_defined?(:autocorrect)
end
Expand Down
10 changes: 7 additions & 3 deletions spec/rubocop/cop/cop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@

context 'when cop supports autocorrection', :restore_registry do
let(:cop_class) do
stub_cop_class('RuboCop::Cop::Test::StubCop', inherit: described_class) do
def autocorrect(node); end
end
cop_class = nil
expect do # rubocop:disable RSpec/ExpectInLet
cop_class = stub_cop_class('RuboCop::Cop::Test::StubCop', inherit: described_class) do
def autocorrect(node); end
end
end.to output(/Inheriting from `RuboCop::Cop::Cop` is deprecated/).to_stderr
cop_class
end

context 'when offense was corrected' do
Expand Down

0 comments on commit cabd576

Please sign in to comment.