Sha256: fffe1ff3390a7f3e78a7422104520d3be3e32abcdfdf631bb86cf5b6a0c4cb20

Contents?: true

Size: 713 Bytes

Versions: 7

Compression:

Stored size: 713 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, :expression)
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
rubocop-shakr-0.6.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-shakr-0.5.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.5.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-shakr-0.1.0 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.4.2 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.4.1 lib/rubocop/cop/github/rails_application_record.rb
rubocop-github-0.4.0 lib/rubocop/cop/github/rails_application_record.rb