Sha256: 1fefb9735e0b51938758123f0bc8966d60ded2a5e5d48c33ca7f1bab4bc57002

Contents?: true

Size: 725 Bytes

Versions: 32

Compression:

Stored size: 725 Bytes

Contents

# frozen_string_literal: true

require "rubocop"

module RuboCop
  module Cop
    module GitHub
      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

32 entries across 32 versions & 2 rubygems

Version Path
rubocop-springest-0.7.5 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.17.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.7.4 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.7.3 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.16.2 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.16.1 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.7.2 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.16.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.15.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.7.1 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.14.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.7.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.6.9 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.6.8 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.13.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.6.7 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.6.6 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.6.5 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.6.4 lib/rubocop/cop/github/rails_application_record.rb
rubocop-springest-0.6.3 lib/rubocop/cop/github/rails_application_record.rb