rubocop-rails 2.14.2 → 2.19.1

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 (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 +190 -12
  5. data/config/obsoletion.yml +10 -0
  6. data/lib/rubocop/cop/mixin/active_record_helper.rb +3 -6
  7. data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +1 -3
  8. data/lib/rubocop/cop/mixin/enforce_superclass.rb +1 -1
  9. data/lib/rubocop/cop/mixin/index_method.rb +7 -17
  10. data/lib/rubocop/cop/mixin/migrations_helper.rb +1 -1
  11. data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +112 -0
  12. data/lib/rubocop/cop/rails/action_controller_test_case.rb +2 -2
  13. data/lib/rubocop/cop/rails/action_filter.rb +2 -2
  14. data/lib/rubocop/cop/rails/action_order.rb +116 -0
  15. data/lib/rubocop/cop/rails/active_record_aliases.rb +3 -4
  16. data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +7 -4
  17. data/lib/rubocop/cop/rails/active_record_override.rb +2 -5
  18. data/lib/rubocop/cop/rails/active_support_aliases.rb +1 -1
  19. data/lib/rubocop/cop/rails/active_support_on_load.rb +70 -0
  20. data/lib/rubocop/cop/rails/add_column_index.rb +3 -6
  21. data/lib/rubocop/cop/rails/after_commit_override.rb +1 -1
  22. data/lib/rubocop/cop/rails/application_controller.rb +2 -2
  23. data/lib/rubocop/cop/rails/application_job.rb +3 -3
  24. data/lib/rubocop/cop/rails/application_mailer.rb +2 -2
  25. data/lib/rubocop/cop/rails/application_record.rb +2 -2
  26. data/lib/rubocop/cop/rails/arel_star.rb +2 -2
  27. data/lib/rubocop/cop/rails/assert_not.rb +1 -1
  28. data/lib/rubocop/cop/rails/attribute_default_block_value.rb +1 -1
  29. data/lib/rubocop/cop/rails/belongs_to.rb +2 -5
  30. data/lib/rubocop/cop/rails/blank.rb +10 -11
  31. data/lib/rubocop/cop/rails/bulk_change_table.rb +8 -25
  32. data/lib/rubocop/cop/rails/compact_blank.rb +6 -2
  33. data/lib/rubocop/cop/rails/content_tag.rb +6 -7
  34. data/lib/rubocop/cop/rails/create_table_with_timestamps.rb +16 -3
  35. data/lib/rubocop/cop/rails/date.rb +12 -17
  36. data/lib/rubocop/cop/rails/default_scope.rb +1 -1
  37. data/lib/rubocop/cop/rails/delegate.rb +24 -18
  38. data/lib/rubocop/cop/rails/delegate_allow_blank.rb +2 -2
  39. data/lib/rubocop/cop/rails/deprecated_active_model_errors_methods.rb +63 -3
  40. data/lib/rubocop/cop/rails/dot_separated_keys.rb +71 -0
  41. data/lib/rubocop/cop/rails/duplicate_association.rb +2 -2
  42. data/lib/rubocop/cop/rails/duplicate_scope.rb +1 -1
  43. data/lib/rubocop/cop/rails/duration_arithmetic.rb +4 -4
  44. data/lib/rubocop/cop/rails/dynamic_find_by.rb +26 -14
  45. data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +6 -2
  46. data/lib/rubocop/cop/rails/enum_hash.rb +3 -4
  47. data/lib/rubocop/cop/rails/enum_uniqueness.rb +3 -6
  48. data/lib/rubocop/cop/rails/environment_comparison.rb +3 -4
  49. data/lib/rubocop/cop/rails/environment_variable_access.rb +1 -1
  50. data/lib/rubocop/cop/rails/exit.rb +1 -1
  51. data/lib/rubocop/cop/rails/expanded_date_range.rb +39 -23
  52. data/lib/rubocop/cop/rails/file_path.rb +41 -24
  53. data/lib/rubocop/cop/rails/find_by.rb +1 -1
  54. data/lib/rubocop/cop/rails/find_by_id.rb +3 -3
  55. data/lib/rubocop/cop/rails/find_each.rb +14 -4
  56. data/lib/rubocop/cop/rails/freeze_time.rb +79 -0
  57. data/lib/rubocop/cop/rails/has_and_belongs_to_many.rb +1 -1
  58. data/lib/rubocop/cop/rails/has_many_or_has_one_dependent.rb +14 -8
  59. data/lib/rubocop/cop/rails/helper_instance_variable.rb +3 -3
  60. data/lib/rubocop/cop/rails/http_positional_arguments.rb +23 -12
  61. data/lib/rubocop/cop/rails/http_status.rb +6 -11
  62. data/lib/rubocop/cop/rails/i18n_lazy_lookup.rb +3 -1
  63. data/lib/rubocop/cop/rails/i18n_locale_assignment.rb +1 -1
  64. data/lib/rubocop/cop/rails/i18n_locale_texts.rb +2 -2
  65. data/lib/rubocop/cop/rails/ignored_columns_assignment.rb +50 -0
  66. data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +5 -14
  67. data/lib/rubocop/cop/rails/index_by.rb +2 -2
  68. data/lib/rubocop/cop/rails/index_with.rb +2 -2
  69. data/lib/rubocop/cop/rails/inquiry.rb +1 -1
  70. data/lib/rubocop/cop/rails/inverse_of.rb +4 -10
  71. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +22 -16
  72. data/lib/rubocop/cop/rails/link_to_blank.rb +2 -5
  73. data/lib/rubocop/cop/rails/mailer_name.rb +5 -5
  74. data/lib/rubocop/cop/rails/match_route.rb +1 -1
  75. data/lib/rubocop/cop/rails/migration_class_name.rb +2 -2
  76. data/lib/rubocop/cop/rails/negate_include.rb +2 -2
  77. data/lib/rubocop/cop/rails/not_null_column.rb +10 -7
  78. data/lib/rubocop/cop/rails/order_by_id.rb +2 -3
  79. data/lib/rubocop/cop/rails/output.rb +7 -9
  80. data/lib/rubocop/cop/rails/output_safety.rb +6 -2
  81. data/lib/rubocop/cop/rails/pick.rb +1 -1
  82. data/lib/rubocop/cop/rails/pluck.rb +45 -13
  83. data/lib/rubocop/cop/rails/pluck_id.rb +2 -2
  84. data/lib/rubocop/cop/rails/pluck_in_where.rb +1 -1
  85. data/lib/rubocop/cop/rails/pluralization_grammar.rb +2 -3
  86. data/lib/rubocop/cop/rails/presence.rb +22 -13
  87. data/lib/rubocop/cop/rails/present.rb +10 -13
  88. data/lib/rubocop/cop/rails/rake_environment.rb +3 -3
  89. data/lib/rubocop/cop/rails/read_write_attribute.rb +2 -2
  90. data/lib/rubocop/cop/rails/redundant_allow_nil.rb +5 -7
  91. data/lib/rubocop/cop/rails/redundant_foreign_key.rb +3 -3
  92. data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +3 -3
  93. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +31 -27
  94. data/lib/rubocop/cop/rails/redundant_travel_back.rb +1 -1
  95. data/lib/rubocop/cop/rails/reflection_class_name.rb +35 -2
  96. data/lib/rubocop/cop/rails/refute_methods.rb +1 -5
  97. data/lib/rubocop/cop/rails/relative_date_constant.rb +5 -8
  98. data/lib/rubocop/cop/rails/render_inline.rb +1 -1
  99. data/lib/rubocop/cop/rails/render_plain_text.rb +1 -1
  100. data/lib/rubocop/cop/rails/request_referer.rb +2 -3
  101. data/lib/rubocop/cop/rails/require_dependency.rb +2 -2
  102. data/lib/rubocop/cop/rails/response_parsed_body.rb +57 -0
  103. data/lib/rubocop/cop/rails/reversible_migration.rb +15 -63
  104. data/lib/rubocop/cop/rails/reversible_migration_method_definition.rb +5 -6
  105. data/lib/rubocop/cop/rails/root_join_chain.rb +1 -1
  106. data/lib/rubocop/cop/rails/root_pathname_methods.rb +238 -0
  107. data/lib/rubocop/cop/rails/root_public_path.rb +59 -0
  108. data/lib/rubocop/cop/rails/safe_navigation.rb +8 -13
  109. data/lib/rubocop/cop/rails/safe_navigation_with_blank.rb +2 -4
  110. data/lib/rubocop/cop/rails/save_bang.rb +12 -24
  111. data/lib/rubocop/cop/rails/schema_comment.rb +1 -1
  112. data/lib/rubocop/cop/rails/scope_args.rb +1 -1
  113. data/lib/rubocop/cop/rails/short_i18n.rb +3 -6
  114. data/lib/rubocop/cop/rails/skips_model_validations.rb +3 -4
  115. data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +10 -7
  116. data/lib/rubocop/cop/rails/strip_heredoc.rb +56 -0
  117. data/lib/rubocop/cop/rails/table_name_assignment.rb +1 -1
  118. data/lib/rubocop/cop/rails/three_state_boolean_column.rb +73 -0
  119. data/lib/rubocop/cop/rails/time_zone.rb +34 -32
  120. data/lib/rubocop/cop/rails/time_zone_assignment.rb +4 -4
  121. data/lib/rubocop/cop/rails/to_formatted_s.rb +46 -0
  122. data/lib/rubocop/cop/rails/to_s_with_argument.rb +78 -0
  123. data/lib/rubocop/cop/rails/top_level_hash_with_indifferent_access.rb +49 -0
  124. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +17 -12
  125. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +3 -6
  126. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +14 -7
  127. data/lib/rubocop/cop/rails/unknown_env.rb +3 -5
  128. data/lib/rubocop/cop/rails/unused_ignored_columns.rb +7 -2
  129. data/lib/rubocop/cop/rails/validation.rb +5 -13
  130. data/lib/rubocop/cop/rails/where_equals.rb +2 -2
  131. data/lib/rubocop/cop/rails/where_exists.rb +3 -3
  132. data/lib/rubocop/cop/rails/where_missing.rb +118 -0
  133. data/lib/rubocop/cop/rails/where_not.rb +2 -2
  134. data/lib/rubocop/cop/rails/where_not_with_multiple_conditions.rb +55 -0
  135. data/lib/rubocop/cop/rails_cops.rb +16 -0
  136. data/lib/rubocop/rails/schema_loader/schema.rb +8 -5
  137. data/lib/rubocop/rails/version.rb +1 -1
  138. data/lib/rubocop/rails.rb +1 -1
  139. data/lib/rubocop-rails.rb +19 -0
  140. metadata +23 -9
  141. data/bin/console +0 -11
  142. data/bin/setup +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: babf21479a37aa37cba8b6b8401b23ddb6532e14afd679095d456f749aca3ca0
4
- data.tar.gz: 11a94f8219a5b9d241d68af1c3ecd69afb0a47ccf988db59d00f48caaf73dfbf
3
+ metadata.gz: b020fcc0db6203c33dfe23032cc2c6ec0df139e6abb048409bdf7439ea2d4183
4
+ data.tar.gz: fc6e892161124d21b9067e01e6b86178857df27d14ae687f3f0fdcceb2b3d078
5
5
  SHA512:
6
- metadata.gz: 02b2646080a54c50c8708cd6feeed501b5aafd7ae77d04e42ed0bf5b8779f43fa778bc3f46daec2c06474ac76f40ae144bf0afed35e5acf996c4b2213df53f89
7
- data.tar.gz: 4b29b44608474ead97651327e5c896bfb403eadcc1deffd10730853f303e75682e3ebebed80f8b3b05c1f9f0862441845bea89135d694ecf70ee3d6c776f2a97
6
+ metadata.gz: f09636066a282111462ab5cc3b93463ec0cd8a111e2882b6e7c21889da3b36958766f722926418439e48933d8791ce41c0edadc3e4a590c5f8caeb82f35ad5b1
7
+ data.tar.gz: 40586400ad94701ee39ee71ab7280f7328889245f4786503cf5a851d158a05e4f736eea42c53f61164a420af8fab7e19854c6302237115a29efd3bdd1f19cc68
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-22 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
@@ -10,6 +10,12 @@ AllCops:
10
10
  # Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
11
11
  # See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
12
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
13
19
  # What version of Rails is the inspected code using? If a value is specified
14
20
  # for TargetRailsVersion then it is used. Acceptable values are specified
15
21
  # as a float (i.e. 5.1); the patch version of Rails should not be included.
@@ -23,7 +29,7 @@ Lint/NumberConversion:
23
29
  # Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
24
30
  # so that calling `to_i` on one of these does not register an offense.
25
31
  # See: https://github.com/rubocop/rubocop/issues/8950
26
- IgnoredMethods:
32
+ AllowedMethods:
27
33
  - ago
28
34
  - from_now
29
35
  - second
@@ -39,13 +45,24 @@ Lint/NumberConversion:
39
45
  - fortnight
40
46
  - fortnights
41
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'
42
59
 
43
60
  Rails/ActionControllerTestCase:
44
61
  Description: 'Use `ActionDispatch::IntegrationTest` instead of `ActionController::TestCase`.'
45
62
  StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
46
63
  Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
47
64
  Enabled: 'pending'
48
- SafeAutocorrect: false
65
+ SafeAutoCorrect: false
49
66
  VersionAdded: '2.14'
50
67
  Include:
51
68
  - '**/test/**/*.rb'
@@ -60,6 +77,22 @@ Rails/ActionFilter:
60
77
  - filter
61
78
  Include:
62
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
63
96
 
64
97
  Rails/ActiveRecordAliases:
65
98
  Description: >-
@@ -83,7 +116,9 @@ Rails/ActiveRecordOverride:
83
116
  Check for overriding Active Record methods instead of using
84
117
  callbacks.
85
118
  Enabled: true
119
+ Severity: warning
86
120
  VersionAdded: '0.67'
121
+ VersionChanged: '2.18'
87
122
  Include:
88
123
  - app/models/**/*.rb
89
124
 
@@ -95,6 +130,15 @@ Rails/ActiveSupportAliases:
95
130
  Enabled: true
96
131
  VersionAdded: '0.48'
97
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
+
98
142
  Rails/AddColumnIndex:
99
143
  Description: >-
100
144
  Rails migrations don't make use of a given `index` key, but also
@@ -107,7 +151,7 @@ Rails/AddColumnIndex:
107
151
 
108
152
  Rails/AfterCommitOverride:
109
153
  Description: >-
110
- This cop enforces that there is only one call to `after_commit`
154
+ Enforces that there is only one call to `after_commit`
111
155
  (and its aliases - `after_create_commit`, `after_update_commit`,
112
156
  and `after_destroy_commit`) with the same callback name per model.
113
157
  Enabled: 'pending'
@@ -159,12 +203,15 @@ Rails/AttributeDefaultBlockValue:
159
203
  Enabled: pending
160
204
  VersionAdded: '2.9'
161
205
  Include:
162
- - 'models/**/*'
206
+ - 'app/models/**/*'
163
207
 
164
208
  Rails/BelongsTo:
165
209
  Description: >-
166
210
  Use `optional: true` instead of `required: false` for
167
211
  `belongs_to` relations.
212
+ Reference:
213
+ - https://guides.rubyonrails.org/5_0_release_notes.html
214
+ - https://github.com/rails/rails/pull/18937
168
215
  Enabled: true
169
216
  VersionAdded: '0.62'
170
217
 
@@ -183,6 +230,9 @@ Rails/Blank:
183
230
 
184
231
  Rails/BulkChangeTable:
185
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
186
236
  Enabled: true
187
237
  VersionAdded: '0.57'
188
238
  Database: null
@@ -269,18 +319,30 @@ Rails/DelegateAllowBlank:
269
319
  Rails/DeprecatedActiveModelErrorsMethods:
270
320
  Description: 'Avoid manipulating ActiveModel errors hash directly.'
271
321
  Enabled: pending
322
+ Severity: warning
272
323
  Safe: false
273
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'
274
332
 
275
333
  Rails/DuplicateAssociation:
276
334
  Description: "Don't repeat associations in a model."
277
335
  Enabled: pending
336
+ Severity: warning
278
337
  VersionAdded: '2.14'
338
+ VersionChanged: '2.18'
279
339
 
280
340
  Rails/DuplicateScope:
281
341
  Description: 'Multiple scopes share this same where clause.'
282
342
  Enabled: pending
343
+ Severity: warning
283
344
  VersionAdded: '2.14'
345
+ VersionChanged: '2.18'
284
346
 
285
347
  Rails/DurationArithmetic:
286
348
  Description: 'Do not use duration as arithmetic operand with `Time.current`.'
@@ -298,10 +360,13 @@ Rails/DynamicFindBy:
298
360
  # The `Whitelist` has been deprecated, Please use `AllowedMethods` instead.
299
361
  Whitelist:
300
362
  - find_by_sql
363
+ - find_by_token_for
301
364
  AllowedMethods:
302
365
  - find_by_sql
366
+ - find_by_token_for
303
367
  AllowedReceivers:
304
368
  - Gem::Specification
369
+ - page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
305
370
 
306
371
  Rails/EagerEvaluationLogMessage:
307
372
  Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'
@@ -359,6 +424,7 @@ Rails/Exit:
359
424
 
360
425
  Rails/ExpandedDateRange:
361
426
  Description: 'Checks for expanded date range.'
427
+ StyleGuide: 'https://rails.rubystyle.guide/#date-time-range'
362
428
  Enabled: pending
363
429
  VersionAdded: '2.11'
364
430
 
@@ -391,19 +457,28 @@ Rails/FindById:
391
457
  VersionAdded: '2.7'
392
458
 
393
459
  Rails/FindEach:
394
- Description: 'Prefer all.find_each over all.find.'
460
+ Description: 'Prefer all.find_each over all.each.'
395
461
  StyleGuide: 'https://rails.rubystyle.guide#find-each'
396
462
  Enabled: true
463
+ Safe: false
397
464
  VersionAdded: '0.30'
398
- VersionChanged: '2.9'
465
+ VersionChanged: '2.19'
399
466
  Include:
400
467
  - app/models/**/*.rb
401
- IgnoredMethods:
468
+ AllowedMethods:
402
469
  # Methods that don't work well with `find_each`.
403
470
  - order
404
471
  - limit
405
472
  - select
406
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
407
482
 
408
483
  Rails/HasAndBelongsToMany:
409
484
  Description: 'Prefer has_many :through to has_and_belongs_to_many.'
@@ -453,7 +528,7 @@ Rails/I18nLazyLookup:
453
528
  Enabled: pending
454
529
  VersionAdded: '2.14'
455
530
  Include:
456
- - 'controllers/**/*'
531
+ - 'app/controllers/**/*.rb'
457
532
 
458
533
  Rails/I18nLocaleAssignment:
459
534
  Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
@@ -469,6 +544,13 @@ Rails/I18nLocaleTexts:
469
544
  Enabled: pending
470
545
  VersionAdded: '2.14'
471
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
+
472
554
  Rails/IgnoredSkipActionFilterOption:
473
555
  Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.'
474
556
  Reference: 'https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options'
@@ -476,6 +558,7 @@ Rails/IgnoredSkipActionFilterOption:
476
558
  VersionAdded: '0.63'
477
559
  Include:
478
560
  - app/controllers/**/*.rb
561
+ - app/mailers/**/*.rb
479
562
 
480
563
  Rails/IndexBy:
481
564
  Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
@@ -497,6 +580,9 @@ Rails/Inquiry:
497
580
 
498
581
  Rails/InverseOf:
499
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
500
586
  Enabled: true
501
587
  VersionAdded: '0.52'
502
588
  IgnoreScopes: false
@@ -504,13 +590,14 @@ Rails/InverseOf:
504
590
  - app/models/**/*.rb
505
591
 
506
592
  Rails/LexicallyScopedActionFilter:
507
- 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."
508
594
  StyleGuide: 'https://rails.rubystyle.guide#lexically-scoped-action-filter'
509
595
  Enabled: true
510
596
  Safe: false
511
597
  VersionAdded: '0.52'
512
598
  Include:
513
599
  - app/controllers/**/*.rb
600
+ - app/mailers/**/*.rb
514
601
 
515
602
  Rails/LinkToBlank:
516
603
  Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
@@ -599,7 +686,9 @@ Rails/Pluck:
599
686
  Description: 'Prefer `pluck` over `map { ... }`.'
600
687
  StyleGuide: 'https://rails.rubystyle.guide#pluck'
601
688
  Enabled: 'pending'
689
+ Safe: false
602
690
  VersionAdded: '2.7'
691
+ VersionChanged: '2.18'
603
692
 
604
693
  Rails/PluckId:
605
694
  Description: 'Use `ids` instead of `pluck(:id)` or `pluck(primary_key)`.'
@@ -690,7 +779,7 @@ Rails/RedundantReceiverInWithOptions:
690
779
  VersionAdded: '0.52'
691
780
 
692
781
  Rails/RedundantTravelBack:
693
- Description: This cop checks for redundant `travel_back` calls.
782
+ Description: Checks for redundant `travel_back` calls.
694
783
  Enabled: pending
695
784
  VersionAdded: '2.12'
696
785
  Include:
@@ -751,6 +840,18 @@ Rails/RequireDependency:
751
840
  Enabled: false
752
841
  VersionAdded: '2.10'
753
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
+
754
855
  Rails/ReversibleMigration:
755
856
  Description: 'Checks whether the change method of the migration file is reversible.'
756
857
  StyleGuide: 'https://rails.rubystyle.guide#reversible-migration'
@@ -774,6 +875,17 @@ Rails/RootJoinChain:
774
875
  Enabled: pending
775
876
  VersionAdded: '2.13'
776
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'
888
+
777
889
  Rails/SafeNavigation:
778
890
  Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`."
779
891
  Enabled: true
@@ -808,7 +920,7 @@ Rails/SaveBang:
808
920
 
809
921
  Rails/SchemaComment:
810
922
  Description: >-
811
- This cop enforces the use of the `comment` option when adding a new table or column
923
+ Enforces the use of the `comment` option when adding a new table or column
812
924
  to the database during a migration.
813
925
  Enabled: false
814
926
  VersionAdded: '2.13'
@@ -867,9 +979,15 @@ Rails/SquishedSQLHeredocs:
867
979
  VersionAdded: '2.8'
868
980
  VersionChanged: '2.9'
869
981
  # Some SQL syntax (e.g. PostgreSQL comments and functions) requires newlines
870
- # 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.
871
983
  SafeAutoCorrect: false
872
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
+
873
991
  Rails/TableNameAssignment:
874
992
  Description: >-
875
993
  Do not use `self.table_name =`. Use Inflections or `table_name_prefix` instead.
@@ -879,6 +997,14 @@ Rails/TableNameAssignment:
879
997
  Include:
880
998
  - app/models/**/*.rb
881
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
+
882
1008
  Rails/TimeZone:
883
1009
  Description: 'Checks the correct usage of time zone aware methods.'
884
1010
  StyleGuide: 'https://rails.rubystyle.guide#time'
@@ -905,8 +1031,34 @@ Rails/TimeZoneAssignment:
905
1031
  - spec/**/*.rb
906
1032
  - test/**/*.rb
907
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
+
908
1058
  Rails/TransactionExitStatement:
909
1059
  Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.'
1060
+ Reference:
1061
+ - https://github.com/rails/rails/commit/15aa4200e083
910
1062
  Enabled: pending
911
1063
  VersionAdded: '2.14'
912
1064
 
@@ -931,7 +1083,9 @@ Rails/UniqueValidationWithoutIndex:
931
1083
  Rails/UnknownEnv:
932
1084
  Description: 'Use correct environment name.'
933
1085
  Enabled: true
1086
+ Severity: warning
934
1087
  VersionAdded: '0.51'
1088
+ VersionChanged: '2.18'
935
1089
  Environments:
936
1090
  - development
937
1091
  - test
@@ -971,12 +1125,36 @@ Rails/WhereExists:
971
1125
  VersionAdded: '2.7'
972
1126
  VersionChanged: '2.10'
973
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
+
974
1134
  Rails/WhereNot:
975
1135
  Description: 'Use `where.not(...)` instead of manually constructing negated SQL in `where`.'
976
1136
  StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions'
977
1137
  Enabled: 'pending'
978
1138
  VersionAdded: '2.8'
979
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
+
980
1148
  # Accept `redirect_to(...) and return` and similar cases.
981
1149
  Style/AndOr:
982
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
@@ -5,3 +5,13 @@
5
5
  #
6
6
  extracted:
7
7
  Rails/*: ~
8
+
9
+ # Cop parameters that have been changed
10
+ # Can be treated as a warning instead of a failure with `severity: warning`
11
+ changed_parameters:
12
+ - cops: Rails/FindEach
13
+ parameters: IgnoredMethods
14
+ alternatives:
15
+ - AllowedMethods
16
+ - AllowedPatterns
17
+ severity: warning
@@ -10,8 +10,8 @@ module RuboCop
10
10
 
11
11
  def_node_matcher :active_record?, <<~PATTERN
12
12
  {
13
- (const nil? :ApplicationRecord)
14
- (const (const nil? :ActiveRecord) :Base)
13
+ (const {nil? cbase} :ApplicationRecord)
14
+ (const (const {nil? cbase} :ActiveRecord) :Base)
15
15
  }
16
16
  PATTERN
17
17
 
@@ -48,10 +48,7 @@ module RuboCop
48
48
 
49
49
  class_nodes = class_node.defined_module.each_node
50
50
  namespaces = class_node.each_ancestor(:class, :module).map(&:identifier)
51
- [*class_nodes, *namespaces]
52
- .reverse
53
- .map { |node| node.children[1] }.join('_')
54
- .tableize
51
+ [*class_nodes, *namespaces].reverse.map { |node| node.children[1] }.join('_').tableize
55
52
  end
56
53
 
57
54
  # Resolve relation into column name.
@@ -10,9 +10,7 @@ module RuboCop
10
10
  bigint binary boolean date datetime decimal float integer json string
11
11
  text time timestamp virtual
12
12
  ].freeze
13
- RAILS_ABSTRACT_SCHEMA_DEFINITIONS_HELPERS = %i[
14
- column references belongs_to primary_key numeric
15
- ].freeze
13
+ RAILS_ABSTRACT_SCHEMA_DEFINITIONS_HELPERS = %i[column references belongs_to primary_key numeric].freeze
16
14
  POSTGRES_SCHEMA_DEFINITIONS = %i[
17
15
  bigserial bit bit_varying cidr citext daterange hstore inet interval
18
16
  int4range int8range jsonb ltree macaddr money numrange oid point line
@@ -32,7 +32,7 @@ module RuboCop
32
32
 
33
33
  def register_offense(offense_node)
34
34
  add_offense(offense_node) do |corrector|
35
- corrector.replace(offense_node.source_range, self.class::SUPERCLASS)
35
+ corrector.replace(offense_node, self.class::SUPERCLASS)
36
36
  end
37
37
  end
38
38
  end
@@ -6,7 +6,7 @@ module RuboCop
6
6
  module IndexMethod # rubocop:disable Metrics/ModuleLength
7
7
  RESTRICT_ON_SEND = %i[each_with_object to_h map collect []].freeze
8
8
 
9
- def on_block(node)
9
+ def on_block(node) # rubocop:todo InternalAffairs/NumblockHandler
10
10
  on_bad_each_with_object(node) do |*match|
11
11
  handle_possible_offense(node, match, 'each_with_object')
12
12
  end
@@ -98,10 +98,7 @@ module RuboCop
98
98
 
99
99
  captures = extract_captures(correction.match)
100
100
  correction.set_new_arg_name(captures.transformed_argname, corrector)
101
- correction.set_new_body_expression(
102
- captures.transforming_body_expr,
103
- corrector
104
- )
101
+ correction.set_new_body_expression(captures.transforming_body_expr, corrector)
105
102
  end
106
103
 
107
104
  # Internal helper class to hold match data
@@ -110,8 +107,7 @@ module RuboCop
110
107
  :transforming_body_expr
111
108
  ) do
112
109
  def noop_transformation?
113
- transforming_body_expr.lvar_type? &&
114
- transforming_body_expr.children == [transformed_argname]
110
+ transforming_body_expr.lvar_type? && transforming_body_expr.children == [transformed_argname]
115
111
  end
116
112
  end
117
113
 
@@ -138,11 +134,11 @@ module RuboCop
138
134
  end
139
135
 
140
136
  def self.from_hash_brackets_map(node, match)
141
- new(match, node.children.last, 'Hash['.length, ']'.length)
137
+ new(match, node.children.last, "#{node.receiver.source}[".length, ']'.length)
142
138
  end
143
139
 
144
140
  def strip_prefix_and_suffix(node, corrector)
145
- expression = node.loc.expression
141
+ expression = node.source_range
146
142
  corrector.remove_leading(expression, leading)
147
143
  corrector.remove_trailing(expression, trailing)
148
144
  end
@@ -157,17 +153,11 @@ module RuboCop
157
153
  end
158
154
 
159
155
  def set_new_arg_name(transformed_argname, corrector)
160
- corrector.replace(
161
- block_node.arguments.loc.expression,
162
- "|#{transformed_argname}|"
163
- )
156
+ corrector.replace(block_node.arguments, "|#{transformed_argname}|")
164
157
  end
165
158
 
166
159
  def set_new_body_expression(transforming_body_expr, corrector)
167
- corrector.replace(
168
- block_node.body.loc.expression,
169
- transforming_body_expr.loc.expression.source
170
- )
160
+ corrector.replace(block_node.body, transforming_body_expr.source)
171
161
  end
172
162
  end
173
163
  end
@@ -8,7 +8,7 @@ module RuboCop
8
8
 
9
9
  def_node_matcher :migration_class?, <<~PATTERN
10
10
  (class
11
- (const nil? _)
11
+ (const {nil? cbase} _)
12
12
  (send
13
13
  (const (const {nil? cbase} :ActiveRecord) :Migration)
14
14
  :[]