rubocop-rails 2.30.2 → 2.33.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 (36) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -1
  3. data/config/default.yml +87 -49
  4. data/lib/rubocop/cop/mixin/active_record_helper.rb +2 -2
  5. data/lib/rubocop/cop/mixin/active_record_migrations_helper.rb +2 -2
  6. data/lib/rubocop/cop/mixin/database_type_resolvable.rb +2 -2
  7. data/lib/rubocop/cop/mixin/enforce_superclass.rb +6 -1
  8. data/lib/rubocop/cop/mixin/index_method.rb +6 -1
  9. data/lib/rubocop/cop/rails/arel_star.rb +5 -5
  10. data/lib/rubocop/cop/rails/delegate.rb +7 -4
  11. data/lib/rubocop/cop/rails/duplicate_association.rb +1 -1
  12. data/lib/rubocop/cop/rails/eager_evaluation_log_message.rb +1 -3
  13. data/lib/rubocop/cop/rails/env_local.rb +50 -26
  14. data/lib/rubocop/cop/rails/file_path.rb +2 -2
  15. data/lib/rubocop/cop/rails/find_by_or_assignment_memoization.rb +65 -0
  16. data/lib/rubocop/cop/rails/index_by.rb +9 -0
  17. data/lib/rubocop/cop/rails/index_with.rb +14 -0
  18. data/lib/rubocop/cop/rails/order_arguments.rb +79 -0
  19. data/lib/rubocop/cop/rails/output.rb +4 -2
  20. data/lib/rubocop/cop/rails/pluck.rb +13 -4
  21. data/lib/rubocop/cop/rails/redundant_presence_validation_on_belongs_to.rb +3 -3
  22. data/lib/rubocop/cop/rails/redundant_receiver_in_with_options.rb +7 -2
  23. data/lib/rubocop/cop/rails/reflection_class_name.rb +2 -2
  24. data/lib/rubocop/cop/rails/relative_date_constant.rb +1 -1
  25. data/lib/rubocop/cop/rails/reversible_migration.rb +2 -1
  26. data/lib/rubocop/cop/rails/save_bang.rb +4 -4
  27. data/lib/rubocop/cop/rails/schema_comment.rb +1 -1
  28. data/lib/rubocop/cop/rails/three_state_boolean_column.rb +1 -1
  29. data/lib/rubocop/cop/rails/time_zone.rb +3 -1
  30. data/lib/rubocop/cop/rails/transaction_exit_statement.rb +5 -3
  31. data/lib/rubocop/cop/rails/uniq_before_pluck.rb +1 -1
  32. data/lib/rubocop/cop/rails/where_exists.rb +2 -2
  33. data/lib/rubocop/cop/rails_cops.rb +2 -0
  34. data/lib/rubocop/rails/version.rb +1 -1
  35. data/lib/rubocop-rails.rb +0 -1
  36. metadata +10 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69854cebe11dde8160c57b94c6ebbe60e7df48c1357aae64b932f73bb2f230ad
4
- data.tar.gz: 04b388703ccde52554cb01f0e04a50291beada4dec9199fbb46b3dd750d8a4ff
3
+ metadata.gz: 3a61be89f227c5abed6543c4fb84957391ac66fdbadc7f7891a1876b7be0c193
4
+ data.tar.gz: f2e30c0c3e5a5cac32bae9ec0900a0e1fc382dda89f764f8a844b085ad2abffb
5
5
  SHA512:
6
- metadata.gz: 79fda1fbb14ab98b4472576b7cb776294f3c46eb56c3b0751e47c5fba308615b4f1579a41ea3b14a8c2fb22e19e693ea1e615fe48c5d9fff6f8c857ef887a53f
7
- data.tar.gz: f219f779b57f3ecd44937c02e85872058b453bdd7ce5c83cc1d6ac05175b2c93c01d2548a02c9b46ca26bc2dca6af116611a9d9595d81b53e5a165e47a8b6cf4
6
+ metadata.gz: 8610629e8893c71c21d591cc68897f993699f20edab9cda08a18ce65d9bf67ac153830dffa144e18b2d9e4e204027684c18cbb02e822d01c9c40e35312709083
7
+ data.tar.gz: f7dc418f1cb2f4a38968b9a79ae17028368e10f2d529cba2de15954a2edc5c3f8ebf7bb35617b670cf7e8dab758ccb138c0387a0fd6caa31051ee5e803925c35
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
 
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: '0.50'
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.'
@@ -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,15 @@ 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'
447
470
 
