rubocop-rails 2.11.2 → 2.19.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (142) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +23 -2
  4. data/config/default.yml +316 -20
  5. data/config/obsoletion.yml +10 -0
  6. data/lib/rubocop/cop/mixin/active_record_helper.rb +17 -8
  7. data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +32 -0
  8. data/lib/rubocop/cop/mixin/class_send_node_helper.rb +20 -0
  9. data/lib/rubocop/cop/mixin/enforce_superclass.rb +1 -1
  10. data/lib/rubocop/cop/mixin/index_method.rb +7 -17
  11. data/lib/rubocop/cop/mixin/migrations_helper.rb +26 -0
  12. data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +112 -0
  13. data/lib/rubocop/cop/rails/action_controller_test_case.rb +47 -0
  14. data/lib/rubocop/cop/rails/action_filter.rb +2 -2
  15. data/lib/rubocop/cop/rails/action_order.rb +116 -0
  16. data/lib/rubocop/cop/rails/active_record_aliases.rb +9 -6
  17. data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +8 -13
  18. data/lib/rubocop/cop/rails/active_record_override.rb +2 -5
  19. data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -1
  20. data/lib/rubocop/cop/rails/active_support_on_load.rb +70 -0
  21. data/lib/rubocop/cop/rails/add_column_index.rb +3 -6
  22. data/lib/rubocop/cop/rails/after_commit_override.rb +3 -13
  23. data/lib/rubocop/cop/rails/application_controller.rb +6 -2
  24. data/lib/rubocop/cop/rails/application_job.rb +7 -3
  25. data/lib/rubocop/cop/rails/application_mailer.rb +6 -2
  26. data/lib/rubocop/cop/rails/application_record.rb +7 -2
  27. data/lib/rubocop/cop/rails/arel_star.rb +8 -2
  28. data/lib/rubocop/cop/rails/assert_not.rb +1 -1
  29. data/lib/rubocop/cop/rails/attribute_default_block_value.rb +1 -1
  30. data/lib/rubocop/cop/rails/belongs_to.rb +2 -5
  31. data/lib/rubocop/cop/rails/blank.rb +13 -13
  32. data/lib/rubocop/cop/rails/bulk_change_table.rb +28 -31
  33. data/lib/rubocop/cop/rails/compact_blank.rb +111 -0
  34. data/lib/rubocop/cop/rails/content_tag.rb +42 -33
  35. data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +16 -8
  36. data/lib/rubocop/cop/rails/date.rb +12 -17
  37. data/lib/rubocop/cop/rails/default_scope.rb +1 -1
  38. data/lib/rubocop/cop/rails/delegate.rb +24 -18
  39. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +2 -2
  40. data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +168 -0
  41. data/lib/rubocop/cop/rails/dot_separated_keys.rb +71 -0
  42. data/lib/rubocop/cop/rails/duplicate_association.rb +56 -0
  43. data/lib/rubocop/cop/rails/duplicate_scope.rb +46 -0
  44. data/lib/rubocop/cop/rails/duration_arithmetic.rb +98 -0
  45. data/lib/rubocop/cop/rails/dynamic_find_by.rb +31 -15
  46. data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +6 -2
  47. data/lib/rubocop/cop/rails/enum_hash.rb +3 -4
  48. data/lib/rubocop/cop/rails/enum_uniqueness.rb +3 -6
  49. data/lib/rubocop/cop/rails/environment_comparison.rb +3 -4
  50. data/lib/rubocop/cop/rails/environment_variable_access.rb +1 -1
  51. data/lib/rubocop/cop/rails/exit.rb +1 -1
  52. data/lib/rubocop/cop/rails/expanded_date_range.rb +39 -23
  53. data/lib/rubocop/cop/rails/file_path.rb +41 -24
  54. data/lib/rubocop/cop/rails/find_by.rb +1 -1
  55. data/lib/rubocop/cop/rails/find_by_id.rb +3 -3
  56. data/lib/rubocop/cop/rails/find_each.rb +27 -4
  57. data/lib/rubocop/cop/rails/freeze_time.rb +79 -0
  58. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
  59. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +19 -9
  60. data/lib/rubocop/cop/rails/helper_instance_variable.rb +3 -3
  61. data/lib/rubocop/cop/rails/http_positional_arguments.rb +29 -11
  62. data/lib/rubocop/cop/rails/http_status.rb +6 -11
  63. data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +96 -0
  64. data/lib/rubocop/cop/rails/i18n_locale_assignment.rb +1 -1
  65. data/lib/rubocop/cop/rails/i18n_locale_texts.rb +110 -0
  66. data/lib/rubocop/cop/rails/ignored_columns_assignment.rb +50 -0
  67. data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +5 -14
  68. data/lib/rubocop/cop/rails/index_by.rb +8 -8
  69. data/lib/rubocop/cop/rails/index_with.rb +8 -8
  70. data/lib/rubocop/cop/rails/inquiry.rb +1 -1
  71. data/lib/rubocop/cop/rails/inverse_of.rb +20 -10
  72. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +44 -16
  73. data/lib/rubocop/cop/rails/link_to_blank.rb +4 -7
  74. data/lib/rubocop/cop/rails/mailer_name.rb +9 -5
  75. data/lib/rubocop/cop/rails/match_route.rb +1 -1
  76. data/lib/rubocop/cop/rails/migration_class_name.rb +63 -0
  77. data/lib/rubocop/cop/rails/negate_include.rb +5 -4
  78. data/lib/rubocop/cop/rails/not_null_column.rb +10 -7
  79. data/lib/rubocop/cop/rails/order_by_id.rb +2 -3
  80. data/lib/rubocop/cop/rails/output.rb +26 -10
  81. data/lib/rubocop/cop/rails/output_safety.rb +6 -2
  82. data/lib/rubocop/cop/rails/pick.rb +8 -1
  83. data/lib/rubocop/cop/rails/pluck.rb +51 -11
  84. data/lib/rubocop/cop/rails/pluck_id.rb +5 -2
  85. data/lib/rubocop/cop/rails/pluck_in_where.rb +8 -7
  86. data/lib/rubocop/cop/rails/pluralization_grammar.rb +4 -5
  87. data/lib/rubocop/cop/rails/presence.rb +22 -13
  88. data/lib/rubocop/cop/rails/present.rb +10 -13
  89. data/lib/rubocop/cop/rails/rake_environment.rb +8 -3
  90. data/lib/rubocop/cop/rails/read_write_attribute.rb +52 -15
  91. data/lib/rubocop/cop/rails/redundant_allow_nil.rb +7 -17
  92. data/lib/rubocop/cop/rails/redundant_foreign_key.rb +3 -3
  93. data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +257 -0
  94. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +31 -27
  95. data/lib/rubocop/cop/rails/redundant_travel_back.rb +57 -0
  96. data/lib/rubocop/cop/rails/reflection_class_name.rb +39 -4
  97. data/lib/rubocop/cop/rails/refute_methods.rb +1 -5
  98. data/lib/rubocop/cop/rails/relative_date_constant.rb +9 -9
  99. data/lib/rubocop/cop/rails/render_inline.rb +1 -1
  100. data/lib/rubocop/cop/rails/render_plain_text.rb +1 -1
  101. data/lib/rubocop/cop/rails/request_referer.rb +2 -3
  102. data/lib/rubocop/cop/rails/require_dependency.rb +2 -2
  103. data/lib/rubocop/cop/rails/response_parsed_body.rb +57 -0
  104. data/lib/rubocop/cop/rails/reversible_migration.rb +29 -67
  105. data/lib/rubocop/cop/rails/reversible_migration_method_definition.rb +6 -15
  106. data/lib/rubocop/cop/rails/root_join_chain.rb +72 -0
  107. data/lib/rubocop/cop/rails/root_pathname_methods.rb +238 -0
  108. data/lib/rubocop/cop/rails/root_public_path.rb +59 -0
  109. data/lib/rubocop/cop/rails/safe_navigation.rb +8 -13
  110. data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +14 -7
  111. data/lib/rubocop/cop/rails/save_bang.rb +30 -23
  112. data/lib/rubocop/cop/rails/schema_comment.rb +104 -0
  113. data/lib/rubocop/cop/rails/scope_args.rb +6 -2
  114. data/lib/rubocop/cop/rails/short_i18n.rb +3 -6
  115. data/lib/rubocop/cop/rails/skips_model_validations.rb +3 -4
  116. data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +13 -8
  117. data/lib/rubocop/cop/rails/strip_heredoc.rb +56 -0
  118. data/lib/rubocop/cop/rails/table_name_assignment.rb +44 -0
  119. data/lib/rubocop/cop/rails/three_state_boolean_column.rb +73 -0
  120. data/lib/rubocop/cop/rails/time_zone.rb +37 -32
  121. data/lib/rubocop/cop/rails/time_zone_assignment.rb +4 -4
  122. data/lib/rubocop/cop/rails/to_formatted_s.rb +46 -0
  123. data/lib/rubocop/cop/rails/to_s_with_argument.rb +78 -0
  124. data/lib/rubocop/cop/rails/top_level_hash_with_indifferent_access.rb +49 -0
  125. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +99 -0
  126. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +32 -41
  127. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +16 -9
  128. data/lib/rubocop/cop/rails/unknown_env.rb +3 -5
  129. data/lib/rubocop/cop/rails/unused_ignored_columns.rb +9 -2
  130. data/lib/rubocop/cop/rails/validation.rb +5 -13
  131. data/lib/rubocop/cop/rails/where_equals.rb +6 -2
  132. data/lib/rubocop/cop/rails/where_exists.rb +11 -10
  133. data/lib/rubocop/cop/rails/where_missing.rb +118 -0
  134. data/lib/rubocop/cop/rails/where_not.rb +2 -2
  135. data/lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb +55 -0
  136. data/lib/rubocop/cop/rails_cops.rb +34 -0
  137. data/lib/rubocop/rails/schema_loader/schema.rb +8 -5
  138. data/lib/rubocop/rails/version.rb +1 -1
  139. data/lib/rubocop/rails.rb +1 -1
  140. data/lib/rubocop-rails.rb +19 -0
  141. metadata +42 -8
  142. data/bin/setup +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70f7044795da60c3d19962181ad6e9bc1914c1ae9c46f5072f4c2bc9c6115add
