rubocop-sidekiq_plus 0.1.0

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.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE.txt +21 -0
  3. data/README.md +322 -0
  4. data/config/default.yml +396 -0
  5. data/lib/rubocop/cop/sidekiq/active_record_argument.rb +77 -0
  6. data/lib/rubocop/cop/sidekiq/async_in_test.rb +42 -0
  7. data/lib/rubocop/cop/sidekiq/base.rb +14 -0
  8. data/lib/rubocop/cop/sidekiq/consistent_job_suffix.rb +44 -0
  9. data/lib/rubocop/cop/sidekiq/constant_job_class_name.rb +53 -0
  10. data/lib/rubocop/cop/sidekiq/database_connection_leak.rb +33 -0
  11. data/lib/rubocop/cop/sidekiq/date_time_argument.rb +80 -0
  12. data/lib/rubocop/cop/sidekiq/deprecated_default_worker_options.rb +44 -0
  13. data/lib/rubocop/cop/sidekiq/deprecated_delay_extension.rb +29 -0
  14. data/lib/rubocop/cop/sidekiq/deprecated_worker_module.rb +40 -0
  15. data/lib/rubocop/cop/sidekiq/enqueue_inefficiency.rb +75 -0
  16. data/lib/rubocop/cop/sidekiq/excessive_retry.rb +52 -0
  17. data/lib/rubocop/cop/sidekiq/find_each_in_job.rb +58 -0
  18. data/lib/rubocop/cop/sidekiq/huge_job_arguments.rb +73 -0
  19. data/lib/rubocop/cop/sidekiq/job_dependency.rb +30 -0
  20. data/lib/rubocop/cop/sidekiq/job_file_location.rb +52 -0
  21. data/lib/rubocop/cop/sidekiq/job_file_naming.rb +38 -0
  22. data/lib/rubocop/cop/sidekiq/job_include.rb +67 -0
  23. data/lib/rubocop/cop/sidekiq/missing_logging.rb +49 -0
  24. data/lib/rubocop/cop/sidekiq/missing_timeout.rb +65 -0
  25. data/lib/rubocop/cop/sidekiq/mixed_retry_strategies.rb +55 -0
  26. data/lib/rubocop/cop/sidekiq/mixin/argument_traversal.rb +28 -0
  27. data/lib/rubocop/cop/sidekiq/mixin/class_name_helper.rb +23 -0
  28. data/lib/rubocop/cop/sidekiq/mixin/processed_source_path.rb +19 -0
  29. data/lib/rubocop/cop/sidekiq/no_rescue_all.rb +70 -0
  30. data/lib/rubocop/cop/sidekiq/perform_inline_usage.rb +53 -0
  31. data/lib/rubocop/cop/sidekiq/perform_method_parameters.rb +53 -0
  32. data/lib/rubocop/cop/sidekiq/pii_in_arguments.rb +90 -0
  33. data/lib/rubocop/cop/sidekiq/puts_or_print_usage.rb +37 -0
  34. data/lib/rubocop/cop/sidekiq/queue_specified.rb +74 -0
  35. data/lib/rubocop/cop/sidekiq/redis_in_job.rb +32 -0
  36. data/lib/rubocop/cop/sidekiq/retry_specified.rb +81 -0
  37. data/lib/rubocop/cop/sidekiq/retry_zero.rb +48 -0
  38. data/lib/rubocop/cop/sidekiq/self_scheduling_job.rb +54 -0
  39. data/lib/rubocop/cop/sidekiq/sensitive_data_in_arguments.rb +92 -0
  40. data/lib/rubocop/cop/sidekiq/sidekiq_over_active_job.rb +30 -0
  41. data/lib/rubocop/cop/sidekiq/silent_rescue.rb +63 -0
  42. data/lib/rubocop/cop/sidekiq/sleep_in_jobs.rb +46 -0
  43. data/lib/rubocop/cop/sidekiq/symbol_argument.rb +69 -0
  44. data/lib/rubocop/cop/sidekiq/thread_in_job.rb +53 -0
  45. data/lib/rubocop/cop/sidekiq/transaction_leak.rb +72 -0
  46. data/lib/rubocop/cop/sidekiq/unknown_sidekiq_option.rb +52 -0
  47. data/lib/rubocop/cop/sidekiq_cops.rb +71 -0
  48. data/lib/rubocop/cop/sidekiq_ent/base.rb +43 -0
  49. data/lib/rubocop/cop/sidekiq_ent/encryption_with_many_arguments.rb +71 -0
  50. data/lib/rubocop/cop/sidekiq_ent/encryption_without_secret_bag.rb +83 -0
  51. data/lib/rubocop/cop/sidekiq_ent/leader_election_without_block.rb +75 -0
  52. data/lib/rubocop/cop/sidekiq_ent/limiter_not_reused.rb +79 -0
  53. data/lib/rubocop/cop/sidekiq_ent/limiter_without_lock_timeout.rb +46 -0
  54. data/lib/rubocop/cop/sidekiq_ent/limiter_without_wait_timeout.rb +49 -0
  55. data/lib/rubocop/cop/sidekiq_ent/periodic_job_invalid_cron.rb +108 -0
  56. data/lib/rubocop/cop/sidekiq_ent/periodic_job_with_arguments.rb +94 -0
  57. data/lib/rubocop/cop/sidekiq_ent/unique_job_too_short_ttl.rb +80 -0
  58. data/lib/rubocop/cop/sidekiq_ent/unique_job_without_ttl.rb +52 -0
  59. data/lib/rubocop/cop/sidekiq_ent/unique_until_mismatch.rb +59 -0
  60. data/lib/rubocop/cop/sidekiq_pro/base.rb +39 -0
  61. data/lib/rubocop/cop/sidekiq_pro/batch_callback_method.rb +66 -0
  62. data/lib/rubocop/cop/sidekiq_pro/batch_retry_in_callback.rb +54 -0
  63. data/lib/rubocop/cop/sidekiq_pro/batch_status_polling.rb +68 -0
  64. data/lib/rubocop/cop/sidekiq_pro/batch_without_callback.rb +92 -0
  65. data/lib/rubocop/cop/sidekiq_pro/empty_batch.rb +108 -0
  66. data/lib/rubocop/cop/sidekiq_pro/expiring_job_without_ttl.rb +101 -0
  67. data/lib/rubocop/cop/sidekiq_pro/large_argument_in_batch.rb +93 -0
  68. data/lib/rubocop/cop/sidekiq_pro/nested_batch_without_parent.rb +55 -0
  69. data/lib/rubocop/cop/sidekiq_pro/reliability_not_enabled.rb +67 -0
  70. data/lib/rubocop/sidekiq/config_formatter.rb +60 -0
  71. data/lib/rubocop/sidekiq/description_extractor.rb +70 -0
  72. data/lib/rubocop/sidekiq/language.rb +79 -0
  73. data/lib/rubocop/sidekiq/plugin.rb +30 -0
  74. data/lib/rubocop/sidekiq/version.rb +7 -0
  75. data/lib/rubocop/sidekiq.rb +10 -0
  76. data/lib/rubocop-sidekiq.rb +5 -0
  77. data/lib/rubocop-sidekiq_plus.rb +9 -0
  78. metadata +150 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: adda04ef399ed9f4d189a88e6567f674c507d90b1071f3a6769c2988e7c1ee53
