diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-24 18:10:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-24 18:10:36 +0300 |
commit | 234dc40a12a1cdaef0cdb825ca4acc3f271c6394 (patch) | |
tree | fb9875dca8b558acafa54c36a591b4d2ed10fc49 /rubocop | |
parent | c7864d3d50b4002c621c7cba2e1ebfb5d23ac7ed (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'rubocop')
-rw-r--r-- | rubocop/cop/performance/active_record_subtransaction_methods.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/rubocop/cop/performance/active_record_subtransaction_methods.rb b/rubocop/cop/performance/active_record_subtransaction_methods.rb new file mode 100644 index 00000000000..2769f8cab42 --- /dev/null +++ b/rubocop/cop/performance/active_record_subtransaction_methods.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +module RuboCop + module Cop + module Performance + # Cop that disallows certain methods that rely on subtransactions in their implementation. + # Companion to Performance/ActiveRecordSubtransactions, which bans direct usage of subtransactions. + class ActiveRecordSubtransactionMethods < RuboCop::Cop::Cop + MSG = 'Methods that rely on subtransactions should not be used. ' \ + 'For more information see: https://gitlab.com/gitlab-org/gitlab/-/issues/338346' + + DISALLOWED_METHODS = %i[ + safe_ensure_unique + create_or_find_by + create_or_find_by! + ].freeze + + def on_send(node) + return unless DISALLOWED_METHODS.include?(node.method_name) + + add_offense(node, location: :selector) + end + end + end + end +end |