rubocop-vendor 0.12.2 → 0.13.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0f75f2d9359b745fe58cb30a7314ac94d01f6603efd77cfcd8fd653aeea1b115
4
- data.tar.gz: 6207bdf6793f485c5ecb6b7a11d26d10d9344d5130d6449736525009a742c559
3
+ metadata.gz: 8201ad6615a9f1238fb755baa9b6272ce8f356a535f847666dac954926c94426
4
+ data.tar.gz: 56b0dc0aea976dd7f336126d14454484500bc8602acb2a93cc756306a063104c
5
5
  SHA512:
6
- metadata.gz: 690945dcd9783af17dfec0e4b326ed8ca46612bb45c6a98a5b3aa7b67f8fe9f983c1cd2495e9491e8d3d9294c1eb37bf46cba0d6e2f8752dcd1e5d4be58a8833
7
- data.tar.gz: bd5e907e32893aae0389412ff196eed02a58af2c63c0c30694155ef954ace00ed6cb6781a327af92c51fb725c09023ad39c3639894e868f39641a0d884900f75
6
+ metadata.gz: a3a82052ce85f8cc48238c63e0de5210b6adb09eadd93a65cd8c53280914e809d91188cbd60f1e22e6cc8390010fcb518608c1cdfa8bede285b18e85e84611c5
7
+ data.tar.gz: 49b3e55679ebfd6d76f8783305995b72d291ebdd6675de5b67944558f8ac515c40b90b5c560a5346176f50a46770bac8bbc96334e65c1985b5a80a2283f67a62
data/config/default.yml CHANGED
@@ -59,3 +59,8 @@ Vendor/WsSdkPathInjection:
59
59
  Description: 'Avoid using `ws_sdk` with path injection.'
60
60
  Enabled: true
61
61
  VersionAdded: '0.12.0'
62
+
63
+ Vendor/ActiveRecordBaseTransactionUse:
64
+ Description: 'Avoid using ActiveRecord::Base.transaction.'
65
+ Enabled: true
66
+ VersionAdded: '0.13.0'
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Vendor
6
+ # Flags uses of ActiveRecord::Base.transaction,
7
+ # as subclasses of ActiveRecord::Base may use a different
8
+ # database connection.
9
+ #
10
+ # This becomes relevant if, for instance, your application
11
+ # defines models or any subclass of ActiveRecord::Base
12
+ # specifying connection configurations, e.g. using `connects_to`.
13
+ #
14
+ # The guarantee that transaction connection matches the
15
+ # model connection is strongest when `MyModelClass.transaction`
16
+ # wraps database operations on instances of MyModelClass only.
17
+ #
18
+ # If multiple model classes are involved in a .transaction
19
+ # call, `.transaction` only needs to be called on one of them,
20
+ # or a common ancestor sharing the same connection
21
+ # if both models share the same underlying connection.
22
+ #
23
+ # If not, a workaround would be to open a transaction on both
24
+ # model classes.
25
+ #
26
+ # @example
27
+ #
28
+ # # bad
29
+ # ActiveRecord::Base.transaction do
30
+ # ... database operations
31
+ # end
32
+ #
33
+ # # good
34
+ # MyModelClass.transaction do
35
+ # ... database operations on instances of MyModelClass
36
+ # end
37
+ #
38
+ # # also good
39
+ # my_model_instance.with_lock do
40
+ # ... database operations on my_model_instance
41
+ # end
42
+ #
43
+ # # good if and only if both models share a database connection
44
+ # MyModelClass.transaction do
45
+ # ... database operations on instances of MyModelClass
46
+ # ... database operations on instances of MyOtherModelClass
47
+ # end
48
+ #
49
+ # # good if and only if ApplicationRecord shares a database
50
+ # # connection with all models involved
51
+ # ApplicationRecord.transaction do
52
+ # ... database operations on instances of MyModelClass
53
+ # ... database operations on instances of MyOtherModelClass
54
+ # end
55
+ #
56
+ # # good if the models do not share a database connection
57
+ # MyModelClass.transaction do
58
+ # MyOtherModelClass.transaction do
59
+ # ... database operations on instances of MyModelClass
60
+ # ... database operations on instances of MyOtherModelClass
61
+ # end
62
+ # end
63
+ #
64
+ class ActiveRecordBaseTransactionUse < Base
65
+ MSG = 'Avoid using `ActiveRecord::Base.transaction, as models inheriting a subclass of ActiveRecord::Base may use a different database connection from ActiveRecord::Base.connection.'
66
+
67
+ # @!method uses_active_record_base?(node)
68
+ def_node_matcher :uses_active_record_base?, <<-PATTERN
69
+ (const (const {nil? cbase} :ActiveRecord) :Base)
70
+ PATTERN
71
+
72
+ def on_send(node)
73
+ receiver_node, method_name = *node
74
+
75
+ return unless uses_active_record_base?(receiver_node) && method_name == :transaction
76
+
77
+ add_offense(node)
78
+ end
79
+ end
80
+ end
81
+ end
82
+ end
@@ -9,8 +9,6 @@ module RuboCop
9
9
  # resulting in at-most once delivery of sidekiq jobs, instead of at-least once delivery
10
10
  # of sidekiq jobs. This means there is a relatively good chance you will LOSE JOBS that were enqueued
11
11
  # if the sidekiq-process runs out of memory or does not shutdown gracefully.
12
- #
13
- # https://wealthsimple.slack.com/archives/C19UB3HNZ/p1683721247371709 for more details
14
12
  class SidekiqThrottledGem < Base
15
13
  MSG = <<~MSG.strip
16
14
  Do not use the sidekiq-throttled gem. sidekiq-throttled overrides the fetcher of sidekiq-pro and sidekiq-enterprise resulting in the ability to lose jobs (switch to at-most once processing).
@@ -3,6 +3,7 @@
3
3
  module RuboCop
4
4
  end
5
5
 
6
+ require_relative 'vendor/active_record_base_transaction_use'
6
7
  require_relative 'vendor/active_record_connection_execute'
7
8
  require_relative 'vendor/recursive_open_struct_gem'
8
9
  require_relative 'vendor/sidekiq_throttled_gem'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Vendor
5
- VERSION = '0.12.2'
5
+ VERSION = '0.13.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubocop-vendor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.13.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Cabello
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2024-01-03 00:00:00.000000000 Z
13
+ date: 2024-07-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -96,6 +96,7 @@ files:
96
96
  - README.md
97
97
  - config/default.yml
98
98
  - lib/rubocop-vendor.rb
99
+ - lib/rubocop/cop/vendor/active_record_base_transaction_use.rb
99
100
  - lib/rubocop/cop/vendor/active_record_connection_execute.rb
100
101
  - lib/rubocop/cop/vendor/base.rb
101
102
  - lib/rubocop/cop/vendor/recursive_open_struct_gem.rb