Sha256: d7c00204edbce75ad3805bf3d4af053958a792ab9b0cfbe1f3d91b54896b79e2

Contents?: true

Size: 727 Bytes

Versions: 1

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

1 entries across 1 versions & 1 rubygems

Version Path
rubocop-standard-1.12.0 lib/rubocop/cop/standard/rails_application_record.rb