rubocop-redis 0.1.2 → 0.1.3

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: 88c0751305ae0be68873bb027ea34611d02059c3654606f6d5b77ff935edd243
4
+ data.tar.gz: 6e2c5281ebbe7fa262938b722aeabe69c07f9ed20ad3966b2e70ad4e14b06454
5
5
  SHA512:
6
- metadata.gz: a72c9dd2111a7708d6a2be7dd647c429f6eb35ed4be3f9b241d708ea6120b245608dfa87458eaf9f926162cf42882b950cc86ea82e1500275ade15e2047f61ce
7
- data.tar.gz: 440440c4c738fc46270389dbc1810ab63066bcd420703d8776c79cce00f5fba9d98f92d78384916ad731addd1d8abfae335fb8160fc4602cf9067d19716f467d
6
+ metadata.gz: 2b9afb62bf8d1c0c49c5aa12ad03d1b53bc2d2eee67b24414fb0ee0ea373d682c7611eee4e4f4d97fc996305e8f64619b4c44f109dc1cd77e6a0f1884a57f3b3
7
+ data.tar.gz: 275ad6cee5146caed431c517a661ac9d919029a55e3412374dccaaed47628751595d89e54a863515caffafbb05b2e302559afa346ef3877b0378cbb0cdfa6d26
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]
File without changes
@@ -0,0 +1,35 @@
1
+ = Redis
2
+
3
+ == Redis/NotKeys
4
+
5
+ |===
6
+ | Enabled by default | Safe | Supports autocorrection | Version Added | Version Changed
7
+
8
+ | Enabled
9
+ | Yes
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
+ === Examples
20
+
21
+ [source,ruby]
22
+ ----
23
+ # bad
24
+ Redis.current.keys("pattern-*")
25
+
26
+ # good
27
+ cursor = 0
28
+ all_keys = []
29
+ loop do
30
+ cursor, keys = Redis.current.scan(cursor, match: "pattern-*")
31
+ all_keys += keys
32
+ break if cursor == "0"
33
+ end
34
+ all_keys
35
+ ----
@@ -4,6 +4,23 @@ 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
+ # @example
11
+ # # bad
12
+ # Redis.current.keys("pattern-*")
13
+ #
14
+ # # good
15
+ # cursor = 0
16
+ # all_keys = []
17
+ # loop do
18
+ # cursor, keys = Redis.current.scan(cursor, match: "pattern-*")
19
+ # all_keys += keys
20
+ # break if cursor == "0"
21
+ # end
22
+ # all_keys
23
+ #
7
24
  class NotKeys < Base
8
25
  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
26
 
@@ -13,6 +30,8 @@ module RuboCop
13
30
  (const {cbase nil?} :Redis) :current) :keys $...)
14
31
  PATTERN
15
32
 
33
+ RESTRICT_ON_SEND = %i[keys].freeze
34
+
16
35
  def on_send(node)
17
36
  return unless keys_call?(node)
18
37
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rubocop
4
4
  module Redis
5
- VERSION = "0.1.2"
5
+ VERSION = "0.1.3"
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.3
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-08-24 00:00:00.000000000 Z
11
+ date: 2022-09-04 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,13 +33,15 @@ 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
39
- post_install_message:
43
+ changelog_uri: https://github.com/9sako6/rubocop-redis/releases
44
+ post_install_message:
40
45
  rdoc_options: []
41
46
  require_paths:
42
47
  - lib
@@ -51,8 +56,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
56
  - !ruby/object:Gem::Version
52
57
  version: '0'
53
58
  requirements: []
54
- rubygems_version: 3.3.4
55
- signing_key:
59
+ rubygems_version: 3.2.15
60
+ signing_key:
56
61
  specification_version: 4
57
62
  summary: An extension of RuboCop for redis/redis gem.
58
63
  test_files: []