448
471
  Rails/EnvLocal:
449
472
  Description: 'Use `Rails.env.local?` instead of `Rails.env.development? || Rails.env.test?`.'
@@ -462,11 +485,11 @@ Rails/EnvironmentVariableAccess:
462
485
  VersionAdded: '2.10'
463
486
  VersionChanged: '2.24'
464
487
  Include:
465
- - app/**/*.rb
466
- - config/initializers/**/*.rb
467
- - lib/**/*.rb
488
+ - '**/app/**/*.rb'
489
+ - '**/config/initializers/**/*.rb'
490
+ - '**/lib/**/*.rb'
468
491
  Exclude:
469
- - lib/**/*.rake
492
+ - '**/lib/**/*.rake'
470
493
  AllowReads: false
471
494
  AllowWrites: false
472
495
 
@@ -478,11 +501,11 @@ Rails/Exit:
478
501
  Enabled: true
479
502
  VersionAdded: '0.41'
480
503
  Include:
481
- - app/**/*.rb
482
- - config/**/*.rb
483
- - lib/**/*.rb
504
+ - '**/app/**/*.rb'
505
+ - '**/config/**/*.rb'
506
+ - '**/lib/**/*.rb'
484
507
  Exclude:
485
- - lib/**/*.rake
508
+ - '**/lib/**/*.rake'
486
509
 
487
510
  Rails/ExpandedDateRange:
488
511
  Description: 'Checks for expanded date range.'
@@ -516,6 +539,13 @@ Rails/FindById:
516
539
  Enabled: 'pending'
517
540
  VersionAdded: '2.7'
518
541
 
542
+ Rails/FindByOrAssignmentMemoization:
543
+ Description: 'Avoid memoizing `find_by` results with `||=`.'
544
+ StyleGuide: 'https://rails.rubystyle.guide/#find-by-memoization'
545
+ Enabled: pending
546
+ Safe: false
547
+ VersionAdded: '2.33'
548
+
519
549
  Rails/FindEach:
520
550
  Description: 'Prefer all.find_each over all.each.'
521
551
  StyleGuide: 'https://rails.rubystyle.guide#find-each'
@@ -544,7 +574,7 @@ Rails/HasAndBelongsToMany:
544
574
  Enabled: true
545
575
  VersionAdded: '0.12'
546
576
  Include:
547
- - app/models/**/*.rb
577
+ - '**/app/models/**/*.rb'
548
578
 
549
579
  Rails/HasManyOrHasOneDependent:
550
580
  Description: 'Define the dependent option to the has_many and has_one associations.'
@@ -552,14 +582,14 @@ Rails/HasManyOrHasOneDependent:
552
582
  Enabled: true
553
583
  VersionAdded: '0.50'
554
584
  Include:
555
- - app/models/**/*.rb
585
+ - '**/app/models/**/*.rb'
556
586
 
557
587
  Rails/HelperInstanceVariable:
558
588
  Description: 'Do not use instance variables in helpers.'
559
589
  Enabled: true
560
590
  VersionAdded: '2.0'
561
591
  Include:
562
- - app/helpers/**/*.rb
592
+ - '**/app/helpers/**/*.rb'
563
593
 
564
594
  Rails/HttpPositionalArguments:
565
595
  Description: 'Use keyword arguments instead of positional arguments in http method calls.'
@@ -590,7 +620,7 @@ Rails/I18nLazyLookup:
590
620
  - lazy
591
621
  - explicit
592
622
  Include:
593
- - 'app/controllers/**/*.rb'
623
+ - '**/app/controllers/**/*.rb'
594
624
 
595
625
  Rails/I18nLocaleAssignment:
596
626
  Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
@@ -619,8 +649,8 @@ Rails/IgnoredSkipActionFilterOption:
619
649
  Enabled: true
620
650
  VersionAdded: '0.63'
621
651
  Include:
622
- - app/controllers/**/*.rb
623
- - app/mailers/**/*.rb
652
+ - '**/app/controllers/**/*.rb'
653
+ - '**/app/mailers/**/*.rb'
624
654
 
625
655
  Rails/IndexBy:
626
656
  Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
@@ -631,8 +661,9 @@ Rails/IndexBy:
631
661
  Rails/IndexWith:
632
662
  Description: 'Prefer `index_with` over `each_with_object`, `to_h`, or `map`.'
633
663
  Enabled: true
664
+ SafeAutoCorrect: false
634
665
  VersionAdded: '2.5'
