rubocop-rails 2.31.0 → 2.35.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.
- checksums.yaml +4 -4
- data/LICENSE.txt +1 -1
- data/config/default.yml +106 -62
- data/lib/rubocop/cop/mixin/active_record_helper.rb +1 -1
- data/lib/rubocop/cop/mixin/database_type_resolvable.rb +3 -3
- data/lib/rubocop/cop/mixin/index_method.rb +4 -0
- data/lib/rubocop/cop/mixin/target_rails_version.rb +7 -17
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +4 -2
- data/lib/rubocop/cop/rails/action_filter.rb +1 -1
- data/lib/rubocop/cop/rails/delegate.rb +4 -4
- data/lib/rubocop/cop/rails/duplicate_association.rb +1 -1
- data/lib/rubocop/cop/rails/duplicate_scope.rb +2 -2
- data/lib/rubocop/cop/rails/env.rb +57 -0
- data/lib/rubocop/cop/rails/env_local.rb +50 -26
- data/lib/rubocop/cop/rails/environment_comparison.rb +56 -48
- data/lib/rubocop/cop/rails/exit.rb +7 -4
- data/lib/rubocop/cop/rails/file_path.rb +2 -2
- data/lib/rubocop/cop/rails/find_by.rb +1 -1
- data/lib/rubocop/cop/rails/find_by_or_assignment_memoization.rb +124 -0
- data/lib/rubocop/cop/rails/helper_instance_variable.rb +16 -17
- data/lib/rubocop/cop/rails/http_status_name_consistency.rb +80 -0
- data/lib/rubocop/cop/rails/i18n_locale_texts.rb +24 -2
- data/lib/rubocop/cop/rails/index_with.rb +5 -0
- data/lib/rubocop/cop/rails/inverse_of.rb +7 -0
- data/lib/rubocop/cop/rails/not_null_column.rb +2 -0
- data/lib/rubocop/cop/rails/order_arguments.rb +84 -0
- data/lib/rubocop/cop/rails/output.rb +3 -0
- data/lib/rubocop/cop/rails/output_safety.rb +3 -1
- data/lib/rubocop/cop/rails/pluck.rb +6 -3
- data/lib/rubocop/cop/rails/presence.rb +76 -20
- data/lib/rubocop/cop/rails/rake_environment.rb +1 -1
- data/lib/rubocop/cop/rails/read_write_attribute.rb +1 -1
- data/lib/rubocop/cop/rails/redirect_back_or_to.rb +99 -0
- data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +3 -3
- data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +1 -1
- data/lib/rubocop/cop/rails/response_parsed_body.rb +59 -50
- data/lib/rubocop/cop/rails/save_bang.rb +2 -2
- data/lib/rubocop/cop/rails/schema_comment.rb +1 -1
- data/lib/rubocop/cop/rails/select_map.rb +26 -4
- data/lib/rubocop/cop/rails/strong_parameters_expect.rb +71 -1
- data/lib/rubocop/cop/rails/three_state_boolean_column.rb +1 -1
- data/lib/rubocop/cop/rails/time_zone.rb +3 -1
- data/lib/rubocop/cop/rails/transaction_exit_statement.rb +4 -1
- data/lib/rubocop/cop/rails/unknown_env.rb +39 -12
- data/lib/rubocop/cop/rails/where_exists.rb +5 -5
- data/lib/rubocop/cop/rails_cops.rb +5 -0
- data/lib/rubocop/rails/version.rb +1 -1
- metadata +11 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e4946e79ccf9661248df014d69703665df3b0a72aa800e8c456afc59594ad944
|
|
4
|
+
data.tar.gz: 7575ea946eb4e6985d6c0c365a0f39345fc6d32b0634c74949526f987d1ac38d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7a660eb16537b1dafe092cb100229fd9f039f8d98b51e1408b9438997176c8fc0fde61494ae462bfa8ea15e65524f5ec99e4d2efac42d0461395da65bfe8cb8b
|
|
7
|
+
data.tar.gz: ad601bb6b3296dceb196159604975b5e2efecaca5c66f715523368344f8a77e62d93cf8e22c4b3d53ce67d849a34cf9a1f4d184d6b655ecea0f12da23490bb35
|
data/LICENSE.txt
CHANGED
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
|
|
@@ -91,6 +91,12 @@ Lint/UselessAccessModifier:
|
|
|
91
91
|
- concern
|
|
92
92
|
- concerning
|
|
93
93
|
|
|
94
|
+
Lint/UselessMethodDefinition:
|
|
95
|
+
# Avoids conflict with `Rails/LexicallyScopedActionFilter` cop.
|
|
96
|
+
Exclude:
|
|
97
|
+
- '**/app/controllers/**/*.rb'
|
|
98
|
+
- '**/app/mailers/**/*.rb'
|
|
99
|
+
|
|
94
100
|
Rails:
|
|
95
101
|
Enabled: true
|
|
96
102
|
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
|
|
@@ -121,8 +127,8 @@ Rails/ActionFilter:
|
|
|
121
127
|
- action
|
|
122
128
|
- filter
|
|
123
129
|
Include:
|
|
124
|
-
- app/controllers/**/*.rb
|
|
125
|
-
- app/mailers/**/*.rb
|
|
130
|
+
- '**/app/controllers/**/*.rb'
|
|
131
|
+
- '**/app/mailers/**/*.rb'
|
|
126
132
|
|
|
127
133
|
Rails/ActionOrder:
|
|
128
134
|
Description: 'Enforce consistent ordering of controller actions.'
|
|
@@ -137,7 +143,7 @@ Rails/ActionOrder:
|
|
|
137
143
|
- update
|
|
138
144
|
- destroy
|
|
139
145
|
Include:
|
|
140
|
-
- app/controllers/**/*.rb
|
|
146
|
+
- '**/app/controllers/**/*.rb'
|
|
141
147
|
|
|
142
148
|
Rails/ActiveRecordAliases:
|
|
143
149
|
Description: >-
|
|
@@ -154,7 +160,7 @@ Rails/ActiveRecordCallbacksOrder:
|
|
|
154
160
|
Enabled: 'pending'
|
|
155
161
|
VersionAdded: '2.7'
|
|
156
162
|
Include:
|
|
157
|
-
- app/models/**/*.rb
|
|
163
|
+
- '**/app/models/**/*.rb'
|
|
158
164
|
|
|
159
165
|
Rails/ActiveRecordOverride:
|
|
160
166
|
Description: >-
|
|
@@ -165,7 +171,7 @@ Rails/ActiveRecordOverride:
|
|
|
165
171
|
VersionAdded: '0.67'
|
|
166
172
|
VersionChanged: '2.18'
|
|
167
173
|
Include:
|
|
168
|
-
- app/models/**/*.rb
|
|
174
|
+
- '**/app/models/**/*.rb'
|
|
169
175
|
|
|
170
176
|
Rails/ActiveSupportAliases:
|
|
171
177
|
Description: >-
|
|
@@ -252,7 +258,7 @@ Rails/AttributeDefaultBlockValue:
|
|
|
252
258
|
Enabled: pending
|
|
253
259
|
VersionAdded: '2.9'
|
|
254
260
|
Include:
|
|
255
|
-
- 'app/models/**/*'
|
|
261
|
+
- '**/app/models/**/*'
|
|
256
262
|
|
|
257
263
|
Rails/BelongsTo:
|
|
258
264
|
Description: >-
|
|
@@ -311,8 +317,8 @@ Rails/ContentTag:
|
|
|
311
317
|
# https://puma.io/puma/Puma/DSL.html#tag-instance_method
|
|
312
318
|
# No helpers are used in normal models and configs.
|
|
313
319
|
Exclude:
|
|
314
|
-
- app/models/**/*.rb
|
|
315
|
-
- config/**/*.rb
|
|
320
|
+
- '**/app/models/**/*.rb'
|
|
321
|
+
- '**/config/**/*.rb'
|
|
316
322
|
|
|
317
323
|
Rails/CreateTableWithTimestamps:
|
|
318
324
|
Description: >-
|
|
@@ -373,7 +379,7 @@ Rails/Delegate:
|
|
|
373
379
|
# violation. When set to false, this case is legal.
|
|
374
380
|
EnforceForPrefixed: true
|
|
375
381
|
Exclude:
|
|
376
|
-
- app/controllers/**/*.rb
|
|
382
|
+
- '**/app/controllers/**/*.rb'
|
|
377
383
|
|
|
378
384
|
Rails/DelegateAllowBlank:
|
|
379
385
|
Description: 'Do not use allow_blank as an option to delegate.'
|
|
@@ -402,7 +408,7 @@ Rails/DuplicateAssociation:
|
|
|
402
408
|
VersionChanged: '2.18'
|
|
403
409
|
|
|
404
410
|
Rails/DuplicateScope:
|
|
405
|
-
Description: 'Multiple scopes share this same
|
|
411
|
+
Description: 'Multiple scopes share this same expression.'
|
|
406
412
|
Enabled: pending
|
|
407
413
|
Severity: warning
|
|
408
414
|
VersionAdded: '2.14'
|
|
@@ -444,7 +450,7 @@ Rails/EnumHash:
|
|
|
444
450
|
Enabled: true
|
|
445
451
|
VersionAdded: '2.3'
|
|
446
452
|
Include:
|
|
447
|
-
- app/models/**/*.rb
|
|
453
|
+
- '**/app/models/**/*.rb'
|
|
448
454
|
|
|
449
455
|
Rails/EnumSyntax:
|
|
450
456
|
Description: 'Use positional arguments over keyword arguments when defining enums.'
|
|
@@ -452,14 +458,20 @@ Rails/EnumSyntax:
|
|
|
452
458
|
Severity: warning
|
|
453
459
|
VersionAdded: '2.26'
|
|
454
460
|
Include:
|
|
455
|
-
- app/models/**/*.rb
|
|
461
|
+
- '**/app/models/**/*.rb'
|
|
462
|
+
- '**/lib/**/*.rb'
|
|
456
463
|
|
|
457
464
|
Rails/EnumUniqueness:
|
|
458
465
|
Description: 'Avoid duplicate integers in hash-syntax `enum` declaration.'
|
|
459
466
|
Enabled: true
|
|
460
467
|
VersionAdded: '0.46'
|
|
461
468
|
Include:
|
|
462
|
-
- app/models/**/*.rb
|
|
469
|
+
- '**/app/models/**/*.rb'
|
|
470
|
+
|
|
471
|
+
Rails/Env:
|
|
472
|
+
Description: 'Use Feature Flags or config instead of `Rails.env`.'
|
|
473
|
+
Enabled: false
|
|
474
|
+
VersionAdded: '2.34'
|
|
463
475
|
|
|
464
476
|
Rails/EnvLocal:
|
|
465
477
|
Description: 'Use `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`.'
|
|
@@ -478,11 +490,11 @@ Rails/EnvironmentVariableAccess:
|
|
|
478
490
|
VersionAdded: '2.10'
|
|
479
491
|
VersionChanged: '2.24'
|
|
480
492
|
Include:
|
|
481
|
-
- app/**/*.rb
|
|
482
|
-
- config/initializers/**/*.rb
|
|
483
|
-
- lib/**/*.rb
|
|
493
|
+
- '**/app/**/*.rb'
|
|
494
|
+
- '**/config/initializers/**/*.rb'
|
|
495
|
+
- '**/lib/**/*.rb'
|
|
484
496
|
Exclude:
|
|
485
|
-
- lib/**/*.rake
|
|
497
|
+
- '**/lib/**/*.rake'
|
|
486
498
|
AllowReads: false
|
|
487
499
|
AllowWrites: false
|
|
488
500
|
|
|
@@ -494,11 +506,11 @@ Rails/Exit:
|
|
|
494
506
|
Enabled: true
|
|
495
507
|
VersionAdded: '0.41'
|
|
496
508
|
Include:
|
|
497
|
-
- app/**/*.rb
|
|
498
|
-
- config/**/*.rb
|
|
499
|
-
- lib/**/*.rb
|
|
509
|
+
- '**/app/**/*.rb'
|
|
510
|
+
- '**/config/**/*.rb'
|
|
511
|
+
- '**/lib/**/*.rb'
|
|
500
512
|
Exclude:
|
|
501
|
-
- lib/**/*.rake
|
|
513
|
+
- '**/lib/**/*.rake'
|
|
502
514
|
|
|
503
515
|
Rails/ExpandedDateRange:
|
|
504
516
|
Description: 'Checks for expanded date range.'
|
|
@@ -532,6 +544,13 @@ Rails/FindById:
|
|
|
532
544
|
Enabled: 'pending'
|
|
533
545
|
VersionAdded: '2.7'
|
|
534
546
|
|
|
547
|
+
Rails/FindByOrAssignmentMemoization:
|
|
548
|
+
Description: 'Avoid memoizing `find_by` results with `||=`.'
|
|
549
|
+
StyleGuide: 'https://rails.rubystyle.guide/#find-by-memoization'
|
|
550
|
+
Enabled: pending
|
|
551
|
+
Safe: false
|
|
552
|
+
VersionAdded: '2.33'
|
|
553
|
+
|
|
535
554
|
Rails/FindEach:
|
|
536
555
|
Description: 'Prefer all.find_each over all.each.'
|
|
537
556
|
StyleGuide: 'https://rails.rubystyle.guide#find-each'
|
|
@@ -560,7 +579,7 @@ Rails/HasAndBelongsToMany:
|
|
|
560
579
|
Enabled: true
|
|
561
580
|
VersionAdded: '0.12'
|
|
562
581
|
Include:
|
|
563
|
-
- app/models/**/*.rb
|
|
582
|
+
- '**/app/models/**/*.rb'
|
|
564
583
|
|
|
565
584
|
Rails/HasManyOrHasOneDependent:
|
|
566
585
|
Description: 'Define the dependent option to the has_many and has_one associations.'
|
|
@@ -568,22 +587,22 @@ Rails/HasManyOrHasOneDependent:
|
|
|
568
587
|
Enabled: true
|
|
569
588
|
VersionAdded: '0.50'
|
|
570
589
|
Include:
|
|
571
|
-
- app/models/**/*.rb
|
|
590
|
+
- '**/app/models/**/*.rb'
|
|
572
591
|
|
|
573
592
|
Rails/HelperInstanceVariable:
|
|
574
593
|
Description: 'Do not use instance variables in helpers.'
|
|
575
594
|
Enabled: true
|
|
576
595
|
VersionAdded: '2.0'
|
|
577
596
|
Include:
|
|
578
|
-
- app/helpers/**/*.rb
|
|
597
|
+
- '**/app/helpers/**/*.rb'
|
|
579
598
|
|
|
580
599
|
Rails/HttpPositionalArguments:
|
|
581
600
|
Description: 'Use keyword arguments instead of positional arguments in http method calls.'
|
|
582
601
|
Enabled: true
|
|
583
602
|
VersionAdded: '0.44'
|
|
584
603
|
Include:
|
|
585
|
-
- 'spec/**/*'
|
|
586
|
-
- 'test/**/*'
|
|
604
|
+
- '**/spec/**/*'
|
|
605
|
+
- '**/test/**/*'
|
|
587
606
|
|
|
588
607
|
Rails/HttpStatus:
|
|
589
608
|
Description: 'Enforces use of symbolic or numeric value to define HTTP status.'
|
|
@@ -595,6 +614,14 @@ Rails/HttpStatus:
|
|
|
595
614
|
- numeric
|
|
596
615
|
- symbolic
|
|
597
616
|
|
|
617
|
+
Rails/HttpStatusNameConsistency:
|
|
618
|
+
Description: 'Enforces consistency by using the current HTTP status names.'
|
|
619
|
+
Enabled: pending
|
|
620
|
+
Severity: warning
|
|
621
|
+
VersionAdded: '2.34'
|
|
622
|
+
Include:
|
|
623
|
+
- '**/app/controllers/**/*.rb'
|
|
624
|
+
|
|
598
625
|
Rails/I18nLazyLookup:
|
|
599
626
|
Description: 'Checks for places where I18n "lazy" lookup can be used.'
|
|
600
627
|
StyleGuide: 'https://rails.rubystyle.guide/#lazy-lookup'
|
|
@@ -606,15 +633,15 @@ Rails/I18nLazyLookup:
|
|
|
606
633
|
- lazy
|
|
607
634
|
- explicit
|
|
608
635
|
Include:
|
|
609
|
-
- 'app/controllers/**/*.rb'
|
|
636
|
+
- '**/app/controllers/**/*.rb'
|
|
610
637
|
|
|
611
638
|
Rails/I18nLocaleAssignment:
|
|
612
639
|
Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
|
|
613
640
|
Enabled: 'pending'
|
|
614
641
|
VersionAdded: '2.11'
|
|
615
642
|
Include:
|
|
616
|
-
- spec/**/*.rb
|
|
617
|
-
- test/**/*.rb
|
|
643
|
+
- '**/spec/**/*.rb'
|
|
644
|
+
- '**/test/**/*.rb'
|
|
618
645
|
|
|
619
646
|
Rails/I18nLocaleTexts:
|
|
620
647
|
Description: 'Enforces use of I18n and locale files instead of locale specific strings.'
|
|
@@ -635,8 +662,8 @@ Rails/IgnoredSkipActionFilterOption:
|
|
|
635
662
|
Enabled: true
|
|
636
663
|
VersionAdded: '0.63'
|
|
637
664
|
Include:
|
|
638
|
-
- app/controllers/**/*.rb
|
|
639
|
-
- app/mailers/**/*.rb
|
|
665
|
+
- '**/app/controllers/**/*.rb'
|
|
666
|
+
- '**/app/mailers/**/*.rb'
|
|
640
667
|
|
|
641
668
|
Rails/IndexBy:
|
|
642
669
|
Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
|
|
@@ -647,8 +674,9 @@ Rails/IndexBy:
|
|
|
647
674
|
Rails/IndexWith:
|
|
648
675
|
Description: 'Prefer `index_with` over `each_with_object`, `to_h`, or `map`.'
|
|
649
676
|
Enabled: true
|
|
677
|
+
SafeAutoCorrect: false
|
|
650
678
|
VersionAdded: '2.5'
|
|
651
|
-
VersionChanged: '2.
|
|
679
|
+
VersionChanged: '2.33'
|
|
652
680
|
|
|
653
681
|
Rails/Inquiry:
|
|
654
682
|
Description: "Prefer Ruby's comparison operators over Active Support's `Array#inquiry` and `String#inquiry`."
|
|
@@ -665,7 +693,7 @@ Rails/InverseOf:
|
|
|
665
693
|
VersionAdded: '0.52'
|
|
666
694
|
IgnoreScopes: false
|
|
667
695
|
Include:
|
|
668
|
-
- app/models/**/*.rb
|
|
696
|
+
- '**/app/models/**/*.rb'
|
|
669
697
|
|
|
670
698
|
Rails/LexicallyScopedActionFilter:
|
|
671
699
|
Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
|
|
@@ -674,8 +702,8 @@ Rails/LexicallyScopedActionFilter:
|
|
|
674
702
|
Safe: false
|
|
675
703
|
VersionAdded: '0.52'
|
|
676
704
|
Include:
|
|
677
|
-
- app/controllers/**/*.rb
|
|
678
|
-
- app/mailers/**/*.rb
|
|
705
|
+
- '**/app/controllers/**/*.rb'
|
|
706
|
+
- '**/app/mailers/**/*.rb'
|
|
679
707
|
|
|
680
708
|
Rails/LinkToBlank:
|
|
681
709
|
Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
|
|
@@ -693,7 +721,7 @@ Rails/MailerName:
|
|
|
693
721
|
SafeAutoCorrect: false
|
|
694
722
|
VersionAdded: '2.7'
|
|
695
723
|
Include:
|
|
696
|
-
- app/mailers/**/*.rb
|
|
724
|
+
- '**/app/mailers/**/*.rb'
|
|
697
725
|
|
|
698
726
|
Rails/MatchRoute:
|
|
699
727
|
Description: >-
|
|
@@ -703,8 +731,8 @@ Rails/MatchRoute:
|
|
|
703
731
|
Enabled: 'pending'
|
|
704
732
|
VersionAdded: '2.7'
|
|
705
733
|
Include:
|
|
706
|
-
- config/routes.rb
|
|
707
|
-
- config/routes/**/*.rb
|
|
734
|
+
- '**/config/routes.rb'
|
|
735
|
+
- '**/config/routes/**/*.rb'
|
|
708
736
|
|
|
709
737
|
Rails/MigrationClassName:
|
|
710
738
|
Description: 'The class name of the migration should match its file name.'
|
|
@@ -720,8 +748,8 @@ Rails/MultipleRoutePaths:
|
|
|
720
748
|
Severity: warning
|
|
721
749
|
VersionAdded: '2.29'
|
|
722
750
|
Include:
|
|
723
|
-
- config/routes.rb
|
|
724
|
-
- config/routes/**/*.rb
|
|
751
|
+
- '**/config/routes.rb'
|
|
752
|
+
- '**/config/routes/**/*.rb'
|
|
725
753
|
|
|
726
754
|
Rails/NegateInclude:
|
|
727
755
|
Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
|
|
@@ -742,6 +770,13 @@ Rails/NotNullColumn:
|
|
|
742
770
|
Include:
|
|
743
771
|
- db/**/*.rb
|
|
744
772
|
|
|
773
|
+
Rails/OrderArguments:
|
|
774
|
+
Description: 'Prefer symbol arguments over strings in `order` method.'
|
|
775
|
+
StyleGuide: 'https://rails.rubystyle.guide/#order-arguments'
|
|
776
|
+
Enabled: pending
|
|
777
|
+
VersionAdded: '2.33'
|
|
778
|
+
Safe: false
|
|
779
|
+
|
|
745
780
|
Rails/OrderById:
|
|
746
781
|
Description: >-
|
|
747
782
|
Do not use the `id` column for ordering.
|
|
@@ -757,10 +792,10 @@ Rails/Output:
|
|
|
757
792
|
VersionAdded: '0.15'
|
|
758
793
|
VersionChanged: '0.19'
|
|
759
794
|
Include:
|
|
760
|
-
- app/**/*.rb
|
|
761
|
-
- config/**/*.rb
|
|
795
|
+
- '**/app/**/*.rb'
|
|
796
|
+
- '**/config/**/*.rb'
|
|
762
797
|
- db/**/*.rb
|
|
763
|
-
- lib/**/*.rb
|
|
798
|
+
- '**/lib/**/*.rb'
|
|
764
799
|
|
|
765
800
|
Rails/OutputSafety:
|
|
766
801
|
Description: 'The use of `html_safe` or `raw` may be a security risk.'
|
|
@@ -809,6 +844,7 @@ Rails/Presence:
|
|
|
809
844
|
Description: 'Checks code that can be written more easily using `Object#presence` defined by Active Support.'
|
|
810
845
|
Enabled: true
|
|
811
846
|
VersionAdded: '0.52'
|
|
847
|
+
VersionChanged: '2.34'
|
|
812
848
|
|
|
813
849
|
Rails/Present:
|
|
814
850
|
Description: 'Enforces use of `present?`.'
|
|
@@ -832,7 +868,7 @@ Rails/RakeEnvironment:
|
|
|
832
868
|
- '**/Rakefile'
|
|
833
869
|
- '**/*.rake'
|
|
834
870
|
Exclude:
|
|
835
|
-
- 'lib/capistrano/tasks/**/*.rake'
|
|
871
|
+
- '**/lib/capistrano/tasks/**/*.rake'
|
|
836
872
|
|
|
837
873
|
Rails/ReadWriteAttribute:
|
|
838
874
|
Description: >-
|
|
@@ -843,7 +879,15 @@ Rails/ReadWriteAttribute:
|
|
|
843
879
|
VersionAdded: '0.20'
|
|
844
880
|
VersionChanged: '0.29'
|
|
845
881
|
Include:
|
|
846
|
-
- app/models/**/*.rb
|
|
882
|
+
- '**/app/models/**/*.rb'
|
|
883
|
+
|
|
884
|
+
Rails/RedirectBackOrTo:
|
|
885
|
+
Description: >-
|
|
886
|
+
Use `redirect_back_or_to` instead of `redirect_back` with
|
|
887
|
+
`fallback_location` option.
|
|
888
|
+
Enabled: pending
|
|
889
|
+
Severity: warning
|
|
890
|
+
VersionAdded: '2.34'
|
|
847
891
|
|
|
848
892
|
Rails/RedundantActiveRecordAllMethod:
|
|
849
893
|
Description: Detect redundant `all` used as a receiver for Active Record query methods.
|
|
@@ -862,7 +906,7 @@ Rails/RedundantAllowNil:
|
|
|
862
906
|
Enabled: true
|
|
863
907
|
VersionAdded: '0.67'
|
|
864
908
|
Include:
|
|
865
|
-
- app/models/**/*.rb
|
|
909
|
+
- '**/app/models/**/*.rb'
|
|
866
910
|
|
|
867
911
|
Rails/RedundantForeignKey:
|
|
868
912
|
Description: 'Checks for associations where the `:foreign_key` option is redundant.'
|
|
@@ -885,8 +929,8 @@ Rails/RedundantTravelBack:
|
|
|
885
929
|
Enabled: pending
|
|
886
930
|
VersionAdded: '2.12'
|
|
887
931
|
Include:
|
|
888
|
-
- spec/**/*.rb
|
|
889
|
-
- test/**/*.rb
|
|
932
|
+
- '**/spec/**/*.rb'
|
|
933
|
+
- '**/test/**/*.rb'
|
|
890
934
|
|
|
891
935
|
Rails/ReflectionClassName:
|
|
892
936
|
Description: 'Use a string for `class_name` option value in the definition of a reflection.'
|
|
@@ -949,10 +993,10 @@ Rails/ResponseParsedBody:
|
|
|
949
993
|
VersionAdded: '2.18'
|
|
950
994
|
VersionChanged: '2.19'
|
|
951
995
|
Include:
|
|
952
|
-
- spec/controllers/**/*.rb
|
|
953
|
-
- spec/requests/**/*.rb
|
|
954
|
-
- test/controllers/**/*.rb
|
|
955
|
-
- test/integration/**/*.rb
|
|
996
|
+
- '**/spec/controllers/**/*.rb'
|
|
997
|
+
- '**/spec/requests/**/*.rb'
|
|
998
|
+
- '**/test/controllers/**/*.rb'
|
|
999
|
+
- '**/test/integration/**/*.rb'
|
|
956
1000
|
|
|
957
1001
|
Rails/ReversibleMigration:
|
|
958
1002
|
Description: 'Checks whether the change method of the migration file is reversible.'
|
|
@@ -1033,7 +1077,7 @@ Rails/ScopeArgs:
|
|
|
1033
1077
|
VersionAdded: '0.19'
|
|
1034
1078
|
VersionChanged: '2.12'
|
|
1035
1079
|
Include:
|
|
1036
|
-
- app/models/**/*.rb
|
|
1080
|
+
- '**/app/models/**/*.rb'
|
|
1037
1081
|
|
|
1038
1082
|
Rails/SelectMap:
|
|
1039
1083
|
Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
|
|
@@ -1102,7 +1146,7 @@ Rails/StrongParametersExpect:
|
|
|
1102
1146
|
Reference: 'https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect'
|
|
1103
1147
|
Enabled: pending
|
|
1104
1148
|
Include:
|
|
1105
|
-
- app/controllers/**/*.rb
|
|
1149
|
+
- '**/app/controllers/**/*.rb'
|
|
1106
1150
|
SafeAutoCorrect: false
|
|
1107
1151
|
VersionAdded: '2.29'
|
|
1108
1152
|
|
|
@@ -1113,7 +1157,7 @@ Rails/TableNameAssignment:
|
|
|
1113
1157
|
Enabled: false
|
|
1114
1158
|
VersionAdded: '2.14'
|
|
1115
1159
|
Include:
|
|
1116
|
-
- app/models/**/*.rb
|
|
1160
|
+
- '**/app/models/**/*.rb'
|
|
1117
1161
|
|
|
1118
1162
|
Rails/ThreeStateBooleanColumn:
|
|
1119
1163
|
Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
|
|
@@ -1126,7 +1170,7 @@ Rails/ThreeStateBooleanColumn:
|
|
|
1126
1170
|
Rails/TimeZone:
|
|
1127
1171
|
Description: 'Checks the correct usage of time zone aware methods.'
|
|
1128
1172
|
StyleGuide: 'https://rails.rubystyle.guide#time'
|
|
1129
|
-
Reference: '
|
|
1173
|
+
Reference: 'https://danilenko.org/2012/7/6/rails_timezones'
|
|
1130
1174
|
Enabled: true
|
|
1131
1175
|
SafeAutoCorrect: false
|
|
1132
1176
|
VersionAdded: '0.30'
|
|
@@ -1146,8 +1190,8 @@ Rails/TimeZoneAssignment:
|
|
|
1146
1190
|
Enabled: 'pending'
|
|
1147
1191
|
VersionAdded: '2.10'
|
|
1148
1192
|
Include:
|
|
1149
|
-
- spec/**/*.rb
|
|
1150
|
-
- test/**/*.rb
|
|
1193
|
+
- '**/spec/**/*.rb'
|
|
1194
|
+
- '**/test/**/*.rb'
|
|
1151
1195
|
|
|
1152
1196
|
Rails/ToFormattedS:
|
|
1153
1197
|
Description: 'Checks for consistent uses of `to_fs` or `to_formatted_s`.'
|
|
@@ -1197,7 +1241,7 @@ Rails/UniqueValidationWithoutIndex:
|
|
|
1197
1241
|
Enabled: true
|
|
1198
1242
|
VersionAdded: '2.5'
|
|
1199
1243
|
Include:
|
|
1200
|
-
- app/models/**/*.rb
|
|
1244
|
+
- '**/app/models/**/*.rb'
|
|
1201
1245
|
|
|
1202
1246
|
Rails/UnknownEnv:
|
|
1203
1247
|
Description: 'Use correct environment name.'
|
|
@@ -1216,7 +1260,7 @@ Rails/UnusedIgnoredColumns:
|
|
|
1216
1260
|
VersionAdded: '2.11'
|
|
1217
1261
|
VersionChanged: '2.25'
|
|
1218
1262
|
Include:
|
|
1219
|
-
- app/models/**/*.rb
|
|
1263
|
+
- '**/app/models/**/*.rb'
|
|
1220
1264
|
|
|
1221
1265
|
Rails/UnusedRenderContent:
|
|
1222
1266
|
Description: 'Do not specify body content for a response with a non-content status code.'
|
|
@@ -1230,7 +1274,7 @@ Rails/Validation:
|
|
|
1230
1274
|
VersionAdded: '0.9'
|
|
1231
1275
|
VersionChanged: '0.41'
|
|
1232
1276
|
Include:
|
|
1233
|
-
- app/models/**/*.rb
|
|
1277
|
+
- '**/app/models/**/*.rb'
|
|
1234
1278
|
|
|
1235
1279
|
Rails/WhereEquals:
|
|
1236
1280
|
Description: 'Pass conditions to `where` and `where.not` as a hash instead of manually constructing SQL.'
|
|
@@ -106,7 +106,7 @@ module RuboCop
|
|
|
106
106
|
send_node = node.each_ancestor(:call).first
|
|
107
107
|
return false unless send_node
|
|
108
108
|
|
|
109
|
-
return true if WHERE_METHODS.include?(send_node.method_name)
|
|
109
|
+
return true if WHERE_METHODS.include?(send_node.method_name) && send_node.receiver != node
|
|
110
110
|
|
|
111
111
|
receiver = send_node.receiver
|
|
112
112
|
return false unless receiver&.send_type?
|
|
@@ -40,7 +40,7 @@ module RuboCop
|
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
43
|
-
def database_yaml
|
|
43
|
+
def database_yaml(environment = 'development')
|
|
44
44
|
return unless File.exist?('config/database.yml')
|
|
45
45
|
|
|
46
46
|
yaml = if YAML.respond_to?(:unsafe_load_file)
|
|
@@ -50,7 +50,7 @@ module RuboCop
|
|
|
50
50
|
end
|
|
51
51
|
return unless yaml.is_a? Hash
|
|
52
52
|
|
|
53
|
-
config = yaml[
|
|
53
|
+
config = yaml[environment]
|
|
54
54
|
return unless config.is_a?(Hash)
|
|
55
55
|
|
|
56
56
|
config
|
|
@@ -59,7 +59,7 @@ module RuboCop
|
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
def database_adapter
|
|
62
|
-
database_yaml['adapter'] || database_yaml.first.last['adapter']
|
|
62
|
+
database_yaml['adapter'] || database_yaml('shared')&.dig('adapter') || database_yaml.first.last['adapter']
|
|
63
63
|
end
|
|
64
64
|
end
|
|
65
65
|
end
|
|
@@ -132,9 +132,13 @@ module RuboCop
|
|
|
132
132
|
add_offense(
|
|
133
133
|
node, message: "Prefer `#{new_method_name}` over `#{match_desc}`."
|
|
134
134
|
) do |corrector|
|
|
135
|
+
next if part_of_ignored_node?(node)
|
|
136
|
+
|
|
135
137
|
correction = prepare_correction(node)
|
|
136
138
|
execute_correction(corrector, node, correction)
|
|
137
139
|
end
|
|
140
|
+
|
|
141
|
+
ignore_node(node)
|
|
138
142
|
end
|
|
139
143
|
|
|
140
144
|
def extract_captures(match)
|
|
@@ -12,29 +12,19 @@ module RuboCop
|
|
|
12
12
|
TARGET_GEM_NAME = 'railties' # :nodoc:
|
|
13
13
|
|
|
14
14
|
def minimum_target_rails_version(version)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
when String then requires_gem(TARGET_GEM_NAME, version)
|
|
19
|
-
end
|
|
20
|
-
else
|
|
21
|
-
# Fallback path for previous versions of RuboCop which don't support the `requires_gem` API yet.
|
|
22
|
-
@minimum_target_rails_version = version
|
|
15
|
+
case version
|
|
16
|
+
when Integer, Float then requires_gem(TARGET_GEM_NAME, ">= #{version}")
|
|
17
|
+
when String then requires_gem(TARGET_GEM_NAME, version)
|
|
23
18
|
end
|
|
24
19
|
end
|
|
25
20
|
|
|
26
21
|
def support_target_rails_version?(version)
|
|
27
|
-
|
|
28
|
-
return false unless gem_requirements
|
|
22
|
+
return false unless gem_requirements
|
|
29
23
|
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
gem_requirement = gem_requirements[TARGET_GEM_NAME]
|
|
25
|
+
return true unless gem_requirement # If we have no requirement, then we support all versions
|
|
32
26
|
|
|
33
|
-
|
|
34
|
-
else
|
|
35
|
-
# Fallback path for previous versions of RuboCop which don't support the `requires_gem` API yet.
|
|
36
|
-
@minimum_target_rails_version <= version
|
|
37
|
-
end
|
|
27
|
+
gem_requirement.satisfied_by?(Gem::Version.new(version))
|
|
38
28
|
end
|
|
39
29
|
end
|
|
40
30
|
end
|
|
@@ -73,7 +73,7 @@ module RuboCop
|
|
|
73
73
|
return false if use_redirect_to?(context)
|
|
74
74
|
|
|
75
75
|
context = node
|
|
76
|
-
elsif context.right_siblings.empty?
|
|
76
|
+
elsif context.right_siblings.empty? && !use_redirect_to?(context.parent)
|
|
77
77
|
return true
|
|
78
78
|
end
|
|
79
79
|
context = context.right_siblings
|
|
@@ -98,7 +98,9 @@ module RuboCop
|
|
|
98
98
|
end
|
|
99
99
|
|
|
100
100
|
def use_redirect_to?(context)
|
|
101
|
-
context.right_siblings.
|
|
101
|
+
context.right_siblings.any? do |sibling|
|
|
102
|
+
next unless sibling.is_a?(AST::Node)
|
|
103
|
+
|
|
102
104
|
# Unwrap `return redirect_to :index`
|
|
103
105
|
sibling = sibling.children.first if sibling.return_type? && sibling.children.one?
|
|
104
106
|
sibling.send_type? && sibling.method?(:redirect_to)
|
|
@@ -72,7 +72,7 @@ module RuboCop
|
|
|
72
72
|
|
|
73
73
|
RESTRICT_ON_SEND = FILTER_METHODS + ACTION_METHODS
|
|
74
74
|
|
|
75
|
-
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler
|
|
75
|
+
def on_block(node) # rubocop:disable InternalAffairs/NumblockHandler, InternalAffairs/ItblockHandler
|
|
76
76
|
check_method_node(node.send_node)
|
|
77
77
|
end
|
|
78
78
|
|
|
@@ -76,7 +76,7 @@ module RuboCop
|
|
|
76
76
|
|
|
77
77
|
def on_def(node)
|
|
78
78
|
return unless trivial_delegate?(node)
|
|
79
|
-
return if private_or_protected_delegation(node)
|
|
79
|
+
return if private_or_protected_delegation?(node)
|
|
80
80
|
return if module_function_declared?(node)
|
|
81
81
|
|
|
82
82
|
register_offense(node)
|
|
@@ -163,8 +163,8 @@ module RuboCop
|
|
|
163
163
|
end
|
|
164
164
|
end
|
|
165
165
|
|
|
166
|
-
def private_or_protected_delegation(node)
|
|
167
|
-
private_or_protected_inline(node) || node_visibility(node) != :public
|
|
166
|
+
def private_or_protected_delegation?(node)
|
|
167
|
+
private_or_protected_inline?(node) || node_visibility(node) != :public
|
|
168
168
|
end
|
|
169
169
|
|
|
170
170
|
def module_function_declared?(node)
|
|
@@ -173,7 +173,7 @@ module RuboCop
|
|
|
173
173
|
end
|
|
174
174
|
end
|
|
175
175
|
|
|
176
|
-
def private_or_protected_inline(node)
|
|
176
|
+
def private_or_protected_inline?(node)
|
|
177
177
|
processed_source[node.first_line - 1].strip.match?(/\A(private )|(protected )/)
|
|
178
178
|
end
|
|
179
179
|
end
|
|
@@ -94,7 +94,7 @@ module RuboCop
|
|
|
94
94
|
filtered_nodes = association_nodes.reject { |node| node.method?(:belongs_to) }
|
|
95
95
|
grouped_associations = filtered_nodes.group_by do |node|
|
|
96
96
|
arguments = association(node).last
|
|
97
|
-
next unless arguments.
|
|
97
|
+
next unless arguments.one?
|
|
98
98
|
|
|
99
99
|
if (class_name = class_name(arguments.first))
|
|
100
100
|
class_name.source
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module RuboCop
|
|
4
4
|
module Cop
|
|
5
5
|
module Rails
|
|
6
|
-
# Checks for multiple scopes in a model that have the same
|
|
6
|
+
# Checks for multiple scopes in a model that have the same expression. This
|
|
7
7
|
# often means you copy/pasted a scope, updated the name, and forgot to change the condition.
|
|
8
8
|
#
|
|
9
9
|
# @example
|
|
@@ -19,7 +19,7 @@ module RuboCop
|
|
|
19
19
|
class DuplicateScope < Base
|
|
20
20
|
include ClassSendNodeHelper
|
|
21
21
|
|
|
22
|
-
MSG = 'Multiple scopes share this same
|
|
22
|
+
MSG = 'Multiple scopes share this same expression.'
|
|
23
23
|
|
|
24
24
|
def_node_matcher :scope, <<~PATTERN
|
|
25
25
|
(send nil? :scope _ $...)
|