5819ca1a24
One should really use a separate table instead of using polymorphic associations. See https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/11168 for more information.
23 lines
625 B
Ruby
23 lines
625 B
Ruby
require_relative '../model_helpers'
|
|
|
|
module RuboCop
|
|
module Cop
|
|
# Cop that prevents the use of polymorphic associations
|
|
class PolymorphicAssociations < RuboCop::Cop::Cop
|
|
include ModelHelpers
|
|
|
|
MSG = 'Do not use polymorphic associations, use separate tables instead'.freeze
|
|
|
|
def on_send(node)
|
|
return unless in_model?(node)
|
|
return unless node.children[1] == :belongs_to
|
|
|
|
node.children.last.each_node(:pair) do |pair|
|
|
key_name = pair.children[0].children[0]
|
|
|
|
add_offense(pair, :expression) if key_name == :polymorphic
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|