rubocop-rails 2.25.1 → 2.32.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 (80) hide show
  1. checksums.yaml +4 -4
  2. data/LICENSE.txt +1 -1
  3. data/README.md +60 -8
  4. data/config/default.yml +103 -51
  5. data/lib/rubocop/cop/mixin/active_record_helper.rb +2 -2
  6. data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +2 -2
  7. data/lib/rubocop/cop/mixin/database_type_resolvable.rb +2 -2
  8. data/lib/rubocop/cop/mixin/enforce_superclass.rb +6 -1
  9. data/lib/rubocop/cop/mixin/index_method.rb +69 -61
  10. data/lib/rubocop/cop/mixin/routes_helper.rb +20 -0
  11. data/lib/rubocop/cop/mixin/target_rails_version.rb +3 -5
  12. data/lib/rubocop/cop/rails/action_order.rb +1 -5
  13. data/lib/rubocop/cop/rails/active_record_callbacks_order.rb +1 -5
  14. data/lib/rubocop/cop/rails/add_column_index.rb +1 -0
  15. data/lib/rubocop/cop/rails/application_record.rb +4 -0
  16. data/lib/rubocop/cop/rails/arel_star.rb +5 -5
  17. data/lib/rubocop/cop/rails/belongs_to.rb +1 -1
  18. data/lib/rubocop/cop/rails/blank.rb +1 -1
  19. data/lib/rubocop/cop/rails/bulk_change_table.rb +3 -2
  20. data/lib/rubocop/cop/rails/compact_blank.rb +29 -8
  21. data/lib/rubocop/cop/rails/content_tag.rb +1 -1
  22. data/lib/rubocop/cop/rails/dangerous_column_names.rb +2 -0
  23. data/lib/rubocop/cop/rails/date.rb +2 -2
  24. data/lib/rubocop/cop/rails/delegate.rb +53 -7
  25. data/lib/rubocop/cop/rails/duplicate_association.rb +8 -4
  26. data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +1 -3
  27. data/lib/rubocop/cop/rails/enum_hash.rb +31 -8
  28. data/lib/rubocop/cop/rails/enum_syntax.rb +130 -0
  29. data/lib/rubocop/cop/rails/enum_uniqueness.rb +29 -7
  30. data/lib/rubocop/cop/rails/env_local.rb +26 -3
  31. data/lib/rubocop/cop/rails/file_path.rb +62 -10
  32. data/lib/rubocop/cop/rails/http_positional_arguments.rb +7 -0
  33. data/lib/rubocop/cop/rails/ignored_skip_action_filter_option.rb +1 -1
  34. data/lib/rubocop/cop/rails/index_by.rb +37 -12
  35. data/lib/rubocop/cop/rails/index_with.rb +37 -12
  36. data/lib/rubocop/cop/rails/inquiry.rb +1 -1
  37. data/lib/rubocop/cop/rails/lexically_scoped_action_filter.rb +11 -1
  38. data/lib/rubocop/cop/rails/match_route.rb +1 -9
  39. data/lib/rubocop/cop/rails/multiple_route_paths.rb +50 -0
  40. data/lib/rubocop/cop/rails/not_null_column.rb +6 -2
  41. data/lib/rubocop/cop/rails/output.rb +1 -2
  42. data/lib/rubocop/cop/rails/pluck.rb +30 -4
  43. data/lib/rubocop/cop/rails/pluck_in_where.rb +17 -8
  44. data/lib/rubocop/cop/rails/pluralization_grammar.rb +30 -16
  45. data/lib/rubocop/cop/rails/presence.rb +1 -1
  46. data/lib/rubocop/cop/rails/present.rb +1 -3
  47. data/lib/rubocop/cop/rails/redundant_active_record_all_method.rb +1 -30
  48. data/lib/rubocop/cop/rails/redundant_foreign_key.rb +1 -1
  49. data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +9 -0
  50. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +7 -2
  51. data/lib/rubocop/cop/rails/reflection_class_name.rb +3 -3
  52. data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
  53. data/lib/rubocop/cop/rails/render_plain_text.rb +6 -3
  54. data/lib/rubocop/cop/rails/request_referer.rb +1 -1
  55. data/lib/rubocop/cop/rails/reversible_migration.rb +4 -1
  56. data/lib/rubocop/cop/rails/root_pathname_methods.rb +21 -12
  57. data/lib/rubocop/cop/rails/save_bang.rb +8 -7
  58. data/lib/rubocop/cop/rails/schema_comment.rb +2 -1
  59. data/lib/rubocop/cop/rails/select_map.rb +3 -2
  60. data/lib/rubocop/cop/rails/skips_model_validations.rb +5 -3
  61. data/lib/rubocop/cop/rails/squished_sql_heredocs.rb +1 -1
  62. data/lib/rubocop/cop/rails/strip_heredoc.rb +1 -1
  63. data/lib/rubocop/cop/rails/strong_parameters_expect.rb +104 -0
  64. data/lib/rubocop/cop/rails/three_state_boolean_column.rb +3 -2
  65. data/lib/rubocop/cop/rails/time_zone.rb +16 -7
  66. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +7 -2
  67. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +10 -33
  68. data/lib/rubocop/cop/rails/unique_validation_without_index.rb +1 -1
  69. data/lib/rubocop/cop/rails/validation.rb +1 -1
  70. data/lib/rubocop/cop/rails/where_equals.rb +28 -12
  71. data/lib/rubocop/cop/rails/where_not.rb +11 -6
  72. data/lib/rubocop/cop/rails/where_range.rb +7 -2
  73. data/lib/rubocop/cop/rails_cops.rb +4 -0
  74. data/lib/rubocop/rails/migration_file_skippable.rb +54 -0
  75. data/lib/rubocop/rails/plugin.rb +48 -0
  76. data/lib/rubocop/rails/version.rb +1 -1
  77. data/lib/rubocop/rails.rb +1 -8
  78. data/lib/rubocop-rails.rb +4 -5
  79. metadata +29 -12
  80. data/lib/rubocop/rails/inject.rb +0 -18
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b55703b258e4df9bae3a9a8c1b77a4fa143af6af3ed9b1b22118fd839d1ce06c
4
- data.tar.gz: 24568d7d8d22d69469ae9a4aaf426ea45bf848989604a8744ab6493bc0b222a3
3
+ metadata.gz: '009a04a87f7692e278ce16b061ff93814ada6644691ce2fdd4ac4c7659e68c4d'
4
+ data.tar.gz: 313e26b30279cf9ebba24f5f99bc78b2b44433b24bc3522a6d4261de1cf72282
5
5
  SHA512:
