Sha256: dfed9446b0c7c5c0ff9d6361f12382d10afb2c56d04d18d2ae2fd79344ec4f10

Contents?: true

Size: 703 Bytes

Versions: 2

Compression:

Stored size: 703 Bytes

Contents

# frozen_string_literal: true

require "rubocop"

module RuboCop
  module Cop
    module GitHub
      class RailsApplicationRecord < Base
        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)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubocop-github-0.19.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.18.0 lib/rubocop/cop/github/rails_application_record.rb