rubocop-vendor 0.9.2 → 0.11.0

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: 3aaeec03267633acaabb79d26b67a746cbf6f6c948caf17a23d09f849c848e28
4
- data.tar.gz: ae8181215d4429dc949c8be90b2bed61edc6537a5594d303abf464609cc6020a
3
+ metadata.gz: f69fd94e8d9429fec0334913a5d2bcfa8f2e2873e777ec17879a37d0ca044eb6
4
+ data.tar.gz: 6a012a6071337d04d50cefd51ddc07c63abe07f96f70eae9acd094e9a8d8ee27
5
5
  SHA512:
6
- metadata.gz: ab196d519384425d33f216d7d62c92f3d0f78a57784375ffebb920810cb40ad4e0120c1bdd9a82e0ac6192697b7e93ae0d0c4ce6866f1f945eefc35be184fd85
7
- data.tar.gz: 5cd67595559509195643f091ef0ee35cde3e67b9b11e128360cbd76e6d0c087b568efe3055fc78a5b61aff7ab0726cb5ad6fb4da8ef246960896a22f8b0218dc
6
+ metadata.gz: 6406158144116b3cc61af8e30c8e68c2285073b8eb5ed0ed2fba58f7570a3c5d73732a1ed331beb1333957e08606228faefc1bd1803fdac34d2ab903015d8008
7
+ data.tar.gz: 470e41a804dba4c86ac1b8654a2204fdf4de33dec852d1c185e98b9fbc2f509cf28e7eec4a7fed575374c0cf23cc45cb19ffb30abc2caa6fb89f9b4898c0730d
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Vendor
6
+ # This cop checks for `ActiveRecord::Connection#execute` usage and suggests
7
+ # using non-manually memory managed objects instead.
8
+ #
9
+ # The main reason for this is this is a common way to leak memory in a Ruby on Rails application.
10
+ # see {
11
+ # https://github.com/rails/rails/blob/a19b13b61f7af612569943ec7d536185cbec875c/activerecord/lib/active_record/connection_adapters/abstract/database_statements.rb#L127
12
+ # ActiveRecord documentation
13
+ # }.
14
+ #
15
+ # @example
16
+ # # bad
17
+ # ActiveRecord::Base.connection.execute('SELECT * FROM users')
18
+ # ApplicationRecord.connection.execute('SELECT * FROM users')
19
+ # User.connection.execute('SELECT * FROM users')
20
+ #
21
+ # # good
22
+ # ActiveRecord::Base.connection.select_all('SELECT * FROM users')
23
+ # ApplicationRecord.connection.select_all('SELECT * FROM users')
24
+ # User.connection.select_all('SELECT * FROM users')
25
+ #
26
+ class ActiveRecordConnectionExecute < Base
27
+ MSG = <<-STR.strip
28
+ Use of `ActiveRecord::Connection#execute` returns manually memory managed object, consider using `select_one`, `select_all`, `insert`, `update`, `delete`. If necessary, you can also use `exec_query`, `exec_insert`, `exec_update`, `exec_delete`.
29
+ STR
30
+
31
+ # @!method connection_execute_method_call?(node)
32
+ def_node_matcher :connection_execute_method_call?, <<-PATTERN
33
+ (send (send _ :connection) :execute ...)
34
+ PATTERN
35
+
36
+ def on_send(node)
37
+ return unless connection_execute_method_call?(node)
38
+
39
+ add_offense(node)
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RuboCop
4
+ module Cop
5
+ module Vendor
6
+ # This cop flags uses of the sidekiq-throttled gem.
7
+ #
8
+ # sidekiq-throttled overrides sidekiq-pro and sidekiq-enterprise features,
9
+ # resulting in at-most once delivery of sidekiq jobs, instead of at-least once delivery
10
+ # of sidekiq jobs. This means there is a relatively good chance you will LOSE JOBS that were enqueued
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
+ class SidekiqThrottledGem < Base
15
+ MSG = <<~MSG.strip
16
+ 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).
17
+ MSG
18
+
19
+ def on_new_investigation
20
+ return if processed_source.blank?
21
+
22
+ gem_declarations(processed_source.ast).each do |declaration|
23
+ next unless declaration.first_argument.str_content.match?('sidekiq-throttled')
24
+
25
+ add_offense(declaration)
26
+ end
27
+ end
28
+
29
+ # @!method gem_declarations(node)
30
+ def_node_search :gem_declarations, <<~PATTERN
31
+ (:send nil? :gem str ...)
32
+ PATTERN
33
+ end
34
+ end
35
+ end
36
+ end
@@ -3,7 +3,9 @@
3
3
  module RuboCop
4
4
  end
5
5
 
6
+ require_relative 'vendor/active_record_connection_execute'
6
7
  require_relative 'vendor/recursive_open_struct_gem'
8
+ require_relative 'vendor/sidekiq_throttled_gem'
7
9
  require_relative 'vendor/recursive_open_struct_use'
8
10
  require_relative 'vendor/rollbar_inside_rescue'
9
11
  require_relative 'vendor/rollbar_interpolation'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Vendor
5
- VERSION = '0.9.2'
5
+ VERSION = '0.11.0'
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.9.2
4
+ version: 0.11.0
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: 2023-04-14 00:00:00.000000000 Z
13
+ date: 2023-05-26 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rubocop
@@ -82,6 +82,7 @@ files:
82
82
  - README.md
83
83
  - config/default.yml
84
84
  - lib/rubocop-vendor.rb
85
+ - lib/rubocop/cop/vendor/active_record_connection_execute.rb
85
86
  - lib/rubocop/cop/vendor/base.rb
86
87
  - lib/rubocop/cop/vendor/recursive_open_struct_gem.rb
87
88
  - lib/rubocop/cop/vendor/recursive_open_struct_use.rb
@@ -90,6 +91,7 @@ files:
90
91
  - lib/rubocop/cop/vendor/rollbar_log.rb
91
92
  - lib/rubocop/cop/vendor/rollbar_logger.rb
92
93
  - lib/rubocop/cop/vendor/rollbar_with_exception.rb
94
+ - lib/rubocop/cop/vendor/sidekiq_throttled_gem.rb
93
95
  - lib/rubocop/cop/vendor/strict_dry_struct.rb
94
96
  - lib/rubocop/cop/vendor_cops.rb
95
97
  - lib/rubocop/vendor.rb