I'm using gem 'rubocop', '~> 0.81.0'
, when I try to create a custom rubocop file like below:
return unless defined?(::RuboCop)
module CustomCops
class NoTimecop < ::RuboCop::Cop::Base
MSG = "`Timecop` の代わりにRails標準の `ActiveSupport::Testing::TimeHelpers` が使えませんか?".freeze
def on_send(node)
if node.source.include?("Timecop") && node.receiver.const_name == "Timecop"
add_offense(node)
end
end
end
end
I face with an error uninitialized constant RuboCop::Cop::Base
How can I fix this error?
I am not sure what I might be missing here, I'd appreciate some helpful feedback. Thank you!
You are using an old version of Rubocop, 0.81.0
was released more than three years ago and that version had indeed no Rubocop::Cop::Base
class. Instead custom cop had to inherit from another class named Rubocop::Cop::Cop
.
That means, you have three options:
Rubocop::Cop::Cop
.0.87.0
, the version which introduced a Rubocop::Cop::Base
class, but is still three years old.gem 'rubocop', '~> 1.54', '>= 1.54.2'
.I would, of course, recommend using the latest version, but it might require some effort, because some cops changed, new were added, and you will need to update your code to fix all newly found offenses.