Sha256: 37a93b71ad8337e71b1f7dd9a3058e653032657dd1efa90146d3c1bfa3aae413

Contents?: true

Size: 882 Bytes

Versions: 12

Compression:

Stored size: 882 Bytes

Contents

# frozen_string_literal: true

require_relative '../model_helpers'

module Gitlab
  module Styles
    module Rubocop
      module Cop
        # Cop that prevents the use of `dependent: ...` in ActiveRecord models.
        class ActiveRecordDependent < RuboCop::Cop::Cop
          include ModelHelpers

          MSG = 'Do not use `dependent: to remove associated data, ' \
            'use foreign keys with cascading deletes instead'

          METHOD_NAMES = [:has_many, :has_one, :belongs_to].freeze

          def on_send(node)
            return unless in_model?(node)
            return unless METHOD_NAMES.include?(node.children[1])

            node.children.last.each_node(:pair) do |pair|
              key_name = pair.children[0].children[0]

              add_offense(pair) if key_name == :dependent
            end
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
gitlab-styles-6.6.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-6.5.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-6.4.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-6.3.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-6.2.1 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-6.2.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-6.1.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-6.0.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-5.4.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-5.3.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-5.2.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb
gitlab-styles-5.1.0 lib/gitlab/styles/rubocop/cop/active_record_dependent.rb