2020-09-02 08:10:35 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module RuboCop
|
|
|
|
module Cop
|
|
|
|
module Gitlab
|
|
|
|
# Cop that disallows the use of `Gitlab::SQL::Intersect`, in favour of using
|
|
|
|
# the `FromIntersect` module.
|
2022-09-14 11:12:56 -04:00
|
|
|
class Intersect < RuboCop::Cop::Base
|
2020-09-02 08:10:35 -04:00
|
|
|
MSG = 'Use the `FromIntersect` concern, instead of using `Gitlab::SQL::Intersect` directly'
|
|
|
|
|
|
|
|
def_node_matcher :raw_intersect?, <<~PATTERN
|
|
|
|
(send (const (const (const nil? :Gitlab) :SQL) :Intersect) :new ...)
|
|
|
|
PATTERN
|
|
|
|
|
|
|
|
def on_send(node)
|
|
|
|
return unless raw_intersect?(node)
|
|
|
|
|
2022-09-14 11:12:56 -04:00
|
|
|
add_offense(node)
|
2020-09-02 08:10:35 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|