Sha256: 4f2ac64bc5c5709e87b3d57691c4c5ccefd8bcbdd3d2eeb3982c774a7cd10d0c

Contents?: true

Size: 727 Bytes

Versions: 3

Compression:

Stored size: 727 Bytes

Contents

# frozen_string_literal: true

require 'rubocop'

module RuboCop
  module Cop
    module Standard
      class RailsApplicationRecord < Cop
        MSG = 'Models should subclass from ApplicationRecord'

        def_node_matcher :active_record_base_const?, <<-PATTERN
          (const (const nil? :ActiveRecord) :Base)
        PATTERN

        def_node_matcher :application_record_const?, <<-PATTERN
          (const nil? :ApplicationRecord)
        PATTERN

        def on_class(node)
          klass, superclass, _ = *node

          if active_record_base_const?(superclass) && !(application_record_const?(klass))
            add_offense(superclass, location: :expression)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rubocop-standard-1.15.1 lib/rubocop/cop/standard/rails_application_record.rb
rubocop-standard-1.15.0 lib/rubocop/cop/standard/rails_application_record.rb
rubocop-standard-1.14.0 lib/rubocop/cop/standard/rails_application_record.rb