rubocop-redis 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +3 -0
- data/docs/modules/ROOT/pages/cops_redis.adoc +7 -2
- data/lib/rubocop/cop/redis/not_keys.rb +21 -4
- data/lib/rubocop/redis/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32561f1c19ab9a331fbf7a88828bae2c51e3b688235e8f8d632439c7ed4e94a6
|
4
|
+
data.tar.gz: ffb1a9c65495fff2393ec0f8a3ad5550c1a469b018bc5fce2772890c1bb7167b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe622f73bfcbabf171f47123943bf8be995cbfd2725190126d377bda9b2e0b504db423706b027e8935050a06d60a4ba9e35845059b4acf9dd7652a4043c5e135
|
7
|
+
data.tar.gz: 57d7310c4f3f42fa851aaa6114c38ac221ebcb330ae342a89a12d27b3a0b2c3f935e8e66aedda59bf69068202c135d2afa5f23163e4651a0feeb70678c20e5b7
|
data/.rubocop.yml
CHANGED
@@ -16,18 +16,23 @@ This cop detects the use of `KEYS` query that should be noted when used in a pro
|
|
16
16
|
Consider using `SCAN` query instead of `KEYS` query.
|
17
17
|
See https://redis.io/commands/keys/ for details.
|
18
18
|
|
19
|
+
To avoid detecting `Hash#keys` calling, this cop adds an offense if a receiver of `keys` method is named `redis`.
|
20
|
+
|
19
21
|
=== Examples
|
20
22
|
|
21
23
|
[source,ruby]
|
22
24
|
----
|
23
25
|
# bad
|
24
|
-
|
26
|
+
redis.keys("pattern-*")
|
27
|
+
|
28
|
+
# bad
|
29
|
+
Redis.new.keys("pattern-*")
|
25
30
|
|
26
31
|
# good
|
27
32
|
cursor = 0
|
28
33
|
all_keys = []
|
29
34
|
loop do
|
30
|
-
cursor, keys =
|
35
|
+
cursor, keys = redis.scan(cursor, match: "pattern-*")
|
31
36
|
all_keys += keys
|
32
37
|
break if cursor == "0"
|
33
38
|
end
|
@@ -7,15 +7,20 @@ module RuboCop
|
|
7
7
|
# Consider using `SCAN` query instead of `KEYS` query.
|
8
8
|
# See https://redis.io/commands/keys/ for details.
|
9
9
|
#
|
10
|
+
# To avoid detecting `Hash#keys` calling, this cop adds an offense only if a receiver of `keys` method is named `redis`.
|
11
|
+
#
|
10
12
|
# @example
|
11
13
|
# # bad
|
12
|
-
#
|
14
|
+
# redis.keys("pattern-*")
|
15
|
+
#
|
16
|
+
# # bad
|
17
|
+
# Redis.new.keys("pattern-*")
|
13
18
|
#
|
14
19
|
# # good
|
15
20
|
# cursor = 0
|
16
21
|
# all_keys = []
|
17
22
|
# loop do
|
18
|
-
# cursor, keys =
|
23
|
+
# cursor, keys = redis.scan(cursor, match: "pattern-*")
|
19
24
|
# all_keys += keys
|
20
25
|
# break if cursor == "0"
|
21
26
|
# end
|
@@ -27,16 +32,28 @@ module RuboCop
|
|
27
32
|
def_node_matcher :keys_call?, <<~PATTERN
|
28
33
|
(send
|
29
34
|
(send
|
30
|
-
(const {cbase nil?} :Redis) :current) :keys
|
35
|
+
(const {cbase nil?} :Redis) {:new | :current} ...) :keys ...)
|
36
|
+
PATTERN
|
37
|
+
|
38
|
+
def_node_matcher :keys_call_for_object?, <<~PATTERN
|
39
|
+
(send ($...) :keys ...)
|
31
40
|
PATTERN
|
32
41
|
|
33
42
|
RESTRICT_ON_SEND = %i[keys].freeze
|
34
43
|
|
35
44
|
def on_send(node)
|
36
|
-
return unless keys_call?(node)
|
45
|
+
return unless keys_call?(node) || keys_call_for_object_named_redis?(node)
|
37
46
|
|
38
47
|
add_offense(node)
|
39
48
|
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def keys_call_for_object_named_redis?(node)
|
53
|
+
receiver, message = keys_call_for_object?(node)
|
54
|
+
|
55
|
+
receiver.nil? && message == :redis
|
56
|
+
end
|
40
57
|
end
|
41
58
|
end
|
42
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubocop-redis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 9sako6
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: An extension of RuboCop for redis/redis gem.
|
14
14
|
email:
|
@@ -41,7 +41,7 @@ metadata:
|
|
41
41
|
homepage_uri: https://github.com/9sako6/rubocop-redis
|
42
42
|
source_code_uri: https://github.com/9sako6/rubocop-redis
|
43
43
|
changelog_uri: https://github.com/9sako6/rubocop-redis/releases
|
44
|
-
post_install_message:
|
44
|
+
post_install_message:
|
45
45
|
rdoc_options: []
|
46
46
|
require_paths:
|
47
47
|
- lib
|
@@ -56,8 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
56
56
|
- !ruby/object:Gem::Version
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
|
-
rubygems_version: 3.
|
60
|
-
signing_key:
|
59
|
+
rubygems_version: 3.3.4
|
60
|
+
signing_key:
|
61
61
|
specification_version: 4
|
62
62
|
summary: An extension of RuboCop for redis/redis gem.
|
63
63
|
test_files: []
|