rubocop-vendor 0.10.0 → 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: 0a33862f683a309f1600a568b4eeb7b4f52e5eed2bd2ea5fede18abaf9d561e8
4
- data.tar.gz: c82795011f42d2defeda94fc5449a0dc5467e4d98989fbe7fa3b900e13fc3d68
3
+ metadata.gz: f69fd94e8d9429fec0334913a5d2bcfa8f2e2873e777ec17879a37d0ca044eb6
4
+ data.tar.gz: 6a012a6071337d04d50cefd51ddc07c63abe07f96f70eae9acd094e9a8d8ee27
5
5
  SHA512:
6
- metadata.gz: 424caf7dec430127f8e22d628094c5e133c71c8d6eee4fb4511a6bad1ac4fa6cfc8e1cd1d7a6f00caa0828f20662216569c992b5637590b17ebf43f462674d23
7
- data.tar.gz: 5fbe0dac05a5d3e43a08c194e5889d7bf4f062fba87bc3405791a090d06f1d611a108e8f5c8c3eb848a5c38860187d4e14fecef04b819a459941abcafa8c78aa
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
@@ -3,6 +3,7 @@
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'
7
8
  require_relative 'vendor/sidekiq_throttled_gem'
8
9
  require_relative 'vendor/recursive_open_struct_use'
@@ -2,6 +2,6 @@
2
2
 
3
3
  module RuboCop
4
4
  module Vendor
5
- VERSION = '0.10.0'
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.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danilo Cabello
@@ -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