4
+ data.tar.gz: 79a9151e9e78ac475fc64c385e7622af7971c4f5cf5da5fcb4ceaf79a2933e9a
5
+ SHA512:
6
+ metadata.gz: 14b73e098c02afe7c7560f483b57b4b95a5f5a88b7fd7e1d98c3409c8f86c3cf189f92dc579a9d12ea68db6ff9bb52907b998ec8f0a3c91711850a233520b23c
7
+ data.tar.gz: 15d1a0f565350f6096b571e8b7c29f73901e5c789526c46cbda9c245ffdf8a346802ddf4af4c2ebaa7b5a09ea3a04138b2539ed473c43133d4ca859fbbf2fec0
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Yudai Takada
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,322 @@
1
+ # RuboCop Sidekiq+
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/rubocop-sidekiq_plus.svg)](https://badge.fury.io/rb/rubocop-sidekiq_plus)
4
+ [![CI](https://github.com/ydah/rubocop-sidekiq/actions/workflows/main.yml/badge.svg)](https://github.com/ydah/rubocop-sidekiq/actions/workflows/main.yml)
5
+
6
+ A [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing [Sidekiq](https://github.com/sidekiq/sidekiq) best practices and coding conventions.
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'rubocop-sidekiq_plus', require: false
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ ```bash
19
+ bundle install
20
+ ```
21
+
22
+ ## Usage
23
+
24
+ Add the following to your `.rubocop.yml`:
25
+
26
+ ```yaml
27
+ plugins:
28
+ - rubocop-sidekiq
29
+ ```
30
+
31
+ ## Available Cops
32
+
33
+ ### Sidekiq/ActiveRecordArgument
34
+
35
+ Do not pass ActiveRecord objects to Sidekiq jobs. Pass the id and fetch the record in the job instead.
36
+
37
+ ### Sidekiq/FindEachInJob
38
+
39
+ Do not process large datasets within a single Sidekiq job. Split work into smaller jobs instead.
40
+
41
+ ### Sidekiq/ConsistentJobSuffix
42
+
43
+ Enforce consistent job class name suffix (Job or Worker).
44
+
45
+ ### Sidekiq/ConstantJobClassName
46
+
47
+ Use a constant class name for Sidekiq jobs. Dynamic job class names are harder to trace and may be insecure.
48
+
49
+ ### Sidekiq/DatabaseConnectionLeak
50
+
51
+ Avoid using `ActiveRecord::Base.connection` directly in jobs. Use `connection_pool.with_connection`.
52
+
53
+ ### Sidekiq/DateTimeArgument
54
+
55
+ Do not pass Date/Time objects to Sidekiq jobs. Convert to a string or timestamp first.
56
+
57
+ ### Sidekiq/DeprecatedDefaultWorkerOptions
58
+
59
+ Detect deprecated `Sidekiq.default_worker_options` usage. Use `Sidekiq.default_job_options` instead.
60
+
61
+ ### Sidekiq/DeprecatedDelayExtension
62
+
63
+ Avoid using the deprecated delay extension. Prefer `deliver_later` or enqueue a Sidekiq job.
64
+
65
+ ### Sidekiq/DeprecatedWorkerModule
66
+
67
+ Avoid `Sidekiq::Worker` and use `Sidekiq::Job` instead.
68
+
69
+ ### Sidekiq/ExcessiveRetry
70
+
71
+ Detect excessive retry counts in `sidekiq_options`.
72
+
73
+ ### Sidekiq/HugeJobArguments
74
+
75
+ Avoid passing large arguments to Sidekiq jobs. Pass IDs and load records in the job instead.
76
+
77
+ ### Sidekiq/EnqueueInefficiency
78
+
79
+ Avoid calling `perform_async` inside loops. Use `perform_bulk` instead.
80
+
81
+ ### Sidekiq/JobDependency
82
+
83
+ Avoid implicit job dependencies by enqueuing jobs from other jobs.
84
+
85
+ ### Sidekiq/JobFileLocation
86
+
87
+ Ensure job classes are located under `app/jobs` or `app/workers`.
88
+
89
+ ### Sidekiq/JobFileNaming
90
+
91
+ Ensure job file names match the class name.
92
+
93
+ ### Sidekiq/JobInclude
94
+
95
+ Prefer including `Sidekiq::Job` over `Sidekiq::Worker`. Configurable with `PreferredModule` option.
96
+
97
+ ### Sidekiq/MissingLogging
98
+
99
+ Encourage logging in job `perform` methods. Disabled by default.
100
+
101
+ ### Sidekiq/MissingTimeout
102
+
103
+ Ensure network calls in jobs have explicit timeouts configured.
104
+
105
+ ### Sidekiq/MixedRetryStrategies
106
+
107
+ Avoid mixing ActiveJob `retry_on` with Sidekiq retry options.
108
+
109
+ ### Sidekiq/NoRescueAll
110
+
111
+ Avoid rescuing all exceptions in Sidekiq jobs. Rescue specific exceptions and consider re-raising.
112
+
113
+ ### Sidekiq/AsyncInTest
114
+
115
+ Avoid `perform_async` in tests. Disabled by default.
116
+
117
+ ### Sidekiq/PerformInlineUsage
118
+
119
+ Avoid using `perform_inline` in production code. Use `perform_async` instead.
120
+
121
+ ### Sidekiq/PerformMethodParameters
122
+
123
+ Do not use keyword arguments in the `perform` method. Sidekiq cannot serialize keyword arguments to JSON.
124
+
125
+ ### Sidekiq/PiiInArguments
126
+
127
+ Avoid passing PII in job arguments. Disabled by default.
128
+
129
+ ### Sidekiq/SidekiqOverActiveJob
130
+
131
+ Prefer Sidekiq::Job over ActiveJob. Disabled by default.
132
+
133
+ ### Sidekiq/QueueSpecified
134
+
135
+ Require explicit queue specification for jobs. Disabled by default.
136
+
137
+ ### Sidekiq/RedisInJob
138
+
139
+ Use `Sidekiq.redis` instead of creating new Redis connections in jobs.
140
+
141
+ ### Sidekiq/RetryZero
142
+
143
+ Prefer `retry: false` over `retry: 0` for clarity. Disabled by default.
144
+
145
+ ### Sidekiq/RetrySpecified
146
+
147
+ Require explicit retry configuration for jobs. Disabled by default.
148
+
149
+ ### Sidekiq/SelfSchedulingJob
150
+
151
+ Avoid self-scheduling jobs. Disabled by default.
152
+
153
+ ### Sidekiq/SensitiveDataInArguments
154
+
155
+ Avoid passing sensitive data in job arguments.
156
+
157
+ ### Sidekiq/SilentRescue
158
+
159
+ Avoid silently swallowing exceptions in jobs.
160
+
161
+ ### Sidekiq/SleepInJobs
162
+
163
+ Do not use `sleep` in Sidekiq jobs. It blocks the worker thread.
164
+
165
+ ### Sidekiq/SymbolArgument
166
+
167
+ Do not pass symbols to Sidekiq jobs. Use strings instead.
168
+
169
+ ### Sidekiq/ThreadInJob
170
+
171
+ Do not create threads inside Sidekiq jobs. Use separate jobs or Sidekiq's built-in concurrency.
172
+
173
+ ### Sidekiq/TransactionLeak
174
+
175
+ Do not enqueue Sidekiq jobs inside database transactions. The job may run before the transaction commits.
176
+
177
+ ### Sidekiq/UnknownSidekiqOption
178
+
179
+ Detect unknown or unsupported keys in `sidekiq_options`.
180
+
181
+ ### Sidekiq/PutsOrPrintUsage
182
+
183
+ Use `logger` instead of `puts`/`print` in jobs.
184
+
185
+ ## Sidekiq Pro Cops
186
+
187
+ The following cops are available for [Sidekiq Pro](https://sidekiq.org/products/pro.html) users:
188
+
189
+ ### SidekiqPro/BatchCallbackMethod
190
+
191
+ Ensure batch callback methods are named correctly (`on_complete`, `on_success`, `on_death`).
192
+
193
+ ### SidekiqPro/BatchRetryInCallback
194
+
195
+ Check that jobs enqueued in batch callbacks have retry enabled for reliability.
196
+
197
+ ### SidekiqPro/BatchStatusPolling
198
+
199
+ Discourage polling batch status in loops. Use batch callbacks instead. Disabled by default.
200
+
201
+ ### SidekiqPro/BatchWithoutCallback
202
+
203
+ Recommend registering callbacks or descriptions for batches for tracking. Disabled by default.
204
+
205
+ ### SidekiqPro/EmptyBatch
206
+
207
+ Detect `batch.jobs` blocks that may be empty. Empty batches cause errors in Sidekiq Pro versions before 7.1.
208
+
209
+ ### SidekiqPro/ExpiringJobWithoutTTL
210
+
211
+ Validate TTL range for expiring jobs. Too short TTL may cause jobs to expire before processing. Disabled by default.
212
+
213
+ ### SidekiqPro/LargeArgumentInBatch
214
+
215
+ Avoid passing large arguments to jobs within a batch. This can exhaust Redis memory when many jobs are enqueued simultaneously.
216
+
217
+ ### SidekiqPro/NestedBatchWithoutParent
218
+
219
+ Ensure nested batches reference their parent batch for proper tracking.
220
+
221
+ ### SidekiqPro/ReliabilityNotEnabled
222
+
223
+ Recommend enabling `super_fetch!` and `reliable_push!` for production reliability. Disabled by default.
224
+
225
+ ## Sidekiq Enterprise Cops
226
+
227
+ The following cops are available for [Sidekiq Enterprise](https://sidekiq.org/products/enterprise.html) users:
228
+
229
+ ### SidekiqEnt/EncryptionWithManyArguments
230
+
231
+ Ensure sensitive data is consolidated in the last argument when using encryption. Sidekiq Enterprise only encrypts the last argument.
232
+
233
+ ### SidekiqEnt/EncryptionWithoutSecretBag
234
+
235
+ Recommend proper secret bag usage with encryption. Warns when encrypted jobs have only ID-like arguments. Disabled by default.
236
+
237
+ ### SidekiqEnt/LeaderElectionWithoutBlock
238
+
239
+ Warn about long-running operations in `Sidekiq.leader?` checks. Prefer delegating work to jobs. Disabled by default.
240
+
241
+ ### SidekiqEnt/LimiterNotReused
242
+
243
+ Create rate limiters as class constants for reuse. Creating limiters inside the `perform` method causes Redis memory leaks.
244
+
245
+ ### SidekiqEnt/LimiterWithoutLockTimeout
246
+
247
+ Recommend setting `lock_timeout` for concurrent limiters to match job execution time.
248
+
249
+ ### SidekiqEnt/LimiterWithoutWaitTimeout
250
+
251
+ Specify `wait_timeout` option for rate limiters to avoid blocking worker threads indefinitely.
252
+
253
+ ### SidekiqEnt/PeriodicJobInvalidCron
254
+
255
+ Validate cron expressions for periodic jobs.
256
+
257
+ ### SidekiqEnt/PeriodicJobWithArguments
258
+
259
+ Periodic jobs should not require arguments. Use optional arguments or the `args` option in periodic registration.
260
+
261
+ ### SidekiqEnt/UniqueJobTooShortTTL
262
+
263
+ Warn about unique jobs with too short TTL that may expire during retries.
264
+
265
+ ### SidekiqEnt/UniqueJobWithoutTTL
266
+
267
+ Require `unique_for` option when using `unique_until`. Without a TTL, uniqueness locks may persist indefinitely if jobs fail.
268
+
269
+ ### SidekiqEnt/UniqueUntilMismatch
270
+
271
+ Validate `unique_until` option values. Avoid `unique_until: :start` which may cause concurrent execution.
272
+
273
+ ## Configuration
274
+
275
+ All cops are enabled by default except for:
276
+ - `Sidekiq/QueueSpecified`
277
+ - `Sidekiq/RetrySpecified`
278
+ - `Sidekiq/ConsistentJobSuffix`
279
+ - `Sidekiq/ExcessiveRetry`
280
+ - `Sidekiq/JobDependency`
281
+ - `Sidekiq/JobFileLocation`
282
+ - `Sidekiq/JobFileNaming`
283
+ - `Sidekiq/MissingLogging`
284
+ - `Sidekiq/AsyncInTest`
285
+ - `Sidekiq/PiiInArguments`
286
+ - `Sidekiq/SidekiqOverActiveJob`
287
+ - `Sidekiq/RetryZero`
288
+ - `Sidekiq/SelfSchedulingJob`
289
+ - `SidekiqPro/BatchStatusPolling`
290
+ - `SidekiqPro/BatchWithoutCallback`
291
+ - `SidekiqPro/ExpiringJobWithoutTTL`
292
+ - `SidekiqPro/ReliabilityNotEnabled`
293
+ - `SidekiqEnt/EncryptionWithoutSecretBag`
294
+ - `SidekiqEnt/LeaderElectionWithoutBlock`
295
+
296
+ Example configuration:
297
+
298
+ ```yaml
299
+ Sidekiq/JobInclude:
300
+ PreferredModule: Job # or Worker
301
+
302
+ Sidekiq/PerformInlineUsage:
303
+ AllowedInTests: true
304
+
305
+ Sidekiq/QueueSpecified:
306
+ Enabled: true
307
+
308
+ Sidekiq/RetrySpecified:
309
+ Enabled: true
310
+ ```
311
+
312
+ ## Development
313
+
314
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
315
+
316
+ ## Contributing
317
+
318
+ Bug reports and pull requests are welcome on GitHub at https://github.com/ydah/rubocop-sidekiq_plus.
319
+
320
+ ## License
321
+
322
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).