You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# frozen_string_literal: true
module CustomCops
# @example
#
# # good
# class Rails5Model < ApplicationRecord
# # ...
# end
#
# # bad
# class Rails4Model < ActiveRecord::Base
# # ...
# end
class MustApplicationRecord < RuboCop::Cop::Cop
MSG = 'Models should subclass `ApplicationRecord`.'
SUPERCLASS = 'ApplicationRecord'
BASE_PATTERN = '(const (const nil? :ActiveRecord) :Base)'
include RuboCop::Cop::EnforceSuperclass
def autocorrect(node)
lambda do |corrector|
corrector.replace(node.source_range, self.class::SUPERCLASS)
end
end
end
end
But I got an error running rspec, like this.
Failure/Error:
class MustApplicationRecord < RuboCop::Cop::Cop
MSG = 'Models should subclass `ApplicationRecord`.'
SUPERCLASS = 'ApplicationRecord'
BASE_PATTERN = '(const (const nil? :ActiveRecord) :Base)'
include RuboCop::Cop::EnforceSuperclass
def autocorrect(node)
lambda do |corrector|
corrector.replace(node.source_range, self.class::SUPERCLASS)
NameError:
uninitialized constant CustomCops::RuboCop
Do you know how to solve this error, or other method( like override 'minimum_target_rails_version 5.0' to 'minimum_target_rails_version 4.0' ) ?
versions
Rails 4.2.8
ruby 2.6.6
rubocop 0.80.1
RSpec 3.9
The text was updated successfully, but these errors were encountered:
I'm sorry about I will close this issue because RuboCop Rails is currently negative support for Rails 4 series. #236
I think it works by reusing Rails/ApplicationRecord cop's implementation with your custom cop and removing minimum_target_rails_version 5.0 from the reused implementation.
Hi there.
I want to use ApplicationRecord Cop on Rails 4.
I already added 'self.abstract_class = true' .
And this file is written 'minimum_target_rails_version 5.0'.
https://github.com/rubocop-hq/rubocop-rails/blob/master/lib/rubocop/cop/rails/application_record.rb
So I created custom_cop like this.
But I got an error running rspec, like this.
Do you know how to solve this error, or other method( like override 'minimum_target_rails_version 5.0' to 'minimum_target_rails_version 4.0' ) ?
versions
The text was updated successfully, but these errors were encountered: