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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f69fd94e8d9429fec0334913a5d2bcfa8f2e2873e777ec17879a37d0ca044eb6
|
4
|
+
data.tar.gz: 6a012a6071337d04d50cefd51ddc07c63abe07f96f70eae9acd094e9a8d8ee27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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.
|
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
|