rubocop-redis 0.1.2 → 0.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 479c3bae5bed1f65f985ba12a41b57828d03a74a822066112fde6fa9f478214a
4
- data.tar.gz: fb9ea8b8ff4c8f586d9e060a49a085abef336c15e04f5a8d6155f568fa6c9854
3
+ metadata.gz: dc23288a737431b58136458dcd511758b722f6f3939fefc617abcbd64c7e5fa6
4
+ data.tar.gz: dec4f8b93b223cc068c733f65287f02e2169ec69b90bb672b6f8a9dbe362c627
5
5
  SHA512:
6
- metadata.gz: a72c9dd2111a7708d6a2be7dd647c429f6eb35ed4be3f9b241d708ea6120b245608dfa87458eaf9f926162cf42882b950cc86ea82e1500275ade15e2047f61ce
7
- data.tar.gz: 440440c4c738fc46270389dbc1810ab63066bcd420703d8776c79cce00f5fba9d98f92d78384916ad731addd1d8abfae335fb8160fc4602cf9067d19716f467d
6
+ metadata.gz: df8684490628860d3cd491bbb84f9d2cc9d1b6da56a68ed7f1f87d056131424db367be9ff2d6043b9e626a7ea66bbfeb9a523a32d46cfe7491c5fc0386911eef
7
+ data.tar.gz: aac88b4db49efa476fa52917cf906ce13fe6892bc9ae7e24eb8314189fcd12dba32e9a17f49869cf433785913642d44e47092c22d7433e0610ec4f87d764f141
data/.rubocop.yml CHANGED
@@ -17,3 +17,6 @@ Layout/LineLength:
17
17
 
18
18
  Naming/FileName:
19
19
  Enabled: false
20
+
21
+ Metrics/BlockLength:
22
+ Enabled: false
data/Gemfile CHANGED
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0"
10
10
  gem "rspec", "~> 3.0"
11
11
 
12
12
  gem "rubocop", "~> 1.21"
13
+
14
+ gem "yard", "~> 0.9.28"
data/LICENSE.txt ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright © 2022 9sako6
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  An extension of RuboCop for [redis/redis-rb](https://github.com/redis/redis-rb) Redis client.
4
4
 
5
+ ## Documentation
6
+
7
+ You can read a lot more about rubocop-redis in its [docs](docs/modules/ROOT/pages/cops_redis.adoc).
8
+
5
9
  ## Installation
6
10
 
7
11
  Add this line to your application's Gemfile:
@@ -20,8 +24,46 @@ Or install it yourself as:
20
24
 
21
25
  ## Usage
22
26
 
23
- TODO: Write usage instructions here
27
+ You need to tell RuboCop to load the Redis extension. There are three
28
+ ways to do this:
29
+
30
+ ### RuboCop configuration file
31
+
32
+ Put this into your `.rubocop.yml`.
33
+
34
+ ```yaml
35
+ require: rubocop-redis
36
+ ```
37
+
38
+ Alternatively, use the following array notation when specifying multiple extensions.
39
+
40
+ ```yaml
41
+ require:
42
+ - rubocop-other-extension
43
+ - rubocop-redis
44
+ ```
45
+
46
+ Now you can run `rubocop` and it will automatically load the rubocop-redis
47
+ cops together with the standard cops.
48
+
49
+ ### Command line
50
+
51
+ ```bash
52
+ rubocop --require rubocop-redis
53
+ ```
54
+
55
+ ### Rake task
56
+
57
+ ```ruby
58
+ RuboCop::RakeTask.new do |task|
59
+ task.requires << 'rubocop-redis'
60
+ end
61
+ ```
24
62
 
25
63
  ## Contributing
26
64
 
27
65
  Bug reports and pull requests are welcome on GitHub at https://github.com/9sako6/rubocop-redis.
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/gem_tasks"
4
4
  require "rspec/core/rake_task"
5
+ load "tasks/doc.rake"
5
6
 
6
7
  RSpec::Core::RakeTask.new(:spec)
7
8
 
@@ -9,4 +10,4 @@ require "rubocop/rake_task"
9
10
 
10
11
  RuboCop::RakeTask.new
11
12
 
12
- task default: %i[spec rubocop]
13
+ task default: %i[spec rubocop update_cops_documentation]
data/config/default.yml CHANGED
@@ -4,3 +4,4 @@ Redis/NotKeys:
4
4
  Description: "Do not use `.keys`. It may ruin performance when it is executed against large databases. See https://redis.io/commands/keys/ for details."
5
5
  Enabled: true
6
6
  VersionAdded: "0.1"
7
+ Safe: false
File without changes
@@ -0,0 +1,40 @@
1
+ = Redis
2
+
3
+ == Redis/NotKeys
4
+
5
+ |===
6
+ | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
7
+
8
+ | Enabled
9
+ | No
10
+ | No
11
+ | 0.1
12
+ | -
13
+ |===
14
+
15
+ This cop detects the use of `KEYS` query that should be noted when used in a production environment.
16
+ Consider using `SCAN` query instead of `KEYS` query.
17
+ See https://redis.io/commands/keys/ for details.
18
+
19
+ To avoid detecting `Hash#keys` calling, this cop adds an offense only if a receiver of `keys` method is named `redis`.
20
+
21
+ === Examples
22
+
23
+ [source,ruby]
24
+ ----
25
+ # bad
26
+ redis.keys("pattern-*")
27
+
28
+ # bad
29
+ Redis.new.keys("pattern-*")
30
+
31
+ # good
32
+ cursor = 0
33
+ all_keys = []
34
+ loop do
35
+ cursor, keys = redis.scan(cursor, match: "pattern-*")
36
+ all_keys += keys
37
+ break if cursor == "0"
38
+ end
39
+ all_keys
40
+ ----
@@ -4,20 +4,56 @@ module RuboCop
4
4
  module Cop
5
5
  module Redis
6
6
  # This cop detects the use of `KEYS` query that should be noted when used in a production environment.
7
+ # Consider using `SCAN` query instead of `KEYS` query.
8
+ # See https://redis.io/commands/keys/ for details.
9
+ #
10
+ # To avoid detecting `Hash#keys` calling, this cop adds an offense only if a receiver of `keys` method is named `redis`.
11
+ #
12
+ # @example
13
+ # # bad
14
+ # redis.keys("pattern-*")
15
+ #
16
+ # # bad
17
+ # Redis.new.keys("pattern-*")
18
+ #
19
+ # # good
20
+ # cursor = 0
21
+ # all_keys = []
22
+ # loop do
23
+ # cursor, keys = redis.scan(cursor, match: "pattern-*")
24
+ # all_keys += keys
25
+ # break if cursor == "0"
26
+ # end
27
+ # all_keys
28
+ #
7
29
  class NotKeys < Base
8
30
  MSG = "Do not use `.keys`. It may ruin performance when it is executed against large databases. See https://redis.io/commands/keys/ for details."
9
31
 
10
32
  def_node_matcher :keys_call?, <<~PATTERN
11
33
  (send
12
34
  (send
13
- (const {cbase nil?} :Redis) :current) :keys $...)
35
+ (const {cbase nil?} :Redis) {:new | :current} ...) :keys ...)
14
36
  PATTERN
