rubocop-rails 2.30.2 → 2.34.3
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/README.md +2 -1
- data/config/default.yml +110 -50
- data/lib/rubocop/cop/mixin/active_record_helper.rb +2 -2
- data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +2 -2
- data/lib/rubocop/cop/mixin/database_type_resolvable.rb +2 -2
- data/lib/rubocop/cop/mixin/enforce_superclass.rb +6 -1
- data/lib/rubocop/cop/mixin/index_method.rb +6 -1
- data/lib/rubocop/cop/rails/action_controller_flash_before_render.rb +4 -2
- data/lib/rubocop/cop/rails/arel_star.rb +5 -5
- data/lib/rubocop/cop/rails/delegate.rb +7 -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/eager_evaluation_log_message.rb +1 -3
- 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/index_by.rb +9 -0
- data/lib/rubocop/cop/rails/index_with.rb +14 -0
- data/lib/rubocop/cop/rails/inverse_of.rb +7 -0
- data/lib/rubocop/cop/rails/order_arguments.rb +84 -0
- data/lib/rubocop/cop/rails/output.rb +4 -2
- data/lib/rubocop/cop/rails/output_safety.rb +3 -1
- data/lib/rubocop/cop/rails/pluck.rb +13 -4
- data/lib/rubocop/cop/rails/presence.rb +67 -18
- 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 +7 -2
- data/lib/rubocop/cop/rails/reflection_class_name.rb +2 -2
- data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
- data/lib/rubocop/cop/rails/reversible_migration.rb +2 -1
- data/lib/rubocop/cop/rails/save_bang.rb +4 -4
- data/lib/rubocop/cop/rails/schema_comment.rb +1 -1
- data/lib/rubocop/cop/rails/select_map.rb +12 -4
- 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 +5 -2
- data/lib/rubocop/cop/rails/uniq_before_pluck.rb +1 -1
- 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
- data/lib/rubocop-rails.rb +0 -1
- metadata +13 -8
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cceb6a56dba516cdc368294a42ff59397a70f758801e5a1285df315a9d4abc8f
|
|
4
|
+
data.tar.gz: 555f1da6ed7abe2a2be37867c5405abaa16007b77be36e68c67b2a79d11865c9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 25a1c6aecce64df1814142ee6a4a0dfb6014ddc9f7a4fdb4c9f59035277a63512163bab201202f9b90fcfbaeae6bf7c87479326f4415f853beaf6fd7c3e64486
|
|
7
|
+
data.tar.gz: 5eec318843c618ae00bf370ef17060d90b5978e427812a90d4b8f7015ab25af5a09a3adee9e973dd821a5ad67d4ba0f503af11a067ceb30a3e81823cfbab2b93
|
data/LICENSE.txt
CHANGED
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
|
-
|
|
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
|
|
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
|
|
@@ -77,6 +77,26 @@ Lint/SafeNavigationChain:
|
|
|
77
77
|
- try!
|
|
78
78
|
- in?
|
|
79
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
|
+
|
|
94
|
+
Lint/UselessMethodDefinition:
|
|
95
|
+
# Avoids conflict with `Rails/LexicallyScopedActionFilter` cop.
|
|
96
|
+
Exclude:
|
|
97
|
+
- '**/app/controllers/**/*.rb'
|
|
98
|
+
- '**/app/mailers/**/*.rb'
|
|
99
|
+
|
|
80
100
|
Rails:
|
|
81
101
|
Enabled: true
|
|
82
102
|
DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
|
|
@@ -107,8 +127,8 @@ Rails/ActionFilter:
|
|
|
107
127
|
- action
|
|
108
128
|
- filter
|
|
109
129
|
Include:
|
|
110
|
-
- app/controllers/**/*.rb
|
|
111
|
-
- app/mailers/**/*.rb
|
|
130
|
+
- '**/app/controllers/**/*.rb'
|
|
131
|
+
- '**/app/mailers/**/*.rb'
|
|
112
132
|
|
|
113
133
|
Rails/ActionOrder:
|
|
114
134
|
Description: 'Enforce consistent ordering of controller actions.'
|
|
@@ -123,7 +143,7 @@ Rails/ActionOrder:
|
|
|
123
143
|
- update
|
|
124
144
|
- destroy
|
|
125
145
|
Include:
|
|
126
|
-
- app/controllers/**/*.rb
|
|
146
|
+
- '**/app/controllers/**/*.rb'
|
|
127
147
|
|
|
128
148
|
Rails/ActiveRecordAliases:
|
|
129
149
|
Description: >-
|
|
@@ -140,7 +160,7 @@ Rails/ActiveRecordCallbacksOrder:
|
|
|
140
160
|
Enabled: 'pending'
|
|
141
161
|
VersionAdded: '2.7'
|
|
142
162
|
Include:
|
|
143
|
-
- app/models/**/*.rb
|
|
163
|
+
- '**/app/models/**/*.rb'
|
|
144
164
|
|
|
145
165
|
Rails/ActiveRecordOverride:
|
|
146
166
|
Description: >-
|
|
@@ -151,7 +171,7 @@ Rails/ActiveRecordOverride:
|
|
|
151
171
|
VersionAdded: '0.67'
|
|
152
172
|
VersionChanged: '2.18'
|
|
153
173
|
Include:
|
|
154
|
-
- app/models/**/*.rb
|
|
174
|
+
- '**/app/models/**/*.rb'
|
|
155
175
|
|
|
156
176
|
Rails/ActiveSupportAliases:
|
|
157
177
|
Description: >-
|
|
@@ -238,7 +258,7 @@ Rails/AttributeDefaultBlockValue:
|
|
|
238
258
|
Enabled: pending
|
|
239
259
|
VersionAdded: '2.9'
|
|
240
260
|
Include:
|
|
241
|
-
- 'app/models/**/*'
|
|
261
|
+
- '**/app/models/**/*'
|
|
242
262
|
|
|
243
263
|
Rails/BelongsTo:
|
|
244
264
|
Description: >-
|
|
@@ -297,8 +317,8 @@ Rails/ContentTag:
|
|
|
297
317
|
# https://puma.io/puma/Puma/DSL.html#tag-instance_method
|
|
298
318
|
# No helpers are used in normal models and configs.
|
|
299
319
|
Exclude:
|
|
300
|
-
- app/models/**/*.rb
|
|
301
|
-
- config/**/*.rb
|
|
320
|
+
- '**/app/models/**/*.rb'
|
|
321
|
+
- '**/config/**/*.rb'
|
|
302
322
|
|
|
303
323
|
Rails/CreateTableWithTimestamps:
|
|
304
324
|
Description: >-
|
|
@@ -353,11 +373,13 @@ Rails/Delegate:
|
|
|
353
373
|
Description: 'Prefer delegate method for delegations.'
|
|
354
374
|
Enabled: true
|
|
355
375
|
VersionAdded: '0.21'
|
|
356
|
-
VersionChanged: '
|
|
376
|
+
VersionChanged: '2.30'
|
|
357
377
|
# When set to true, using the target object as a prefix of the
|
|
358
378
|
# method name without using the `delegate` method will be a
|
|
359
379
|
# violation. When set to false, this case is legal.
|
|
360
380
|
EnforceForPrefixed: true
|
|
381
|
+
Exclude:
|
|
382
|
+
- '**/app/controllers/**/*.rb'
|
|
361
383
|
|
|
362
384
|
Rails/DelegateAllowBlank:
|
|
363
385
|
Description: 'Do not use allow_blank as an option to delegate.'
|
|
@@ -386,7 +408,7 @@ Rails/DuplicateAssociation:
|
|
|
386
408
|
VersionChanged: '2.18'
|
|
387
409
|
|
|
388
410
|
Rails/DuplicateScope:
|
|
389
|
-
Description: 'Multiple scopes share this same
|
|
411
|
+
Description: 'Multiple scopes share this same expression.'
|
|
390
412
|
Enabled: pending
|
|
391
413
|
Severity: warning
|
|
392
414
|
VersionAdded: '2.14'
|
|
@@ -428,7 +450,7 @@ Rails/EnumHash:
|
|
|
428
450
|
Enabled: true
|
|
429
451
|
VersionAdded: '2.3'
|
|
430
452
|
Include:
|
|
431
|
-
- app/models/**/*.rb
|
|
453
|
+
- '**/app/models/**/*.rb'
|
|
432
454
|
|
|
433
455
|
Rails/EnumSyntax:
|
|
434
456
|
Description: 'Use positional arguments over keyword arguments when defining enums.'
|
|
@@ -436,14 +458,20 @@ Rails/EnumSyntax:
|
|
|
436
458
|
Severity: warning
|
|
437
459
|
VersionAdded: '2.26'
|
|
438
460
|
Include:
|
|
439
|
-
- app/models/**/*.rb
|
|
461
|
+
- '**/app/models/**/*.rb'
|
|
462
|
+
- '**/lib/**/*.rb'
|
|
440
463
|
|
|
441
464
|
Rails/EnumUniqueness:
|
|
442
465
|
Description: 'Avoid duplicate integers in hash-syntax `enum` declaration.'
|
|
443
466
|
Enabled: true
|
|
444
467
|
VersionAdded: '0.46'
|
|
445
468
|
Include:
|
|
446
|
-
- 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'
|
|
447
475
|
|
|
448
476
|
Rails/EnvLocal:
|
|
449
477
|
Description: 'Use `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`.'
|
|
@@ -462,11 +490,11 @@ Rails/EnvironmentVariableAccess:
|
|
|
462
490
|
VersionAdded: '2.10'
|
|
463
491
|
VersionChanged: '2.24'
|
|
464
492
|
Include:
|
|
465
|
-
- app/**/*.rb
|
|
466
|
-
- config/initializers/**/*.rb
|
|
467
|
-
- lib/**/*.rb
|
|
493
|
+
- '**/app/**/*.rb'
|
|
494
|
+
- '**/config/initializers/**/*.rb'
|
|
495
|
+
- '**/lib/**/*.rb'
|
|
468
496
|
Exclude:
|
|
469
|
-
- lib/**/*.rake
|
|
497
|
+
- '**/lib/**/*.rake'
|
|
470
498
|
AllowReads: false
|
|
471
499
|
AllowWrites: false
|
|
472
500
|
|
|
@@ -478,11 +506,11 @@ Rails/Exit:
|
|
|
478
506
|
Enabled: true
|
|
479
507
|
VersionAdded: '0.41'
|
|
480
508
|
Include:
|
|
481
|
-
- app/**/*.rb
|
|
482
|
-
- config/**/*.rb
|
|
483
|
-
- lib/**/*.rb
|
|
509
|
+
- '**/app/**/*.rb'
|
|
510
|
+
- '**/config/**/*.rb'
|
|
511
|
+
- '**/lib/**/*.rb'
|
|
484
512
|
Exclude:
|
|
485
|
-
- lib/**/*.rake
|
|
513
|
+
- '**/lib/**/*.rake'
|
|
486
514
|
|
|
487
515
|
Rails/ExpandedDateRange:
|
|
488
516
|
Description: 'Checks for expanded date range.'
|
|
@@ -516,6 +544,13 @@ Rails/FindById:
|
|
|
516
544
|
Enabled: 'pending'
|
|
517
545
|
VersionAdded: '2.7'
|
|
518
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
|
+
|
|
519
554
|
Rails/FindEach:
|
|
520
555
|
Description: 'Prefer all.find_each over all.each.'
|
|
521
556
|
StyleGuide: 'https://rails.rubystyle.guide#find-each'
|
|
@@ -544,7 +579,7 @@ Rails/HasAndBelongsToMany:
|
|
|
544
579
|
Enabled: true
|
|
545
580
|
VersionAdded: '0.12'
|
|
546
581
|
Include:
|
|
547
|
-
- app/models/**/*.rb
|
|
582
|
+
- '**/app/models/**/*.rb'
|
|
548
583
|
|
|
549
584
|
Rails/HasManyOrHasOneDependent:
|
|
550
585
|
Description: 'Define the dependent option to the has_many and has_one associations.'
|
|
@@ -552,14 +587,14 @@ Rails/HasManyOrHasOneDependent:
|
|
|
552
587
|
Enabled: true
|
|
553
588
|
VersionAdded: '0.50'
|
|
554
589
|
Include:
|
|
555
|
-
- app/models/**/*.rb
|
|
590
|
+
- '**/app/models/**/*.rb'
|
|
556
591
|
|
|
557
592
|
Rails/HelperInstanceVariable:
|
|
558
593
|
Description: 'Do not use instance variables in helpers.'
|
|
559
594
|
Enabled: true
|
|
560
595
|
VersionAdded: '2.0'
|
|
561
596
|
Include:
|
|
562
|
-
- app/helpers/**/*.rb
|
|
597
|
+
- '**/app/helpers/**/*.rb'
|
|
563
598
|
|
|
564
599
|
Rails/HttpPositionalArguments:
|
|
565
600
|
Description: 'Use keyword arguments instead of positional arguments in http method calls.'
|
|
@@ -579,6 +614,14 @@ Rails/HttpStatus:
|
|
|
579
614
|
- numeric
|
|
580
615
|
- symbolic
|
|
581
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
|
+
|
|
582
625
|
Rails/I18nLazyLookup:
|
|
583
626
|
Description: 'Checks for places where I18n "lazy" lookup can be used.'
|
|
584
627
|
StyleGuide: 'https://rails.rubystyle.guide/#lazy-lookup'
|
|
@@ -590,7 +633,7 @@ Rails/I18nLazyLookup:
|
|
|
590
633
|
- lazy
|
|
591
634
|
- explicit
|
|
592
635
|
Include:
|
|
593
|
-
- 'app/controllers/**/*.rb'
|
|
636
|
+
- '**/app/controllers/**/*.rb'
|
|
594
637
|
|
|
595
638
|
Rails/I18nLocaleAssignment:
|
|
596
639
|
Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
|
|
@@ -619,8 +662,8 @@ Rails/IgnoredSkipActionFilterOption:
|
|
|
619
662
|
Enabled: true
|
|
620
663
|
VersionAdded: '0.63'
|
|
621
664
|
Include:
|
|
622
|
-
- app/controllers/**/*.rb
|
|
623
|
-
- app/mailers/**/*.rb
|
|
665
|
+
- '**/app/controllers/**/*.rb'
|
|
666
|
+
- '**/app/mailers/**/*.rb'
|
|
624
667
|
|
|
625
668
|
Rails/IndexBy:
|
|
626
669
|
Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
|
|
@@ -631,8 +674,9 @@ Rails/IndexBy:
|
|
|
631
674
|
Rails/IndexWith:
|
|
632
675
|
Description: 'Prefer `index_with` over `each_with_object`, `to_h`, or `map`.'
|
|
633
676
|
Enabled: true
|
|
677
|
+
SafeAutoCorrect: false
|
|
634
678
|
VersionAdded: '2.5'
|
|
635
|
-
VersionChanged: '2.
|
|
679
|
+
VersionChanged: '2.33'
|
|
636
680
|
|
|
637
681
|
Rails/Inquiry:
|
|
638
682
|
Description: "Prefer Ruby's comparison operators over Active Support's `Array#inquiry` and `String#inquiry`."
|
|
@@ -649,7 +693,7 @@ Rails/InverseOf:
|
|
|
649
693
|
VersionAdded: '0.52'
|
|
650
694
|
IgnoreScopes: false
|
|
651
695
|
Include:
|
|
652
|
-
- app/models/**/*.rb
|
|
696
|
+
- '**/app/models/**/*.rb'
|
|
653
697
|
|
|
654
698
|
Rails/LexicallyScopedActionFilter:
|
|
655
699
|
Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
|
|
@@ -658,8 +702,8 @@ Rails/LexicallyScopedActionFilter:
|
|
|
658
702
|
Safe: false
|
|
659
703
|
VersionAdded: '0.52'
|
|
660
704
|
Include:
|
|
661
|
-
- app/controllers/**/*.rb
|
|
662
|
-
- app/mailers/**/*.rb
|
|
705
|
+
- '**/app/controllers/**/*.rb'
|
|
706
|
+
- '**/app/mailers/**/*.rb'
|
|
663
707
|
|
|
664
708
|
Rails/LinkToBlank:
|
|
665
709
|
Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
|
|
@@ -677,7 +721,7 @@ Rails/MailerName:
|
|
|
677
721
|
SafeAutoCorrect: false
|
|
678
722
|
VersionAdded: '2.7'
|
|
679
723
|
Include:
|
|
680
|
-
- app/mailers/**/*.rb
|
|
724
|
+
- '**/app/mailers/**/*.rb'
|
|
681
725
|
|
|
682
726
|
Rails/MatchRoute:
|
|
683
727
|
Description: >-
|
|
@@ -687,8 +731,8 @@ Rails/MatchRoute:
|
|
|
687
731
|
Enabled: 'pending'
|
|
688
732
|
VersionAdded: '2.7'
|
|
689
733
|
Include:
|
|
690
|
-
- config/routes.rb
|
|
691
|
-
- config/routes/**/*.rb
|
|
734
|
+
- '**/config/routes.rb'
|
|
735
|
+
- '**/config/routes/**/*.rb'
|
|
692
736
|
|
|
693
737
|
Rails/MigrationClassName:
|
|
694
738
|
Description: 'The class name of the migration should match its file name.'
|
|
@@ -704,8 +748,8 @@ Rails/MultipleRoutePaths:
|
|
|
704
748
|
Severity: warning
|
|
705
749
|
VersionAdded: '2.29'
|
|
706
750
|
Include:
|
|
707
|
-
- config/routes.rb
|
|
708
|
-
- config/routes/**/*.rb
|
|
751
|
+
- '**/config/routes.rb'
|
|
752
|
+
- '**/config/routes/**/*.rb'
|
|
709
753
|
|
|
710
754
|
Rails/NegateInclude:
|
|
711
755
|
Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
|
|
@@ -726,6 +770,13 @@ Rails/NotNullColumn:
|
|
|
726
770
|
Include:
|
|
727
771
|
- db/**/*.rb
|
|
728
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
|
+
|
|
729
780
|
Rails/OrderById:
|
|
730
781
|
Description: >-
|
|
731
782
|
Do not use the `id` column for ordering.
|
|
@@ -741,10 +792,10 @@ Rails/Output:
|
|
|
741
792
|
VersionAdded: '0.15'
|
|
742
793
|
VersionChanged: '0.19'
|
|
743
794
|
Include:
|
|
744
|
-
- app/**/*.rb
|
|
745
|
-
- config/**/*.rb
|
|
795
|
+
- '**/app/**/*.rb'
|
|
796
|
+
- '**/config/**/*.rb'
|
|
746
797
|
- db/**/*.rb
|
|
747
|
-
- lib/**/*.rb
|
|
798
|
+
- '**/lib/**/*.rb'
|
|
748
799
|
|
|
749
800
|
Rails/OutputSafety:
|
|
750
801
|
Description: 'The use of `html_safe` or `raw` may be a security risk.'
|
|
@@ -793,6 +844,7 @@ Rails/Presence:
|
|
|
793
844
|
Description: 'Checks code that can be written more easily using `Object#presence` defined by Active Support.'
|
|
794
845
|
Enabled: true
|
|
795
846
|
VersionAdded: '0.52'
|
|
847
|
+
VersionChanged: '2.34'
|
|
796
848
|
|
|
797
849
|
Rails/Present:
|
|
798
850
|
Description: 'Enforces use of `present?`.'
|
|
@@ -816,7 +868,7 @@ Rails/RakeEnvironment:
|
|
|
816
868
|
- '**/Rakefile'
|
|
817
869
|
- '**/*.rake'
|
|
818
870
|
Exclude:
|
|
819
|
-
- 'lib/capistrano/tasks/**/*.rake'
|
|
871
|
+
- '**/lib/capistrano/tasks/**/*.rake'
|
|
820
872
|
|
|
821
873
|
Rails/ReadWriteAttribute:
|
|
822
874
|
Description: >-
|
|
@@ -827,7 +879,15 @@ Rails/ReadWriteAttribute:
|
|
|
827
879
|
VersionAdded: '0.20'
|
|
828
880
|
VersionChanged: '0.29'
|
|
829
881
|
Include:
|
|
830
|
-
- 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'
|
|
831
891
|
|
|
832
892
|
Rails/RedundantActiveRecordAllMethod:
|
|
833
893
|
Description: Detect redundant `all` used as a receiver for Active Record query methods.
|
|
@@ -846,7 +906,7 @@ Rails/RedundantAllowNil:
|
|
|
846
906
|
Enabled: true
|
|
847
907
|
VersionAdded: '0.67'
|
|
848
908
|
Include:
|
|
849
|
-
- app/models/**/*.rb
|
|
909
|
+
- '**/app/models/**/*.rb'
|
|
850
910
|
|
|
851
911
|
Rails/RedundantForeignKey:
|
|
852
912
|
Description: 'Checks for associations where the `:foreign_key` option is redundant.'
|
|
@@ -1017,7 +1077,7 @@ Rails/ScopeArgs:
|
|
|
1017
1077
|
VersionAdded: '0.19'
|
|
1018
1078
|
VersionChanged: '2.12'
|
|
1019
1079
|
Include:
|
|
1020
|
-
- app/models/**/*.rb
|
|
1080
|
+
- '**/app/models/**/*.rb'
|
|
1021
1081
|
|
|
1022
1082
|
Rails/SelectMap:
|
|
1023
1083
|
Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
|
|
@@ -1086,7 +1146,7 @@ Rails/StrongParametersExpect:
|
|
|
1086
1146
|
Reference: 'https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect'
|
|
1087
1147
|
Enabled: pending
|
|
1088
1148
|
Include:
|
|
1089
|
-
- app/controllers/**/*.rb
|
|
1149
|
+
- '**/app/controllers/**/*.rb'
|
|
1090
1150
|
SafeAutoCorrect: false
|
|
1091
1151
|
VersionAdded: '2.29'
|
|
1092
1152
|
|
|
@@ -1097,7 +1157,7 @@ Rails/TableNameAssignment:
|
|
|
1097
1157
|
Enabled: false
|
|
1098
1158
|
VersionAdded: '2.14'
|
|
1099
1159
|
Include:
|
|
1100
|
-
- app/models/**/*.rb
|
|
1160
|
+
- '**/app/models/**/*.rb'
|
|
1101
1161
|
|
|
1102
1162
|
Rails/ThreeStateBooleanColumn:
|
|
1103
1163
|
Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
|
|
@@ -1110,7 +1170,7 @@ Rails/ThreeStateBooleanColumn:
|
|
|
1110
1170
|
Rails/TimeZone:
|
|
1111
1171
|
Description: 'Checks the correct usage of time zone aware methods.'
|
|
1112
1172
|
StyleGuide: 'https://rails.rubystyle.guide#time'
|
|
1113
|
-
Reference: '
|
|
1173
|
+
Reference: 'https://danilenko.org/2012/7/6/rails_timezones'
|
|
1114
1174
|
Enabled: true
|
|
1115
1175
|
SafeAutoCorrect: false
|
|
1116
1176
|
VersionAdded: '0.30'
|
|
@@ -1181,7 +1241,7 @@ Rails/UniqueValidationWithoutIndex:
|
|
|
1181
1241
|
Enabled: true
|
|
1182
1242
|
VersionAdded: '2.5'
|
|
1183
1243
|
Include:
|
|
1184
|
-
- app/models/**/*.rb
|
|
1244
|
+
- '**/app/models/**/*.rb'
|
|
1185
1245
|
|
|
1186
1246
|
Rails/UnknownEnv:
|
|
1187
1247
|
Description: 'Use correct environment name.'
|
|
@@ -1200,7 +1260,7 @@ Rails/UnusedIgnoredColumns:
|
|
|
1200
1260
|
VersionAdded: '2.11'
|
|
1201
1261
|
VersionChanged: '2.25'
|
|
1202
1262
|
Include:
|
|
1203
|
-
- app/models/**/*.rb
|
|
1263
|
+
- '**/app/models/**/*.rb'
|
|
1204
1264
|
|
|
1205
1265
|
Rails/UnusedRenderContent:
|
|
1206
1266
|
Description: 'Do not specify body content for a response with a non-content status code.'
|
|
@@ -1214,7 +1274,7 @@ Rails/Validation:
|
|
|
1214
1274
|
VersionAdded: '0.9'
|
|
1215
1275
|
VersionChanged: '0.41'
|
|
1216
1276
|
Include:
|
|
1217
|
-
- app/models/**/*.rb
|
|
1277
|
+
- '**/app/models/**/*.rb'
|
|
1218
1278
|
|
|
1219
1279
|
Rails/WhereEquals:
|
|
1220
1280
|
Description: 'Pass conditions to `where` and `where.not` as a hash instead of manually constructing SQL.'
|
|
@@ -103,10 +103,10 @@ module RuboCop
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def in_where?(node)
|
|
106
|
-
send_node = node.each_ancestor(:
|
|
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?
|
|
@@ -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)
|
|
@@ -58,7 +58,7 @@ module RuboCop
|
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def set_new_arg_name(transformed_argname, corrector)
|
|
61
|
-
return
|
|
61
|
+
return unless block_node.block_type?
|
|
62
62
|
|
|
63
63
|
corrector.replace(block_node.arguments, "|#{transformed_argname}|")
|
|
64
64
|
end
|
|
@@ -84,6 +84,7 @@ module RuboCop
|
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
alias on_numblock on_block
|
|
87
|
+
alias on_itblock on_block
|
|
87
88
|
|
|
88
89
|
def on_send(node)
|
|
89
90
|
on_bad_map_to_h(node) do |*match|
|
|
@@ -131,9 +132,13 @@ module RuboCop
|
|
|
131
132
|
add_offense(
|
|
132
133
|
node, message: "Prefer `#{new_method_name}` over `#{match_desc}`."
|
|
133
134
|
) do |corrector|
|
|
135
|
+
next if part_of_ignored_node?(node)
|
|
136
|
+
|
|
134
137
|
correction = prepare_correction(node)
|
|
135
138
|
execute_correction(corrector, node, correction)
|
|
136
139
|
end
|
|
140
|
+
|
|
141
|
+
ignore_node(node)
|
|
137
142
|
end
|
|
138
143
|
|
|
139
144
|
def extract_captures(match)
|
|
@@ -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)
|
|
@@ -5,14 +5,14 @@ module RuboCop
|
|
|
5
5
|
module Rails
|
|
6
6
|
# Prevents usage of `"*"` on an Arel::Table column reference.
|
|
7
7
|
#
|
|
8
|
-
# Using `arel_table["
|
|
9
|
-
# quoted asterisk (e.g.
|
|
10
|
-
# database to look for a column named
|
|
8
|
+
# Using `arel_table["\*"]` causes the outputted string to be a literal
|
|
9
|
+
# quoted asterisk (e.g. `my_model`.`*`). This causes the
|
|
10
|
+
# database to look for a column named `\*` (or `"*"`) as opposed
|
|
11
11
|
# to expanding the column list as one would likely expect.
|
|
12
12
|
#
|
|
13
13
|
# @safety
|
|
14
|
-
# This cop's autocorrection is unsafe because it turns a quoted
|
|
15
|
-
# an SQL `*`, unquoted.
|
|
14
|
+
# This cop's autocorrection is unsafe because it turns a quoted `\*` into
|
|
15
|
+
# an SQL `*`, unquoted. `\*` is a valid column name in certain databases
|
|
16
16
|
# supported by Rails, and even though it is usually a mistake,
|
|
17
17
|
# it might denote legitimate access to a column named `*`.
|
|
18
18
|
#
|
|
@@ -15,6 +15,9 @@ module RuboCop
|
|
|
15
15
|
# without using the `delegate` method will be a violation.
|
|
16
16
|
# When set to `false`, this case is legal.
|
|
17
17
|
#
|
|
18
|
+
# It is disabled for controllers in order to keep controller actions
|
|
19
|
+
# explicitly defined.
|
|
20
|
+
#
|
|
18
21
|
# @example
|
|
19
22
|
# # bad
|
|
20
23
|
# def bar
|
|
@@ -73,7 +76,7 @@ module RuboCop
|
|
|
73
76
|
|
|
74
77
|
def on_def(node)
|
|
75
78
|
return unless trivial_delegate?(node)
|
|
76
|
-
return if private_or_protected_delegation(node)
|
|
79
|
+
return if private_or_protected_delegation?(node)
|
|
77
80
|
return if module_function_declared?(node)
|
|
78
81
|
|
|
79
82
|
register_offense(node)
|
|
@@ -160,8 +163,8 @@ module RuboCop
|
|
|
160
163
|
end
|
|
161
164
|
end
|
|
162
165
|
|
|
163
|
-
def private_or_protected_delegation(node)
|
|
164
|
-
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
|
|
165
168
|
end
|
|
166
169
|
|
|
167
170
|
def module_function_declared?(node)
|
|
@@ -170,7 +173,7 @@ module RuboCop
|
|
|
170
173
|
end
|
|
171
174
|
end
|
|
172
175
|
|
|
173
|
-
def private_or_protected_inline(node)
|
|
176
|
+
def private_or_protected_inline?(node)
|
|
174
177
|
processed_source[node.first_line - 1].strip.match?(/\A(private )|(protected )/)
|
|
175
178
|
end
|
|
176
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 _ $...)
|
|
@@ -45,12 +45,10 @@ module RuboCop
|
|
|
45
45
|
return if node.parent&.block_type?
|
|
46
46
|
|
|
47
47
|
interpolated_string_passed_to_debug(node) do |arguments|
|
|
48
|
-
message = format(MSG)
|
|
49
|
-
|
|
50
48
|
range = replacement_range(node)
|
|
51
49
|
replacement = replacement_source(node, arguments)
|
|
52
50
|
|
|
53
|
-
add_offense(range
|
|
51
|
+
add_offense(range) do |corrector|
|
|
54
52
|
corrector.replace(range, replacement)
|
|
55
53
|
end
|
|
56
54
|
end
|