summaryrefslogtreecommitdiff
path: root/rubocop/cop/gitlab/union.rb
blob: 09541d8af3bec4a8b14e61d5006b282fab3a1fc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true
require_relative '../../spec_helpers'

module RuboCop
  module Cop
    module Gitlab
      # Cop that disallows the use of `Gitlab::SQL::Union`, in favour of using
      # the `FromUnion` module.
      class Union < RuboCop::Cop::Cop
        include SpecHelpers

        MSG = 'Use the `FromUnion` concern, instead of using `Gitlab::SQL::Union` directly'

        def_node_matcher :raw_union?, <<~PATTERN
          (send (const (const (const nil? :Gitlab) :SQL) :Union) :new ...)
        PATTERN

        def on_send(node)
          return unless raw_union?(node)
          return if in_spec?(node)

          add_offense(node, location: :expression)
        end
      end
    end
  end
end