4
- data.tar.gz: d1130053b86d468d25b114694dca3d56eea533aafdbff9ff8dc33f3fdc306fbb
3
+ metadata.gz: b020fcc0db6203c33dfe23032cc2c6ec0df139e6abb048409bdf7439ea2d4183
4
+ data.tar.gz: fc6e892161124d21b9067e01e6b86178857df27d14ae687f3f0fdcceb2b3d078
5
5
  SHA512:
6
- metadata.gz: 49d18f985b54c2a8beefe8f00ad758b2cabed80d463315e10c994eeb348af4f1e6db1f53ac7a73434105d210db831b98ddb8f5ae44e849346888ff427c4eabcc
7
- data.tar.gz: 291ad9f2cafe1c8ce146bf9e311e5bf84c667e087596050076d9fa560ef0612c41a425beb8d314386f98e4f2eeb4f31bdb50f134eebad52b44efca82ea4299ba
6
+ metadata.gz: f09636066a282111462ab5cc3b93463ec0cd8a111e2882b6e7c21889da3b36958766f722926418439e48933d8791ce41c0edadc3e4a590c5f8caeb82f35ad5b1
7
+ data.tar.gz: 40586400ad94701ee39ee71ab7280f7328889245f4786503cf5a851d158a05e4f736eea42c53f61164a420af8fab7e19854c6302237115a29efd3bdd1f19cc68
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-21 Bozhidar Batsov
1
+ Copyright (c) 2012-23 Bozhidar Batsov
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -12,7 +12,7 @@ Note: This repository manages rubocop-rails gem (>= 2.0.0). rubocop-rails gem (<
12
12
  Just install the `rubocop-rails` gem
13
13
 
14
14
  ```sh
15
- gem install rubocop-rails
15
+ $ gem install rubocop-rails
16
16
  ```
17
17
 
18
18
  or if you use bundler put this in your `Gemfile`
@@ -48,7 +48,7 @@ cops together with the standard cops.
48
48
  ### Command line
49
49
 
50
50
  ```sh
51
- rubocop --require rubocop-rails
51
+ $ rubocop --require rubocop-rails
52
52
  ```
53
53
 
54
54
  Note: `--rails` option is required while `rubocop` command supports `--rails` option.
@@ -61,6 +61,27 @@ RuboCop::RakeTask.new do |task|
61
61
  end
62
62
  ```
63
63
 
64
+ ## Rails configuration tip
65
+
66
+ If you are using Rails 6.1 or newer, add the following `config.generators.after_generate` setting to
67
+ your config/application.rb to apply RuboCop autocorrection to code generated by `bin/rails g`.
68
+
69
+ ```ruby
70
+ # config/application.rb
71
+ module YourCoolApp
72
+ class Application < Rails::Application
73
+ config.generators.after_generate do |files|
74
+ parsable_files = files.filter { |file| file.end_with?('.rb') }
75
+ system("bundle exec rubocop -A --fail-level=E #{parsable_files.shelljoin}", exception: true)
76
+ end
77
+ end
78
+ end
79
+ ```
80
+
81
+ It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsafe autocorretion cops.
82
+ `rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
83
+ be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
84
+
64
85
  ## The Cops
65
86
 
66
87
  All cops are located under
data/config/default.yml CHANGED
@@ -7,9 +7,17 @@ inherit_mode:
7
7
  AllCops:
8
8
  Exclude:
9
9
  - bin/*
10
- - db/schema.rb
10
+ # Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
11
+ # See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
12
+ - db/*schema.rb
13
+ - log/**/*
14
+ - public/**/*
15
+ - storage/**/*
16
+ # Enable checking Active Support extensions.
17
+ # See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
18
+ ActiveSupportExtensionsEnabled: true
11
19
  # What version of Rails is the inspected code using? If a value is specified
12
- # for TargetRailsVersion then it is used. Acceptable values are specificed
20
+ # for TargetRailsVersion then it is used. Acceptable values are specified
13
21
  # as a float (i.e. 5.1); the patch version of Rails should not be included.
14
22
  # If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
15
23
  # gems.locked file to find the version of Rails that has been bound to the
@@ -21,7 +29,7 @@ Lint/NumberConversion:
21
29
  # Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
22
30
  # so that calling `to_i` on one of these does not register an offense.
23
31
  # See: https://github.com/rubocop/rubocop/issues/8950
24
- IgnoredMethods:
32
+ AllowedMethods:
25
33
  - ago
26
34
  - from_now
27
35
  - second
@@ -37,6 +45,27 @@ Lint/NumberConversion:
37
45
  - fortnight
38
46
  - fortnights
39
47
  - in_milliseconds
48
+ AllowedPatterns: []
49
+
50
+ Rails:
51
+ Enabled: true
52
+ DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
53
+
54
+ Rails/ActionControllerFlashBeforeRender:
55
+ Description: 'Use `flash.now` instead of `flash` before `render`.'
56
+ Enabled: 'pending'
57
+ SafeAutoCorrect: false
58
+ VersionAdded: '2.16'
59
+
60
+ Rails/ActionControllerTestCase:
61
+ Description: 'Use `ActionDispatch::IntegrationTest` instead of `ActionController::TestCase`.'
62
+ StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
63
+ Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
64
+ Enabled: 'pending'
65
+ SafeAutoCorrect: false
66
+ VersionAdded: '2.14'
67
+ Include:
68
+ - '**/test/**/*.rb'
40
69
 
41
70
  Rails/ActionFilter:
42
71
  Description: 'Enforces consistent use of action filter methods.'
@@ -48,6 +77,22 @@ Rails/ActionFilter:
48
77
  - filter
49
78
  Include:
50
79
  - app/controllers/**/*.rb
80
+ - app/mailers/**/*.rb
81
+
82
+ Rails/ActionOrder:
83
+ Description: 'Enforce consistent ordering of controller actions.'
84
+ Enabled: pending
85
+ VersionAdded: '2.17'
86
+ ExpectedOrder:
87
+ - index
88
+ - show
89
+ - new
90
+ - edit
91
+ - create
92
+ - update
93
+ - destroy
94
+ Include:
95
+ - app/controllers/**/*.rb
51
96
 
52
97
  Rails/ActiveRecordAliases:
53
98
  Description: >-
@@ -71,7 +116,9 @@ Rails/ActiveRecordOverride:
71
116
  Check for overriding Active Record methods instead of using
72
117
  callbacks.
73
118
  Enabled: true
119
+ Severity: warning
74
120
  VersionAdded: '0.67'
121
+ VersionChanged: '2.18'
75
122
  Include:
76
123
  - app/models/**/*.rb
77
124
 
@@ -83,6 +130,15 @@ Rails/ActiveSupportAliases:
83
130
  Enabled: true
84
131
  VersionAdded: '0.48'
85
132
 
133
+ Rails/ActiveSupportOnLoad:
134
+ Description: 'Use `ActiveSupport.on_load(...)` to patch Rails framework classes.'
135
+ Enabled: 'pending'
136
+ Reference:
137
+ - 'https://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html'
138
+ - 'https://guides.rubyonrails.org/engines.html#available-load-hooks'
139
+ SafeAutoCorrect: false
140
+ VersionAdded: '2.16'
141
+
86
142
  Rails/AddColumnIndex:
87
143
  Description: >-
88
144
  Rails migrations don't make use of a given `index` key, but also
@@ -95,7 +151,7 @@ Rails/AddColumnIndex:
95
151
 
96
152
  Rails/AfterCommitOverride:
97
153
  Description: >-
98
- This cop enforces that there is only one call to `after_commit`
154
+ Enforces that there is only one call to `after_commit`
99
155
  (and its aliases - `after_create_commit`, `after_update_commit`,
100
156
  and `after_destroy_commit`) with the same callback name per model.
101
157
  Enabled: 'pending'
@@ -147,12 +203,15 @@ Rails/AttributeDefaultBlockValue:
147
203
  Enabled: pending
148
204
  VersionAdded: '2.9'
149
205
  Include:
150
- - 'models/**/*'
206
+ - 'app/models/**/*'
151
207
 
152
208
  Rails/BelongsTo:
153
209
  Description: >-
154
210
  Use `optional: true` instead of `required: false` for
155
211
  `belongs_to` relations.
212
+ Reference:
213
+ - https://guides.rubyonrails.org/5_0_release_notes.html
214
+ - https://github.com/rails/rails/pull/18937
156
215
  Enabled: true
157
216
  VersionAdded: '0.62'
158
217
 
@@ -171,6 +230,9 @@ Rails/Blank:
171
230
 
172
231
  Rails/BulkChangeTable:
173
232
  Description: 'Check whether alter queries are combinable.'
233
+ Reference:
234
+ - https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-change_table
235
+ - https://api.rubyonrails.org/classes/ActiveRecord/ConnectionAdapters/Table.html
174
236
  Enabled: true
175
237
  VersionAdded: '0.57'
176
238
  Database: null
@@ -180,13 +242,27 @@ Rails/BulkChangeTable:
180
242
  Include:
181
243
  - db/migrate/*.rb
182
244
 
245
+ Rails/CompactBlank:
246
+ Description: 'Checks if collection can be blank-compacted with `compact_blank`.'
247
+ Enabled: pending
248
+ Safe: false
249
+ VersionAdded: '2.13'
250
+
183
251
  Rails/ContentTag:
184
- Description: 'Use `tag` instead of `content_tag`.'
252
+ Description: 'Use `tag.something` instead of `tag(:something)`.'
185
253
  Reference:
254
+ - 'https://github.com/rubocop/rubocop-rails/issues/260'
186
255
  - 'https://github.com/rails/rails/issues/25195'
187
256
  - 'https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag'
188
257
  Enabled: true
189
258
  VersionAdded: '2.6'
259
+ VersionChanged: '2.12'
260
+ # This `Exclude` config prevents false positives for `tag` calls to `has_one: tag` and Puma configuration:
261
+ # https://puma.io/puma/Puma/DSL.html#tag-instance_method
262
+ # No helpers are used in normal models and configs.
263
+ Exclude:
264
+ - app/models/**/*.rb
265
+ - config/**/*.rb
190
266
 
191
267
  Rails/CreateTableWithTimestamps:
192
268
  Description: >-
@@ -196,6 +272,10 @@ Rails/CreateTableWithTimestamps:
196
272
  VersionAdded: '0.52'
197
273
  Include:
198
274
  - db/migrate/*.rb
275
+ Exclude:
276
+ # Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb`
277
+ # auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified.
278
+ - db/migrate/*_create_active_storage_tables.active_storage.rb
199
279
 
200
280
  Rails/Date:
201
281
  Description: >-
@@ -236,6 +316,40 @@ Rails/DelegateAllowBlank:
236
316
  Enabled: true
237
317
  VersionAdded: '0.44'
238
318
 
319
+ Rails/DeprecatedActiveModelErrorsMethods:
320
+ Description: 'Avoid manipulating ActiveModel errors hash directly.'
321
+ Enabled: pending
322
+ Severity: warning
323
+ Safe: false
324
+ VersionAdded: '2.14'
325
+ VersionChanged: '2.18'
326
+
327
+ Rails/DotSeparatedKeys:
328
+ Description: 'Enforces the use of dot-separated keys instead of `:scope` options in `I18n` translation methods.'
329
+ StyleGuide: 'https://rails.rubystyle.guide/#dot-separated-keys'
330
+ Enabled: pending
331
+ VersionAdded: '2.15'
332
+
333
+ Rails/DuplicateAssociation:
334
+ Description: "Don't repeat associations in a model."
335
+ Enabled: pending
336
+ Severity: warning
337
+ VersionAdded: '2.14'
338
+ VersionChanged: '2.18'
339
+
340
+ Rails/DuplicateScope:
341
+ Description: 'Multiple scopes share this same where clause.'
342
+ Enabled: pending
343
+ Severity: warning
344
+ VersionAdded: '2.14'
345
+ VersionChanged: '2.18'
346
+
347
+ Rails/DurationArithmetic:
348
+ Description: 'Do not use duration as arithmetic operand with `Time.current`.'
349
+ StyleGuide: 'https://rails.rubystyle.guide#duration-arithmetic'
350
+ Enabled: pending
351
+ VersionAdded: '2.13'
352
+
239
353
  Rails/DynamicFindBy:
240
354
  Description: 'Use `find_by` instead of dynamic `find_by_*`.'
241
355
  StyleGuide: 'https://rails.rubystyle.guide#find_by'
@@ -246,10 +360,13 @@ Rails/DynamicFindBy:
246
360
  # The `Whitelist` has been deprecated, Please use `AllowedMethods` instead.
247
361
  Whitelist:
248
362
  - find_by_sql
363
+ - find_by_token_for
249
364
  AllowedMethods:
250
365
  - find_by_sql
366
+ - find_by_token_for
251
367
  AllowedReceivers:
252
368
  - Gem::Specification
369
+ - page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
253
370
 
254
371
  Rails/EagerEvaluationLogMessage:
255
372
  Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'
@@ -307,6 +424,7 @@ Rails/Exit:
307
424
 
308
425
  Rails/ExpandedDateRange:
309
426
  Description: 'Checks for expanded date range.'
427
+ StyleGuide: 'https://rails.rubystyle.guide/#date-time-range'
310
428
  Enabled: pending
311
429
  VersionAdded: '2.11'
312
430
 
@@ -339,19 +457,28 @@ Rails/FindById:
339
457
  VersionAdded: '2.7'
340
458
 
341
459
  Rails/FindEach:
342
- Description: 'Prefer all.find_each over all.find.'
460
+ Description: 'Prefer all.find_each over all.each.'
343
461
  StyleGuide: 'https://rails.rubystyle.guide#find-each'
344
462
  Enabled: true
463
+ Safe: false
345
464
  VersionAdded: '0.30'
346
- VersionChanged: '2.9'
465
+ VersionChanged: '2.19'
347
466
  Include:
348
467
  - app/models/**/*.rb
349
- IgnoredMethods:
468
+ AllowedMethods:
350
469
  # Methods that don't work well with `find_each`.
351
470
  - order
352
471
  - limit
353
472
  - select
354
473
  - lock
474
+ AllowedPatterns: []
475
+
476
+ Rails/FreezeTime:
477
+ Description: 'Prefer `freeze_time` over `travel_to` with an argument of the current time.'
478
+ StyleGuide: 'https://rails.rubystyle.guide/#freeze-time'
479
+ Enabled: pending
480
+ VersionAdded: '2.16'
481
+ SafeAutoCorrect: false
355
482
 
356
483
  Rails/HasAndBelongsToMany:
357
484
  Description: 'Prefer has_many :through to has_and_belongs_to_many.'
@@ -394,6 +521,15 @@ Rails/HttpStatus:
394
521
  - numeric
395
522
  - symbolic
396
523
 
524
+ Rails/I18nLazyLookup:
525
+ Description: 'Checks for places where I18n "lazy" lookup can be used.'
526
+ StyleGuide: 'https://rails.rubystyle.guide/#lazy-lookup'
527
+ Reference: 'https://guides.rubyonrails.org/i18n.html#lazy-lookup'
528
+ Enabled: pending
529
+ VersionAdded: '2.14'
530
+ Include:
531
+ - 'app/controllers/**/*.rb'
532
+
397
533
  Rails/I18nLocaleAssignment:
398
534
  Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
399
535
  Enabled: 'pending'
@@ -402,6 +538,19 @@ Rails/I18nLocaleAssignment:
402
538
  - spec/**/*.rb
403
539
  - test/**/*.rb
404
540
 
541
+ Rails/I18nLocaleTexts:
542
+ Description: 'Enforces use of I18n and locale files instead of locale specific strings.'
543
+ StyleGuide: 'https://rails.rubystyle.guide/#locale-texts'
544
+ Enabled: pending
545
+ VersionAdded: '2.14'
546
+
547
+ Rails/IgnoredColumnsAssignment:
548
+ Description: 'Looks for assignments of `ignored_columns` that override previous assignments.'
549
+ StyleGuide: 'https://rails.rubystyle.guide/#append-ignored-columns'
550
+ Enabled: pending
551
+ SafeAutoCorrect: false
552
+ VersionAdded: '2.17'
553
+
405
554
  Rails/IgnoredSkipActionFilterOption:
406
555
  Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.'
407
556
  Reference: 'https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options'
@@ -409,6 +558,7 @@ Rails/IgnoredSkipActionFilterOption:
409
558
  VersionAdded: '0.63'
410
559
  Include:
411
560
  - app/controllers/**/*.rb
561
+ - app/mailers/**/*.rb
412
562
 
413
563
  Rails/IndexBy:
414
564
  Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
@@ -430,19 +580,24 @@ Rails/Inquiry:
430
580
 
431
581
  Rails/InverseOf:
432
582
  Description: 'Checks for associations where the inverse cannot be determined automatically.'
583
+ Reference:
584
+ - https://guides.rubyonrails.org/association_basics.html#bi-directional-associations
585
+ - https://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#module-ActiveRecord::Associations::ClassMethods-label-Setting+Inverses
433
586
  Enabled: true
434
587
  VersionAdded: '0.52'
588
+ IgnoreScopes: false
435
589
  Include:
436
590
  - app/models/**/*.rb
437
591
 
438
592
  Rails/LexicallyScopedActionFilter:
439
- Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the controller."
593
+ Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
440
594
  StyleGuide: 'https://rails.rubystyle.guide#lexically-scoped-action-filter'
441
595
  Enabled: true
442
596
  Safe: false
443
597
  VersionAdded: '0.52'
444
598
  Include:
445
599
  - app/controllers/**/*.rb
600
+ - app/mailers/**/*.rb
446
601
 
447
602
  Rails/LinkToBlank:
448
603
  Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
@@ -473,6 +628,13 @@ Rails/MatchRoute:
473
628
  - config/routes.rb
474
629
  - config/routes/**/*.rb
475
630
 
631
+ Rails/MigrationClassName:
632
+ Description: 'The class name of the migration should match its file name.'
633
+ Enabled: pending
634
+ VersionAdded: '2.14'
635
+ Include:
636
+ - db/migrate/*.rb
637
+
476
638
  Rails/NegateInclude:
477
639
  Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
478
640
  StyleGuide: 'https://rails.rubystyle.guide#exclude'
@@ -499,6 +661,7 @@ Rails/OrderById:
499
661
  Rails/Output:
500
662
  Description: 'Checks for calls to puts, print, etc.'
501
663
  Enabled: true
664
+ SafeAutoCorrect: false
502
665
  VersionAdded: '0.15'
503
666
  VersionChanged: '0.19'
504
667
  Include:
@@ -523,7 +686,9 @@ Rails/Pluck:
523
686
  Description: 'Prefer `pluck` over `map { ... }`.'
524
687
  StyleGuide: 'https://rails.rubystyle.guide#pluck'
525
688
  Enabled: 'pending'
689
+ Safe: false
526
690
  VersionAdded: '2.7'
691
+ VersionChanged: '2.18'
527
692
 
528
693
  Rails/PluckId:
529
694
  Description: 'Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.'
@@ -602,11 +767,25 @@ Rails/RedundantForeignKey:
602
767
  Enabled: true
603
768
  VersionAdded: '2.6'
604
769
 
770
+ Rails/RedundantPresenceValidationOnBelongsTo:
771
+ Description: 'Checks for redundant presence validation on belongs_to association.'
772
+ Enabled: pending
773
+ SafeAutoCorrect: false
774
+ VersionAdded: '2.13'
775
+
605
776
  Rails/RedundantReceiverInWithOptions:
606
777
  Description: 'Checks for redundant receiver in `with_options`.'
607
778
  Enabled: true
608
779
  VersionAdded: '0.52'
609
780
 
781
+ Rails/RedundantTravelBack:
782
+ Description: Checks for redundant `travel_back` calls.
783
+ Enabled: pending
784
+ VersionAdded: '2.12'
785
+ Include:
786
+ - spec/**/*.rb
787
+ - test/**/*.rb
788
+
610
789
  Rails/ReflectionClassName:
611
790
  Description: 'Use a string for `class_name` option value in the definition of a reflection.'
612
791
  Enabled: true
@@ -628,9 +807,9 @@ Rails/RefuteMethods:
628
807
  Rails/RelativeDateConstant:
629
808
  Description: 'Do not assign relative date to constants.'
630
809
  Enabled: true
810
+ SafeAutoCorrect: false
631
811
  VersionAdded: '0.48'
632
- VersionChanged: '0.59'
633
- AutoCorrect: false
812
+ VersionChanged: '2.13'
634
813
 
635
814
  Rails/RenderInline:
636
815
  Description: 'Prefer using a template over inline rendering.'
@@ -661,21 +840,51 @@ Rails/RequireDependency:
661
840
  Enabled: false
662
841
  VersionAdded: '2.10'
663
842
 
843
+ Rails/ResponseParsedBody:
844
+ Description: Prefer `response.parsed_body` to `JSON.parse(response.body)`.
845
+ Enabled: pending
846
+ Safe: false
847
+ VersionAdded: '2.18'
848
+ VersionChanged: '2.19'
849
+ Include:
850
+ - spec/controllers/**/*.rb
851
+ - spec/requests/**/*.rb
852
+ - test/controllers/**/*.rb
853
+ - test/integration/**/*.rb
854
+
664
855
  Rails/ReversibleMigration:
665
856
  Description: 'Checks whether the change method of the migration file is reversible.'
666
857
  StyleGuide: 'https://rails.rubystyle.guide#reversible-migration'
667
858
  Reference: 'https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html'
668
859
  Enabled: true
669
860
  VersionAdded: '0.47'
861
+ VersionChanged: '2.13'
670
862
  Include:
671
- - db/migrate/*.rb
863
+ - db/**/*.rb
672
864
 
673
865
  Rails/ReversibleMigrationMethodDefinition:
674
866
  Description: 'Checks whether the migration implements either a `change` method or both an `up` and a `down` method.'
675
867
  Enabled: false
676
868
  VersionAdded: '2.10'
869
+ VersionChanged: '2.13'
677
870
  Include:
678
- - db/migrate/*.rb
871
+ - db/**/*.rb
872
+
873
+ Rails/RootJoinChain:
874
+ Description: 'Use a single `#join` instead of chaining on `Rails.root` or `Rails.public_path`.'
875
+ Enabled: pending
876
+ VersionAdded: '2.13'
877
+
878
+ Rails/RootPathnameMethods:
879
+ Description: 'Use `Rails.root` IO methods instead of passing it to `File`.'
880
+ Enabled: pending
881
+ SafeAutoCorrect: false
882
+ VersionAdded: '2.16'
883
+
884
+ Rails/RootPublicPath:
885
+ Description: "Favor `Rails.public_path` over `Rails.root` with `'public'`."
886
+ Enabled: pending
887
+ VersionAdded: '2.15'
679
888
 
680
889
  Rails/SafeNavigation:
681
890
  Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`."
@@ -709,10 +918,18 @@ Rails/SaveBang:
709
918
  AllowedReceivers: []
710
919
  SafeAutoCorrect: false
711
920
 
921
+ Rails/SchemaComment:
922
+ Description: >-
923
+ Enforces the use of the `comment` option when adding a new table or column
924
+ to the database during a migration.
925
+ Enabled: false
926
+ VersionAdded: '2.13'
927
+
712
928
  Rails/ScopeArgs:
713
929
  Description: 'Checks the arguments of ActiveRecord scopes.'
714
930
  Enabled: true
715
931
  VersionAdded: '0.19'
932
+ VersionChanged: '2.12'
716
933
  Include:
717
934
  - app/models/**/*.rb
718
935
 
@@ -762,17 +979,40 @@ Rails/SquishedSQLHeredocs:
762
979
  VersionAdded: '2.8'
763
980
  VersionChanged: '2.9'
764
981
  # Some SQL syntax (e.g. PostgreSQL comments and functions) requires newlines
765
- # to be preserved in order to work, thus auto-correction is not safe.
982
+ # to be preserved in order to work, thus autocorrection is not safe.
766
983
  SafeAutoCorrect: false
767
984
 
985
+ Rails/StripHeredoc:
986
+ Description: 'Enforces the use of squiggly heredoc over `strip_heredoc`.'
987
+ StyleGuide: 'https://rails.rubystyle.guide/#prefer-squiggly-heredoc'
988
+ Enabled: pending
989
+ VersionAdded: '2.15'
990
+
991
+ Rails/TableNameAssignment:
992
+ Description: >-
993
+ Do not use `self.table_name =`. Use Inflections or `table_name_prefix` instead.
994
+ StyleGuide: 'https://rails.rubystyle.guide/#keep-ar-defaults'
995
+ Enabled: false
996
+ VersionAdded: '2.14'
997
+ Include:
998
+ - app/models/**/*.rb
999
+
1000
+ Rails/ThreeStateBooleanColumn:
1001
+ Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
1002
+ StyleGuide: 'https://rails.rubystyle.guide/#three-state-boolean'
1003
+ Enabled: pending
1004
+ VersionAdded: '2.19'
1005
+ Include:
1006
+ - db/**/*.rb
1007
+
768
1008
  Rails/TimeZone:
769
1009
  Description: 'Checks the correct usage of time zone aware methods.'
770
1010
  StyleGuide: 'https://rails.rubystyle.guide#time'
771
1011
  Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
772
1012
  Enabled: true
773
- Safe: false
1013
+ SafeAutoCorrect: false
774
1014
  VersionAdded: '0.30'
775
- VersionChanged: '2.10'
1015
+ VersionChanged: '2.13'
776
1016
  # The value `strict` means that `Time` should be used with `zone`.
777
1017
  # The value `flexible` allows usage of `in_time_zone` instead of `zone`.
778
1018
  EnforcedStyle: flexible
@@ -791,20 +1031,50 @@ Rails/TimeZoneAssignment:
791
1031
  - spec/**/*.rb
792
1032
  - test/**/*.rb
793
1033
 
1034
+ Rails/ToFormattedS:
1035
+ Description: 'Checks for consistent uses of `to_fs` or `to_formatted_s`.'
1036
+ StyleGuide: 'https://rails.rubystyle.guide/#prefer-to-fs'
1037
+ Enabled: pending
1038
+ EnforcedStyle: to_fs
1039
+ SupportedStyles:
1040
+ - to_fs
1041
+ - to_formatted_s
1042
+ VersionAdded: '2.15'
1043
+
1044
+ Rails/ToSWithArgument:
1045
+ Description: 'Identifies passing any argument to `#to_s`.'
1046
+ Enabled: pending
1047
+ Safe: false
1048
+ VersionAdded: '2.16'
1049
+
1050
+ Rails/TopLevelHashWithIndifferentAccess:
1051
+ Description: 'Identifies top-level `HashWithIndifferentAccess`.'
1052
+ Reference: 'https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#top-level-hashwithindifferentaccess-is-soft-deprecated'
1053
+ Enabled: pending
1054
+ Severity: warning
1055
+ VersionAdded: '2.16'
1056
+ VersionChanged: '2.18'
1057
+
1058
+ Rails/TransactionExitStatement:
1059
+ Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.'
1060
+ Reference:
1061
+ - https://github.com/rails/rails/commit/15aa4200e083
1062
+ Enabled: pending
1063
+ VersionAdded: '2.14'
1064
+
794
1065
  Rails/UniqBeforePluck:
795
1066
  Description: 'Prefer the use of uniq or distinct before pluck.'
796
1067
  Enabled: true
797
1068
  VersionAdded: '0.40'
798
- VersionChanged: '2.8'
1069
+ VersionChanged: '2.13'
799
1070
  EnforcedStyle: conservative
800
1071
  SupportedStyles:
801
1072
  - conservative
802
1073
  - aggressive
803
1074
  SafeAutoCorrect: false
804
- AutoCorrect: false
805
1075
 
806
1076
  Rails/UniqueValidationWithoutIndex:
807
- Description: 'Uniqueness validation should be with a unique index.'
1077
+ Description: 'Uniqueness validation should have a unique index on the database column.'
808
1078
  Enabled: true
809
1079
  VersionAdded: '2.5'
810
1080
  Include:
@@ -813,7 +1083,9 @@ Rails/UniqueValidationWithoutIndex:
813
1083
  Rails/UnknownEnv:
814
1084
  Description: 'Use correct environment name.'
815
1085
  Enabled: true
1086
+ Severity: warning
816
1087
  VersionAdded: '0.51'
1088
+ VersionChanged: '2.18'
817
1089
  Environments:
818
1090
  - development
819
1091
  - test
@@ -853,12 +1125,36 @@ Rails/WhereExists:
853
1125
  VersionAdded: '2.7'
854
1126
  VersionChanged: '2.10'
855
1127
 
1128
+ Rails/WhereMissing:
1129
+ Description: 'Use `where.missing(...)` to find missing relationship records.'
1130
+ StyleGuide: 'https://rails.rubystyle.guide/#finding-missing-relationship-records'
1131
+ Enabled: pending
1132
+ VersionAdded: '2.16'
1133
+
856
1134
  Rails/WhereNot:
857
1135
  Description: 'Use `where.not(...)` instead of manually constructing negated SQL in `where`.'
858
1136
  StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions'
859
1137
  Enabled: 'pending'
860
1138
  VersionAdded: '2.8'
861
1139
 
1140
+ Rails/WhereNotWithMultipleConditions:
1141
+ Description: 'Do not use `where.not(...)` with multiple conditions.'
1142
+ StyleGuide: 'https://rails.rubystyle.guide/#where-not-with-multiple-attributes'
1143
+ Enabled: 'pending'
1144
+ Severity: warning
1145
+ VersionAdded: '2.17'
1146
+ VersionChanged: '2.18'
1147
+
862
1148
  # Accept `redirect_to(...) and return` and similar cases.
863
1149
  Style/AndOr:
864
1150
  EnforcedStyle: conditionals
1151
+
1152
+ Style/FormatStringToken:
1153
+ AllowedMethods:
1154
+ - redirect
1155
+
1156
+ Style/SymbolProc:
1157
+ AllowedMethods:
1158
+ - define_method
1159
+ - mail
1160
+ - respond_to