6
- metadata.gz: 47d5668b744967fc740b47552e9d05068fc5ce5c209a4a994a429262a0628b13e0f1e48d6a39018430fb7e874f88e4badbd9427219b9a77220e522d6706b1c3c
7
- data.tar.gz: 242030d6fe9063d51f18e98869e2a048a4b7b847f0f6a25937fc3d9781dbb7749de8b015b3fa0b4933511b83487ad060fbdbf9adb7942a20bfc035d5fc9e2f04
6
+ metadata.gz: 1f7397609be46c75da8ff050ed1325db850c39df7d097d9faeb6984162b706ed92e203f151a30a68aa41b3af8fcdd63b7e76c51ebdcfe31980129a853d7cd8a3
7
+ data.tar.gz: 46006ebeb148838e1ae7f3dc56614b261fc90779c5e3772e163c9431034a89dbc614ef1cb1b913d5236fbc2b04708643fc27b593d8c0c4147898271c045cb4c7
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012-23 Bozhidar Batsov
1
+ Copyright (c) 2012-25 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
@@ -5,7 +5,8 @@
5
5
 
6
6
  A [RuboCop](https://github.com/rubocop/rubocop) extension focused on enforcing Rails best practices and coding conventions.
7
7
 
8
- Note: This repository manages rubocop-rails gem (>= 2.0.0). rubocop-rails gem (<= 1.5.0) has been renamed to [rubocop-rails_config](https://rubygems.org/gems/rubocop-rails_config) gem.
8
+ > [!IMPORTANT]
9
+ > This repository manages rubocop-rails gem (>= 2.0.0). rubocop-rails gem (<= 1.5.0) has been renamed to [rubocop-rails_config](https://rubygems.org/gems/rubocop-rails_config) gem.
9
10
 
10
11
  ## Installation
11
12
 
@@ -31,13 +32,13 @@ ways to do this:
31
32
  Put this into your `.rubocop.yml`.
32
33
 
33
34
  ```yaml
34
- require: rubocop-rails
35
+ plugins: rubocop-rails
35
36
  ```
36
37
 
37
38
  Alternatively, use the following array notation when specifying multiple extensions.
38
39
 
39
40
  ```yaml
40
- require:
41
+ plugins:
41
42
  - rubocop-other-extension
42
43
  - rubocop-rails
43
44
  ```
@@ -45,27 +46,64 @@ require:
45
46
  Now you can run `rubocop` and it will automatically load the RuboCop Rails
46
47
  cops together with the standard cops.
47
48
 
49
+ > [!NOTE]
50
+ > The plugin system is supported in RuboCop 1.72+. In earlier versions, use `require` instead of `plugins`.
51
+
48
52
  ### Command line
49
53
 
50
54
  ```sh
51
- $ rubocop --require rubocop-rails
55
+ $ rubocop --plugin rubocop-rails
52
56
  ```
53
57
 
54
- Note: `--rails` option is required while `rubocop` command supports `--rails` option.
55
-
56
58
  ### Rake task
57
59
 
58
60
  ```ruby
59
61
  require 'rubocop/rake_task'
60
62
 
61
63
  RuboCop::RakeTask.new do |task|
62
- task.requires << 'rubocop-rails'
64
+ task.plugins << 'rubocop-rails'
63
65
  end
64
66
  ```
65
67
 
68
+ ## RuboCop Rails configuration
69
+
70
+ The following settings specific to RuboCop Rails can be configured in `.rubocop.yml`.
71
+
72
+ ### `AllCops: TargetRailsVersion`
73
+
74
+ What version of Rails is the inspected code using? If a value is specified
75
+ for `TargetRailsVersion` then it is used. Acceptable values are specified
76
+ as a float (e.g., 7.2); the patch version of Rails should not be included.
77
+
78
+ ```yaml
79
+ AllCops:
80
+ TargetRailsVersion: 7.2
81
+ ```
82
+
83
+ If `TargetRailsVersion` is not set, RuboCop will parse the Gemfile.lock or
84
+ gems.locked file to find the version of Rails that has been bound to the
85
+ application. If neither of those files exist, RuboCop will use Rails 5.0
86
+ as the default.
87
+
88
+ ### `AllCops: MigratedSchemaVersion`
89
+
90
+ By specifying the `MigratedSchemaVersion` option, migration files that have already been run can be ignored.
91
+ When `MigratedSchemaVersion: '20241225000000'` is set, migration files lower than or equal to '20241225000000' will be ignored.
92
+ For example, to ignore db/migrate/20241225000000_create_articles.rb and earlier migrations you would configure it the following way:
93
+
94
+ ```yaml
95
+ AllCops:
96
+ MigratedSchemaVersion: '20241225000000'
97
+ ```
98
+
99
+ This prevents inspecting schema settings for already applied migration files.
100
+ Changing already applied migrations should be avoided because it can lead to the schema getting out of sync
101
+ between your local copy and what it actually is in production, depending on when `bin/rails db:migrate` was executed.
102
+ If you want to modify your schema to comply with the cops, you should instead create new migrations.
103
+
66
104
  ## Rails configuration tip
67
105
 
68
- If you are using Rails 6.1 or newer, add the following `config.generators.after_generate` setting to
106
+ In Rails 6.1+, add the following `config.generators.after_generate` setting to
69
107
  your `config/environments/development.rb` to apply RuboCop autocorrection to code generated by `bin/rails g`.
70
108
 
71
109
  ```ruby
@@ -84,6 +122,20 @@ It uses `rubocop -A` to apply `Style/FrozenStringLiteralComment` and other unsaf
84
122
  `rubocop -A` is unsafe autocorrection, but code generated by default is simple and less likely to
85
123
  be incompatible with `rubocop -A`. If you have problems you can replace it with `rubocop -a` instead.
86
124
 
125
+ In Rails 7.2+, it is recommended to use `config.generators.apply_rubocop_autocorrect_after_generate!` instead of the above setting:
126
+
127
+ ```diff
128
+ # config/environments/development.rb
129
+ Rails.application.configure do
130
+ (snip)
131
+ # Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
132
+ - # config.generators.apply_rubocop_autocorrect_after_generate!
133
+ + config.generators.apply_rubocop_autocorrect_after_generate!
134
+ end
135
+ ```
136
+
137
+ You only need to uncomment.
138
+
87
139
  ## The Cops
88
140
 
89
141
  All cops are located under
data/config/default.yml CHANGED
@@ -6,7 +6,7 @@ inherit_mode:
6
6
 
7
7
  AllCops:
8
8
  Exclude:
9
- - app/assets/**/*
9
+ - '**/app/assets/**/*'
10
10
  - bin/*
11
11
  # Exclude db/schema.rb and db/[CONFIGURATION_NAMESPACE]_schema.rb by default.
12
12
  # See: https://guides.rubyonrails.org/active_record_multiple_databases.html#setting-up-your-application
@@ -17,14 +17,18 @@ AllCops:
17
17
  # Enable checking Active Support extensions.
18
18
  # See: https://docs.rubocop.org/rubocop/configuration.html#enable-checking-active-support-extensions
19
19
  ActiveSupportExtensionsEnabled: true
20
- # What version of Rails is the inspected code using? If a value is specified
21
- # for TargetRailsVersion then it is used. Acceptable values are specified
22
- # as a float (i.e. 5.1); the patch version of Rails should not be included.
23
- # If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
20
+ # What version of Rails is the inspected code using? If a value is specified
21
+ # for `TargetRailsVersion` then it is used. Acceptable values are specified
22
+ # as a float (e.g., 7.2); the patch version of Rails should not be included.
23
+ # If `TargetRailsVersion` is not set, RuboCop will parse the Gemfile.lock or
24
24
  # gems.locked file to find the version of Rails that has been bound to the
25
- # application. If neither of those files exist, RuboCop will use Rails 5.0
25
+ # application. If neither of those files exist, RuboCop will use Rails 5.0
26
26
  # as the default.
27
27
  TargetRailsVersion: ~
28
+ # By specifying `MigratedSchemaVersion` option, migration files that have been migrated can be ignored.
29
+ # When `MigratedSchemaVersion: '20241231000000'` is set. Migration files lower than or equal to '20250101000000' will be ignored.
30
+ # For example, this is the timestamp in db/migrate/20250101000000_create_articles.rb.
31
+ MigratedSchemaVersion: '19700101000000' # NOTE: Used as a sentinel value for the UNIX epoch time.
28
32
 
29
33
  Lint/NumberConversion:
30
34
  # Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
@@ -73,6 +77,20 @@ Lint/SafeNavigationChain:
73
77
  - try!
74
78
  - in?
75
79
 
80
+ Lint/UselessAccessModifier:
81
+ # Add methods from `ActiveSupport::Concern` and `Module::Concerning`:
82
+ # https://api.rubyonrails.org/classes/ActiveSupport/Concern.html
83
+ # https://api.rubyonrails.org/classes/Module/Concerning
84
+ inherit_mode:
85
+ merge:
86
+ - ContextCreatingMethods
87
+ ContextCreatingMethods:
88
+ - class_methods
89
+ - included
90
+ - prepended
91
+ - concern
92
+ - concerning
93
+
76
94
  Rails:
77
95
  Enabled: true
78
96
  DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
@@ -103,8 +121,8 @@ Rails/ActionFilter:
103
121
  - action
104
122
  - filter
105
123
  Include:
106
- - app/controllers/**/*.rb
107
- - app/mailers/**/*.rb
124
+ - '**/app/controllers/**/*.rb'
125
+ - '**/app/mailers/**/*.rb'
108
126
 
109
127
  Rails/ActionOrder:
110
128
  Description: 'Enforce consistent ordering of controller actions.'
@@ -119,7 +137,7 @@ Rails/ActionOrder:
119
137
  - update
120
138
  - destroy
121
139
  Include:
122
- - app/controllers/**/*.rb
140
+ - '**/app/controllers/**/*.rb'
123
141
 
124
142
  Rails/ActiveRecordAliases:
125
143
  Description: >-
@@ -136,7 +154,7 @@ Rails/ActiveRecordCallbacksOrder:
136
154
  Enabled: 'pending'
137
155
  VersionAdded: '2.7'
138
156
  Include:
139
- - app/models/**/*.rb
157
+ - '**/app/models/**/*.rb'
140
158
 
141
159
  Rails/ActiveRecordOverride:
142
160
  Description: >-
@@ -147,7 +165,7 @@ Rails/ActiveRecordOverride:
147
165
  VersionAdded: '0.67'
148
166
  VersionChanged: '2.18'
149
167
  Include:
150
- - app/models/**/*.rb
168
+ - '**/app/models/**/*.rb'
151
169
 
152
170
  Rails/ActiveSupportAliases:
153
171
  Description: >-
@@ -212,7 +230,9 @@ Rails/ApplicationRecord:
212
230
  Enabled: true
213
231
  SafeAutoCorrect: false
214
232
  VersionAdded: '0.49'
215
- VersionChanged: '2.5'
233
+ VersionChanged: '2.26'
234
+ Exclude:
235
+ - db/**/*.rb
216
236
 
217
237
  Rails/ArelStar:
218
238
  Description: 'Enforces `Arel.star` instead of `"*"` for expanded columns.'
@@ -232,7 +252,7 @@ Rails/AttributeDefaultBlockValue:
232
252
  Enabled: pending
233
253
  VersionAdded: '2.9'
234
254
  Include:
235
- - 'app/models/**/*'
255
+ - '**/app/models/**/*'
236
256
 
237
257
  Rails/BelongsTo:
238
258
  Description: >-
@@ -291,8 +311,8 @@ Rails/ContentTag:
291
311
  # https://puma.io/puma/Puma/DSL.html#tag-instance_method
292
312
  # No helpers are used in normal models and configs.
293
313
  Exclude:
294
- - app/models/**/*.rb
295
- - config/**/*.rb
314
+ - '**/app/models/**/*.rb'
315
+ - '**/config/**/*.rb'
296
316
 
297
317
  Rails/CreateTableWithTimestamps:
298
318
  Description: >-
@@ -347,11 +367,13 @@ Rails/Delegate:
347
367
  Description: 'Prefer delegate method for delegations.'
348
368
  Enabled: true
349
369
  VersionAdded: '0.21'
350
- VersionChanged: '0.50'
370
+ VersionChanged: '2.30'
351
371
  # When set to true, using the target object as a prefix of the
352
372
  # method name without using the `delegate` method will be a
353
373
  # violation. When set to false, this case is legal.
354
374
  EnforceForPrefixed: true
375
+ Exclude:
376
+ - '**/app/controllers/**/*.rb'
355
377
 
356
378
  Rails/DelegateAllowBlank:
357
379
  Description: 'Do not use allow_blank as an option to delegate.'
@@ -422,14 +444,22 @@ Rails/EnumHash:
422
444
  Enabled: true
423
445
  VersionAdded: '2.3'
424
446
  Include:
425
- - app/models/**/*.rb
447
+ - '**/app/models/**/*.rb'
448
+
449
+ Rails/EnumSyntax:
450
+ Description: 'Use positional arguments over keyword arguments when defining enums.'
451
+ Enabled: pending
452
+ Severity: warning
453
+ VersionAdded: '2.26'
454
+ Include:
455
+ - '**/app/models/**/*.rb'
426
456
 
427
457
  Rails/EnumUniqueness:
428
458
  Description: 'Avoid duplicate integers in hash-syntax `enum` declaration.'
429
459
  Enabled: true
430
460
  VersionAdded: '0.46'
431
461
  Include:
432
- - app/models/**/*.rb
462
+ - '**/app/models/**/*.rb'
433
463
 
434
464
  Rails/EnvLocal:
435
465
  Description: 'Use `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`.'
@@ -448,11 +478,11 @@ Rails/EnvironmentVariableAccess:
448
478
  VersionAdded: '2.10'
449
479
  VersionChanged: '2.24'
450
480
  Include:
451
- - app/**/*.rb
452
- - config/initializers/**/*.rb
453
- - lib/**/*.rb
481
+ - '**/app/**/*.rb'
482
+ - '**/config/initializers/**/*.rb'
483
+ - '**/lib/**/*.rb'
454
484
  Exclude:
455
- - lib/**/*.rake
485
+ - '**/lib/**/*.rake'
456
486
  AllowReads: false
457
487
  AllowWrites: false
458
488
 
@@ -464,11 +494,11 @@ Rails/Exit:
464
494
  Enabled: true
465
495
  VersionAdded: '0.41'
466
496
  Include:
467
- - app/**/*.rb
468
- - config/**/*.rb
469
- - lib/**/*.rb
497
+ - '**/app/**/*.rb'
498
+ - '**/config/**/*.rb'
499
+ - '**/lib/**/*.rb'
470
500
  Exclude:
471
- - lib/**/*.rake
501
+ - '**/lib/**/*.rake'
472
502
 
473
503
  Rails/ExpandedDateRange:
474
504
  Description: 'Checks for expanded date range.'
@@ -530,7 +560,7 @@ Rails/HasAndBelongsToMany:
530
560
  Enabled: true
531
561
  VersionAdded: '0.12'
532
562
  Include:
533
- - app/models/**/*.rb
563
+ - '**/app/models/**/*.rb'
534
564
 
535
565
  Rails/HasManyOrHasOneDependent:
536
566
  Description: 'Define the dependent option to the has_many and has_one associations.'
@@ -538,14 +568,14 @@ Rails/HasManyOrHasOneDependent:
538
568
  Enabled: true
539
569
  VersionAdded: '0.50'
540
570
  Include:
541
- - app/models/**/*.rb
571
+ - '**/app/models/**/*.rb'
542
572
 
543
573
  Rails/HelperInstanceVariable:
544
574
  Description: 'Do not use instance variables in helpers.'
545
575
  Enabled: true
546
576
  VersionAdded: '2.0'
547
577
  Include:
548
- - app/helpers/**/*.rb
578
+ - '**/app/helpers/**/*.rb'
549
579
 
550
580
  Rails/HttpPositionalArguments:
551
581
  Description: 'Use keyword arguments instead of positional arguments in http method calls.'
@@ -576,7 +606,7 @@ Rails/I18nLazyLookup:
576
606
  - lazy
577
607
  - explicit
578
608
  Include:
579
- - 'app/controllers/**/*.rb'
609
+ - '**/app/controllers/**/*.rb'
580
610
 
581
611
  Rails/I18nLocaleAssignment:
582
612
  Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
@@ -605,8 +635,8 @@ Rails/IgnoredSkipActionFilterOption:
605
635
  Enabled: true
606
636
  VersionAdded: '0.63'
607
637
  Include:
608
- - app/controllers/**/*.rb
609
- - app/mailers/**/*.rb
638
+ - '**/app/controllers/**/*.rb'
639
+ - '**/app/mailers/**/*.rb'
610
640
 
611
641
  Rails/IndexBy:
612
642
  Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
@@ -635,7 +665,7 @@ Rails/InverseOf:
635
665
  VersionAdded: '0.52'
636
666
  IgnoreScopes: false
637
667
  Include:
638
- - app/models/**/*.rb
668
+ - '**/app/models/**/*.rb'
639
669
 
640
670
  Rails/LexicallyScopedActionFilter:
641
671
  Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
@@ -644,8 +674,8 @@ Rails/LexicallyScopedActionFilter:
644
674
  Safe: false
645
675
  VersionAdded: '0.52'
646
676
  Include:
647
- - app/controllers/**/*.rb
648
- - app/mailers/**/*.rb
677
+ - '**/app/controllers/**/*.rb'
678
+ - '**/app/mailers/**/*.rb'
649
679
 
650
680
  Rails/LinkToBlank:
651
681
  Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
@@ -663,7 +693,7 @@ Rails/MailerName:
663
693
  SafeAutoCorrect: false
664
694
  VersionAdded: '2.7'
665
695
  Include:
666
- - app/mailers/**/*.rb
696
+ - '**/app/mailers/**/*.rb'
667
697
 
668
698
  Rails/MatchRoute:
669
699
  Description: >-
@@ -673,8 +703,8 @@ Rails/MatchRoute:
673
703
  Enabled: 'pending'
674
704
  VersionAdded: '2.7'
675
705
  Include:
676
- - config/routes.rb
677
- - config/routes/**/*.rb
706
+ - '**/config/routes.rb'
707
+ - '**/config/routes/**/*.rb'
678
708
 
679
709
  Rails/MigrationClassName:
680
710
  Description: 'The class name of the migration should match its file name.'
@@ -684,6 +714,15 @@ Rails/MigrationClassName:
684
714
  Include:
685
715
  - db/**/*.rb
686
716
 
717
+ Rails/MultipleRoutePaths:
718
+ Description: 'Checks for mapping a route with multiple paths, which is deprecated and will be removed in Rails 8.1.'
719
+ Enabled: pending
720
+ Severity: warning
721
+ VersionAdded: '2.29'
722
+ Include:
723
+ - '**/config/routes.rb'
724
+ - '**/config/routes/**/*.rb'
725
+
687
726
  Rails/NegateInclude:
688
727
  Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
689
728
  StyleGuide: 'https://rails.rubystyle.guide#exclude'
@@ -718,10 +757,10 @@ Rails/Output:
718
757
  VersionAdded: '0.15'
719
758
  VersionChanged: '0.19'
720
759
  Include:
721
- - app/**/*.rb
722
- - config/**/*.rb
760
+ - '**/app/**/*.rb'
761
+ - '**/config/**/*.rb'
723
762
  - db/**/*.rb
724
- - lib/**/*.rb
763
+ - '**/lib/**/*.rb'
725
764
 
726
765
  Rails/OutputSafety:
727
766
  Description: 'The use of `html_safe` or `raw` may be a security risk.'
@@ -793,7 +832,7 @@ Rails/RakeEnvironment:
793
832
  - '**/Rakefile'
794
833
  - '**/*.rake'
795
834
  Exclude:
796
- - 'lib/capistrano/tasks/**/*.rake'
835
+ - '**/lib/capistrano/tasks/**/*.rake'
797
836
 
798
837
  Rails/ReadWriteAttribute:
799
838
  Description: >-
@@ -804,7 +843,7 @@ Rails/ReadWriteAttribute:
804
843
  VersionAdded: '0.20'
805
844
  VersionChanged: '0.29'
806
845
  Include:
807
- - app/models/**/*.rb
846
+ - '**/app/models/**/*.rb'
808
847
 
809
848
  Rails/RedundantActiveRecordAllMethod:
810
849
  Description: Detect redundant `all` used as a receiver for Active Record query methods.
@@ -823,7 +862,7 @@ Rails/RedundantAllowNil:
823
862
  Enabled: true
824
863
  VersionAdded: '0.67'
825
864
  Include:
826
- - app/models/**/*.rb
865
+ - '**/app/models/**/*.rb'
827
866
 
828
867
  Rails/RedundantForeignKey:
829
868
  Description: 'Checks for associations where the `:foreign_key` option is redundant.'
@@ -994,7 +1033,7 @@ Rails/ScopeArgs:
994
1033
  VersionAdded: '0.19'
995
1034
  VersionChanged: '2.12'
996
1035
  Include:
997
- - app/models/**/*.rb
1036
+ - '**/app/models/**/*.rb'
998
1037
 
999
1038
  Rails/SelectMap:
1000
1039
  Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
@@ -1058,6 +1097,15 @@ Rails/StripHeredoc:
1058
1097
  Enabled: pending
1059
1098
  VersionAdded: '2.15'
1060
1099
 
1100
+ Rails/StrongParametersExpect:
1101
+ Description: 'Enforces the use of `ActionController::Parameters#expect` as a method for strong parameter handling.'
1102
+ Reference: 'https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect'
1103
+ Enabled: pending
1104
+ Include:
1105
+ - '**/app/controllers/**/*.rb'
1106
+ SafeAutoCorrect: false
1107
+ VersionAdded: '2.29'
1108
+
1061
1109
  Rails/TableNameAssignment:
1062
1110
  Description: >-
1063
1111
  Do not use `self.table_name =`. Use Inflections or `table_name_prefix` instead.
@@ -1065,7 +1113,7 @@ Rails/TableNameAssignment:
1065
1113
  Enabled: false
1066
1114
  VersionAdded: '2.14'
1067
1115
  Include:
1068
- - app/models/**/*.rb
1116
+ - '**/app/models/**/*.rb'
1069
1117
 
1070
1118
  Rails/ThreeStateBooleanColumn:
1071
1119
  Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
@@ -1149,7 +1197,7 @@ Rails/UniqueValidationWithoutIndex:
1149
1197
  Enabled: true
1150
1198
  VersionAdded: '2.5'
1151
1199
  Include:
1152
- - app/models/**/*.rb
1200
+ - '**/app/models/**/*.rb'
1153
1201
 
1154
1202
  Rails/UnknownEnv:
1155
1203
  Description: 'Use correct environment name.'
@@ -1168,7 +1216,7 @@ Rails/UnusedIgnoredColumns:
1168
1216
  VersionAdded: '2.11'
1169
1217
  VersionChanged: '2.25'
1170
1218
  Include:
1171
- - app/models/**/*.rb
1219
+ - '**/app/models/**/*.rb'
1172
1220
 
1173
1221
  Rails/UnusedRenderContent:
1174
1222
  Description: 'Do not specify body content for a response with a non-content status code.'
@@ -1182,15 +1230,15 @@ Rails/Validation:
1182
1230
  VersionAdded: '0.9'
1183
1231
  VersionChanged: '0.41'
1184
1232
  Include:
1185
- - app/models/**/*.rb
1233
+ - '**/app/models/**/*.rb'
1186
1234
 
1187
1235
  Rails/WhereEquals:
1188
- Description: 'Pass conditions to `where` as a hash instead of manually constructing SQL.'
1236
+ Description: 'Pass conditions to `where` and `where.not` as a hash instead of manually constructing SQL.'
1189
1237
  StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions'
1190
1238
  Enabled: 'pending'
1191
1239
  SafeAutoCorrect: false
1192
1240
  VersionAdded: '2.9'
1193
- VersionChanged: '2.10'
1241
+ VersionChanged: '2.26'
1194
1242
 
1195
1243
  Rails/WhereExists:
1196
1244
  Description: 'Prefer `exists?(...)` over `where(...).exists?`.'
@@ -1234,6 +1282,10 @@ Rails/WhereRange:
1234
1282
  Style/AndOr:
1235
1283
  EnforcedStyle: conditionals
1236
1284
 
1285
+ Style/CollectionCompact:
1286
+ AllowedReceivers:
1287
+ - params
1288
+
1237
1289
  Style/FormatStringToken:
1238
1290
  AllowedMethods:
1239
1291
  - redirect
@@ -87,7 +87,7 @@ module RuboCop
87
87
 
88
88
  options.each_pair.find do |pair|
89
89
  next unless pair.key.sym_type? && pair.key.value == :foreign_key
90
- next unless pair.value.sym_type? || pair.value.str_type?
90
+ next unless pair.value.type?(:sym, :str)
91
91
 
92
92
  break pair.value.value.to_s
93
93
  end
@@ -103,7 +103,7 @@ module RuboCop
103
103
  end
104
104
 
105
105
  def in_where?(node)
106
- send_node = node.each_ancestor(:send, :csend).first
106
+ send_node = node.each_ancestor(:call).first
107
107
  return false unless send_node
108
108
 
109
109
  return true if WHERE_METHODS.include?(send_node.method_name)
@@ -22,9 +22,9 @@ module RuboCop
22
22
  ].freeze
23
23
 
24
24
  def_node_matcher :create_table_with_block?, <<~PATTERN
25
- (block
25
+ (any_block
26
26
  (send nil? :create_table ...)
27
- (args (arg _var))
27
+ { _ | (args (arg _var)) }
28
28
  _)
29
29
  PATTERN
30
30
  end
@@ -29,8 +29,8 @@ module RuboCop
29
29
  end
30
30
 
31
31
  def database_from_env
32
- url = ENV['DATABASE_URL'].presence
33
- return unless url
32
+ url = ENV.fetch('DATABASE_URL', '')
33
+ return if url.blank?
34
34
 
35
35
  case url
36
36
  when %r{\A(mysql2|trilogy)://}
@@ -1,7 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RuboCop
4
- module Cop
4
+ module Cop # rubocop:disable Style/Documentation
5
+ # The EnforceSuperclass module is also defined in `rubocop` (for backwards
6
+ # compatibility), so here we remove it before (re)defining it, to avoid
7
+ # warnings about methods in the module being redefined.
8
+ remove_const(:EnforceSuperclass) if defined?(EnforceSuperclass)
9
+
5
10
  # Common functionality for enforcing a specific superclass.
6
11
  module EnforceSuperclass
7
12
  def self.included(base)