Welcome to mirror list, hosted at ThFree Co, Russian Federation.

active_record_subtransactions.rb « performance « cop « rubocop - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a550b558e52a1cbb43b495d85fb860a5bc4a4ce5 (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
28
29
30
# frozen_string_literal: true

module RuboCop
  module Cop
    module Performance
      class ActiveRecordSubtransactions < RuboCop::Cop::Cop
        MSG = 'Subtransactions should not be used. ' \
          'For more information see: https://gitlab.com/gitlab-org/gitlab/-/issues/338346'

        def_node_matcher :match_transaction_with_options, <<~PATTERN
          (send _ :transaction (hash $...))
        PATTERN

        def_node_matcher :subtransaction_option?, <<~PATTERN
          (pair (:sym :requires_new) (true))
        PATTERN

        def on_send(node)
          match_transaction_with_options(node) do |option_nodes|
            option_nodes.each do |option_node|
              next unless subtransaction_option?(option_node)

              add_offense(option_node)
            end
          end
        end
      end
    end
  end
end