635
- VersionChanged: '2.8'
666
+ VersionChanged: '2.33'
636
667
 
637
668
  Rails/Inquiry:
638
669
  Description: "Prefer Ruby's comparison operators over Active Support's `Array#inquiry` and `String#inquiry`."
@@ -649,7 +680,7 @@ Rails/InverseOf:
649
680
  VersionAdded: '0.52'
650
681
  IgnoreScopes: false
651
682
  Include:
652
- - app/models/**/*.rb
683
+ - '**/app/models/**/*.rb'
653
684
 
654
685
  Rails/LexicallyScopedActionFilter:
655
686
  Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
@@ -658,8 +689,8 @@ Rails/LexicallyScopedActionFilter:
658
689
  Safe: false
659
690
  VersionAdded: '0.52'
660
691
  Include:
661
- - app/controllers/**/*.rb
662
- - app/mailers/**/*.rb
692
+ - '**/app/controllers/**/*.rb'
693
+ - '**/app/mailers/**/*.rb'
663
694
 
664
695
  Rails/LinkToBlank:
665
696
  Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
@@ -677,7 +708,7 @@ Rails/MailerName:
677
708
  SafeAutoCorrect: false
678
709
  VersionAdded: '2.7'
679
710
  Include:
680
- - app/mailers/**/*.rb
711
+ - '**/app/mailers/**/*.rb'
681
712
 
682
713
  Rails/MatchRoute:
683
714
  Description: >-
@@ -687,8 +718,8 @@ Rails/MatchRoute:
687
718
  Enabled: 'pending'
688
719
  VersionAdded: '2.7'
689
720
  Include:
690
- - config/routes.rb
691
- - config/routes/**/*.rb
721
+ - '**/config/routes.rb'
722
+ - '**/config/routes/**/*.rb'
692
723
 
693
724
  Rails/MigrationClassName:
694
725
  Description: 'The class name of the migration should match its file name.'
@@ -704,8 +735,8 @@ Rails/MultipleRoutePaths:
704
735
  Severity: warning
705
736
  VersionAdded: '2.29'
706
737
  Include:
707
- - config/routes.rb
708
- - config/routes/**/*.rb
738
+ - '**/config/routes.rb'
739
+ - '**/config/routes/**/*.rb'
709
740
 
710
741
  Rails/NegateInclude:
711
742
  Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
@@ -726,6 +757,13 @@ Rails/NotNullColumn:
726
757
  Include:
727
758
  - db/**/*.rb
728
759
 
760
+ Rails/OrderArguments:
761
+ Description: 'Prefer symbol arguments over strings in `order` method.'
762
+ StyleGuide: 'https://rails.rubystyle.guide/#order-arguments'
763
+ Enabled: pending
764
+ VersionAdded: '2.33'
765
+ Safe: false
766
+
729
767
  Rails/OrderById:
730
768
  Description: >-
731
769
  Do not use the `id` column for ordering.
@@ -741,10 +779,10 @@ Rails/Output:
741
779
  VersionAdded: '0.15'
742
780
  VersionChanged: '0.19'
743
781
  Include:
744
- - app/**/*.rb
745
- - config/**/*.rb
782
+ - '**/app/**/*.rb'
783
+ - '**/config/**/*.rb'
746
784
  - db/**/*.rb
747
- - lib/**/*.rb
785
+ - '**/lib/**/*.rb'
748
786
 
749
787
  Rails/OutputSafety:
750
788
  Description: 'The use of `html_safe` or `raw` may be a security risk.'
@@ -816,7 +854,7 @@ Rails/RakeEnvironment:
816
854
  - '**/Rakefile'
817
855
  - '**/*.rake'
818
856
  Exclude:
819
- - 'lib/capistrano/tasks/**/*.rake'
857
+ - '**/lib/capistrano/tasks/**/*.rake'
820
858
 
821
859
  Rails/ReadWriteAttribute:
822
860
  Description: >-
@@ -827,7 +865,7 @@ Rails/ReadWriteAttribute:
827
865
  VersionAdded: '0.20'
828
866
  VersionChanged: '0.29'
829
867
  Include:
830
- - app/models/**/*.rb
868
+ - '**/app/models/**/*.rb'
831
869
 
832
870
  Rails/RedundantActiveRecordAllMethod:
833
871
  Description: Detect redundant `all` used as a receiver for Active Record query methods.
@@ -846,7 +884,7 @@ Rails/RedundantAllowNil:
846
884
  Enabled: true