15
37
 
38
+ def_node_matcher :keys_call_for_object?, <<~PATTERN
39
+ (send ($...) :keys ...)
40
+ PATTERN
41
+
42
+ RESTRICT_ON_SEND = %i[keys].freeze
43
+
16
44
  def on_send(node)
17
- return unless keys_call?(node)
45
+ return unless keys_call?(node) || keys_call_for_object_named_redis?(node)
18
46
 
19
47
  add_offense(node)
20
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
21
57
  end
22
58
  end
23
59
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Redis
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.5"
6
6
  end
7
7
  end
@@ -11,11 +11,12 @@ Gem::Specification.new do |spec|
11
11
  spec.summary = "An extension of RuboCop for redis/redis gem."
12
12
  spec.description = "An extension of RuboCop for redis/redis gem."
13
13
  spec.homepage = "https://github.com/9sako6/rubocop-redis"
14
+ spec.license = 'MIT'
14
15
  spec.required_ruby_version = ">= 2.6.0"
15
16
 
16
17
  spec.metadata["homepage_uri"] = spec.homepage
17
18
  spec.metadata["source_code_uri"] = "https://github.com/9sako6/rubocop-redis"
18
- spec.metadata["changelog_uri"] = "https://github.com/9sako6/rubocop-redis"
19
+ spec.metadata["changelog_uri"] = "https://github.com/9sako6/rubocop-redis/releases"
19
20
 
20
21
  # Specify which files should be added to the gem when it is released.
21
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
data/tasks/doc.rake ADDED
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yard'
4
+ require 'rubocop'
5
+ require_relative '../lib/rubocop-redis'
6
+ require 'rubocop/cops_documentation_generator'
7
+
8
+ YARD::Rake::YardocTask.new(:yard_for_generate_documentation) do |task|
9
+ task.files = ['lib/rubocop/cop/**/*.rb']
10
+ task.options = ['--no-output']
11
+ end
12
+
13
+ task update_cops_documentation: :yard_for_generate_documentation do
14
+ deps = ['Redis']
15
+
16
+ # NOTE: Update `<<next>>` version for docs/modules/ROOT/pages/cops_redis.adoc
17
+ # when running release tasks.
18
+ RuboCop::Redis::Inject.defaults!
19
+
20
+ CopsDocumentationGenerator.new(departments: deps).call
21
+ 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.2
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - 9sako6
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-08-24 00:00:00.000000000 Z
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:
@@ -20,9 +20,12 @@ files:
20
20
  - ".rspec"
21
21
  - ".rubocop.yml"
22
22
  - Gemfile
23
+ - LICENSE.txt
23
24
  - README.md
24
25
  - Rakefile
25
26
  - config/default.yml
27
+ - docs/modules/ROOT/pages/cops.adoc
28
+ - docs/modules/ROOT/pages/cops_redis.adoc
26
29
  - lib/rubocop-redis.rb
27
30
  - lib/rubocop/cop/redis/not_keys.rb
28
31
  - lib/rubocop/cop/redis_cops.rb
@@ -30,12 +33,14 @@ files:
30
33
  - lib/rubocop/redis/inject.rb
31
34
  - lib/rubocop/redis/version.rb
32
35
  - rubocop-redis.gemspec
36
+ - tasks/doc.rake
33
37
  homepage: https://github.com/9sako6/rubocop-redis
34
- licenses: []
38
+ licenses:
39
+ - MIT
35
40
  metadata:
36
41
  homepage_uri: https://github.com/9sako6/rubocop-redis
37
42
  source_code_uri: https://github.com/9sako6/rubocop-redis
38
- changelog_uri: https://github.com/9sako6/rubocop-redis
43
+ changelog_uri: https://github.com/9sako6/rubocop-redis/releases
39
44
  post_install_message:
40
45
  rdoc_options: []
41
46
  require_paths: