diff options
Diffstat (limited to 'rubocop/cop/gitlab/intersect.rb')
-rw-r--r-- | rubocop/cop/gitlab/intersect.rb | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/rubocop/cop/gitlab/intersect.rb b/rubocop/cop/gitlab/intersect.rb new file mode 100644 index 00000000000..4b61073b804 --- /dev/null +++ b/rubocop/cop/gitlab/intersect.rb @@ -0,0 +1,23 @@ +# 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. + class Intersect < RuboCop::Cop::Cop + 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) + + add_offense(node, location: :expression) + end + end + end + end +end |