847
885
  VersionAdded: '0.67'
848
886
  Include:
849
- - app/models/**/*.rb
887
+ - '**/app/models/**/*.rb'
850
888
 
851
889
  Rails/RedundantForeignKey:
852
890
  Description: 'Checks for associations where the `:foreign_key` option is redundant.'
@@ -1017,7 +1055,7 @@ Rails/ScopeArgs:
1017
1055
  VersionAdded: '0.19'
1018
1056
  VersionChanged: '2.12'
1019
1057
  Include:
1020
- - app/models/**/*.rb
1058
+ - '**/app/models/**/*.rb'
1021
1059
 
1022
1060
  Rails/SelectMap:
1023
1061
  Description: 'Checks for uses of `select(:column_name)` with `map(&:column_name)`.'
@@ -1086,7 +1124,7 @@ Rails/StrongParametersExpect:
1086
1124
  Reference: 'https://api.rubyonrails.org/classes/ActionController/Parameters.html#method-i-expect'
1087
1125
  Enabled: pending
1088
1126
  Include:
1089
- - app/controllers/**/*.rb
1127
+ - '**/app/controllers/**/*.rb'
1090
1128
  SafeAutoCorrect: false
1091
1129
  VersionAdded: '2.29'
1092
1130
 
@@ -1097,7 +1135,7 @@ Rails/TableNameAssignment:
1097
1135
  Enabled: false
1098
1136
  VersionAdded: '2.14'
1099
1137
  Include:
1100
- - app/models/**/*.rb
1138
+ - '**/app/models/**/*.rb'
1101
1139
 
1102
1140
  Rails/ThreeStateBooleanColumn:
1103
1141
  Description: 'Add a default value and a `NOT NULL` constraint to boolean columns.'
@@ -1110,7 +1148,7 @@ Rails/ThreeStateBooleanColumn:
1110
1148
  Rails/TimeZone:
1111
1149
  Description: 'Checks the correct usage of time zone aware methods.'
1112
1150
  StyleGuide: 'https://rails.rubystyle.guide#time'
1113
- Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
1151
+ Reference: 'https://danilenko.org/2012/7/6/rails_timezones'
1114
1152
  Enabled: true
1115
1153
  SafeAutoCorrect: false
1116
1154
  VersionAdded: '0.30'
@@ -1181,7 +1219,7 @@ Rails/UniqueValidationWithoutIndex:
1181
1219
  Enabled: true
1182
1220
  VersionAdded: '2.5'
1183
1221
  Include:
1184
- - app/models/**/*.rb
1222
+ - '**/app/models/**/*.rb'
1185
1223
 
1186
1224
  Rails/UnknownEnv:
1187
1225
  Description: 'Use correct environment name.'
@@ -1200,7 +1238,7 @@ Rails/UnusedIgnoredColumns:
1200
1238
  VersionAdded: '2.11'
1201
1239
  VersionChanged: '2.25'
1202
1240
  Include:
1203
- - app/models/**/*.rb
1241
+ - '**/app/models/**/*.rb'
1204
1242
 
1205
1243
  Rails/UnusedRenderContent:
1206
1244
  Description: 'Do not specify body content for a response with a non-content status code.'
@@ -1214,7 +1252,7 @@ Rails/Validation:
1214
1252
  VersionAdded: '0.9'
1215
1253
  VersionChanged: '0.41'
1216
1254
  Include:
1217
- - app/models/**/*.rb
1255
+ - '**/app/models/**/*.rb'
1218
1256
 
1219
1257
  Rails/WhereEquals:
1220
1258
  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(:send, :csend).first
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?
@@ -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)
@@ -58,7 +58,7 @@ module RuboCop
58
58
  end
59
59
 
60
60
  def set_new_arg_name(transformed_argname, corrector)
61
- return if block_node.numblock_type?
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)
@@ -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["*"]` causes the outputted string to be a literal
9
- # quoted asterisk (e.g. <tt>`my_model`.`*`</tt>). This causes the
10
- # database to look for a column named <tt>`*`</tt> (or `"*"`) as opposed
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 `*` into
15
- # an SQL `*`, unquoted. `*` is a valid column name in certain databases
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.count == 1
97
+ next unless arguments.one?
98
98
 
99
99
  if (class_name = class_name(arguments.first))
100
100
  class_name.source
@@ -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, message: message) do |corrector|
51
+ add_offense(range) do |corrector|
54
52
  corrector.replace(range, replacement)
55
53
  end
56
54
  end