makandra-rubocop 9.1.0 → 10.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/config/ext/rails.yml CHANGED
@@ -15,7 +15,7 @@ AllCops:
15
15
  - 'public/system/**/*'
16
16
  - 'db/schema.rb'
17
17
  # What version of Rails is the inspected code using? If a value is specified
18
- # for TargetRailsVersion then it is used. Acceptable values are specificed
18
+ # for TargetRailsVersion then it is used. Acceptable values are specified
19
19
  # as a float (i.e. 5.1); the patch version of Rails should not be included.
20
20
  # If TargetRailsVersion is not set, RuboCop will parse the Gemfile.lock or
21
21
  # gems.locked file to find the version of Rails that has been bound to the
@@ -27,7 +27,7 @@ Lint/NumberConversion:
27
27
  # Add Rails' duration methods to the ignore list for `Lint/NumberConversion`
28
28
  # so that calling `to_i` on one of these does not register an offense.
29
29
  # See: https://github.com/rubocop/rubocop/issues/8950
30
- IgnoredMethods:
30
+ AllowedMethods:
31
31
  - ago
32
32
  - from_now
33
33
  - second
@@ -44,6 +44,28 @@ Lint/NumberConversion:
44
44
  - fortnights
45
45
  - in_milliseconds
46
46
 
47
+ Rails:
48
+ Enabled: true
49
+ DocumentationBaseURL: https://docs.rubocop.org/rubocop-rails
50
+
51
+ Rails/ActionControllerFlashBeforeRender:
52
+ Description: 'Use `flash.now` instead of `flash` before `render`.'
53
+ StyleGuide: 'https://rails.rubystyle.guide/#flash-before-render'
54
+ Reference: 'https://api.rubyonrails.org/classes/ActionController/FlashBeforeRender.html'
55
+ Enabled: false # there may be cases where we actually want to use `flash` before a render.
56
+ SafeAutoCorrect: false
57
+ VersionAdded: '2.16'
58
+
59
+ Rails/ActionControllerTestCase:
60
+ Description: 'Use `ActionDispatch::IntegrationTest` instead of `ActionController::TestCase`.'
61
+ StyleGuide: 'https://rails.rubystyle.guide/#integration-testing'
62
+ Reference: 'https://api.rubyonrails.org/classes/ActionController/TestCase.html'
63
+ Enabled: false # we don't use this anyway
64
+ SafeAutoCorrect: false
65
+ VersionAdded: '2.14'
66
+ Include:
67
+ - '**/test/**/*.rb'
68
+
47
69
  Rails/ActionFilter:
48
70
  Description: 'Enforces consistent use of action filter methods.'
49
71
  Enabled: true
@@ -54,6 +76,22 @@ Rails/ActionFilter:
54
76
  - filter
55
77
  Include:
56
78
  - app/controllers/**/*.rb
79
+ - app/mailers/**/*.rb
80
+
81
+ Rails/ActionOrder:
82
+ Description: 'Enforce consistent ordering of controller actions.'
83
+ Enabled: false # The best order is debatable, and there maybe valid reasons not to stick to any particular order
84
+ VersionAdded: '2.17'
85
+ ExpectedOrder:
86
+ - index
87
+ - show
88
+ - new
89
+ - edit
90
+ - create
91
+ - update
92
+ - destroy
93
+ Include:
94
+ - app/controllers/**/*.rb
57
95
 
58
96
  Rails/ActiveRecordAliases:
59
97
  Description: >-
@@ -89,6 +127,15 @@ Rails/ActiveSupportAliases:
89
127
  Enabled: false
90
128
  VersionAdded: '0.48'
91
129
 
130
+ Rails/ActiveSupportOnLoad:
131
+ Description: 'Use `ActiveSupport.on_load(...)` to patch Rails framework classes.'
132
+ Enabled: true
133
+ Reference:
134
+ - 'https://api.rubyonrails.org/classes/ActiveSupport/LazyLoadHooks.html'
135
+ - 'https://guides.rubyonrails.org/engines.html#available-load-hooks'
136
+ SafeAutoCorrect: false
137
+ VersionAdded: '2.16'
138
+
92
139
  Rails/AddColumnIndex:
93
140
  Description: >-
94
141
  Rails migrations don't make use of a given `index` key, but also
@@ -101,7 +148,7 @@ Rails/AddColumnIndex:
101
148
 
102
149
  Rails/AfterCommitOverride:
103
150
  Description: >-
104
- This cop enforces that there is only one call to `after_commit`
151
+ Enforces that there is only one call to `after_commit`
105
152
  (and its aliases - `after_create_commit`, `after_update_commit`,
106
153
  and `after_destroy_commit`) with the same callback name per model.
107
154
  Enabled: true
@@ -186,13 +233,27 @@ Rails/BulkChangeTable:
186
233
  Include:
187
234
  - db/migrate/*.rb
188
235
 
236
+ Rails/CompactBlank:
237
+ Description: 'Checks if collection can be blank-compacted with `compact_blank`.'
238
+ Enabled: false # This may lead to false positives. See https://docs.rubocop.org/rubocop-rails/cops_rails.html#railscompactblank
239
+ Safe: false
240
+ VersionAdded: '2.13'
241
+
189
242
  Rails/ContentTag:
190
243
  Description: 'Use `tag` instead of `content_tag`.'
191
244
  Reference:
245
+ - 'https://github.com/rubocop/rubocop-rails/issues/260'
192
246
  - 'https://github.com/rails/rails/issues/25195'
193
247
  - 'https://api.rubyonrails.org/classes/ActionView/Helpers/TagHelper.html#method-i-content_tag'
194
248
  Enabled: false # We currently use content_tag in many applications. If content_tag should become deprecated in the future we'll have to change it anyway, but until then, we'll keep the content_tag syntax
195
249
  VersionAdded: '2.6'
250
+ VersionChanged: '2.12'
251
+ # This `Exclude` config prevents false positives for `tag` calls to `has_one: tag` and Puma configuration:
252
+ # https://puma.io/puma/Puma/DSL.html#tag-instance_method
253
+ # No helpers are used in normal models and configs.
254
+ Exclude:
255
+ - app/models/**/*.rb
256
+ - config/**/*.rb
196
257
 
197
258
  Rails/CreateTableWithTimestamps:
198
259
  Description: >-
@@ -202,6 +263,10 @@ Rails/CreateTableWithTimestamps:
202
263
  VersionAdded: '0.52'
203
264
  Include:
204
265
  - db/migrate/*.rb
266
+ Exclude:
267
+ # Respect the `active_storage_variant_records` table of `*_create_active_storage_tables.active_storage.rb`
268
+ # auto-generated by `bin/rails active_storage:install` even if `created_at` is not specified.
269
+ - db/migrate/*_create_active_storage_tables.active_storage.rb
205
270
 
206
271
  Rails/Date:
207
272
  Description: >-
@@ -243,6 +308,35 @@ Rails/DelegateAllowBlank:
243
308
  Enabled: true
244
309
  VersionAdded: '0.44'
245
310
 
311
+ Rails/DeprecatedActiveModelErrorsMethods:
312
+ Description: 'Avoid manipulating ActiveModel errors hash directly.'
313
+ Enabled: true
314
+ Safe: false
315
+ VersionAdded: '2.14'
316
+ VersionChanged: '2.15'
317
+
318
+ Rails/DotSeparatedKeys:
319
+ Description: 'Enforces the use of dot-separated keys instead of `:scope` options in `I18n` translation methods.'
320
+ StyleGuide: 'https://rails.rubystyle.guide/#dot-separated-keys'
321
+ Enabled: false # if they key is set dynamically, using the scope option is more favorable than using dot-separated keys with string interpolation
322
+ VersionAdded: '2.15'
323
+
324
+ Rails/DuplicateAssociation:
325
+ Description: "Don't repeat associations in a model."
326
+ Enabled: true
327
+ VersionAdded: '2.14'
328
+
329
+ Rails/DuplicateScope:
330
+ Description: 'Multiple scopes share this same where clause.'
331
+ Enabled: true
332
+ VersionAdded: '2.14'
333
+
334
+ Rails/DurationArithmetic:
335
+ Description: 'Do not use duration as arithmetic operand with `Time.current`.'
336
+ StyleGuide: 'https://rails.rubystyle.guide#duration-arithmetic'
337
+ Enabled: true
338
+ VersionAdded: '2.13'
339
+
246
340
  Rails/DynamicFindBy:
247
341
  Description: 'Use `find_by` instead of dynamic `find_by_*`.'
248
342
  StyleGuide: 'https://rails.rubystyle.guide#find_by'
@@ -252,10 +346,13 @@ Rails/DynamicFindBy:
252
346
  # The `Whitelist` has been deprecated, Please use `AllowedMethods` instead.
253
347
  Whitelist:
254
348
  - find_by_sql
349
+ - find_by_token_for
255
350
  AllowedMethods:
256
351
  - find_by_sql
352
+ - find_by_token_for
257
353
  AllowedReceivers:
258
354
  - Gem::Specification
355
+ - page # Prevents a warning for `page.find_by_id`. See: https://github.com/rubocop/rubocop-rails/issues/778
259
356
 
260
357
  Rails/EagerEvaluationLogMessage:
261
358
  Description: 'Checks that blocks are used for interpolated strings passed to `Rails.logger.debug`.'
@@ -351,12 +448,20 @@ Rails/FindEach:
351
448
  VersionChanged: '2.9'
352
449
  Include:
353
450
  - app/models/**/*.rb
354
- IgnoredMethods:
451
+ AllowedMethods:
355
452
  # Methods that don't work well with `find_each`.
356
453
  - order
357
454
  - limit
358
455
  - select
359
456
  - lock
457
+ AllowedPatterns: []
458
+
459
+ Rails/FreezeTime:
460
+ Description: 'Prefer `freeze_time` over `travel_to` with an argument of the current time.'
461
+ StyleGuide: 'https://rails.rubystyle.guide/#freeze-time'
462
+ Enabled: false # dangerous because freeze_time calls travel_to with Time.now but the cop also indicates usages of Time.current or other timezone-dependent times which are not the same as Time.now
463
+ VersionAdded: '2.16'
464
+ SafeAutoCorrect: false
360
465
 
361
466
  Rails/HasAndBelongsToMany:
362
467
  Description: 'Prefer has_many :through to has_and_belongs_to_many.'
@@ -399,6 +504,15 @@ Rails/HttpStatus:
399
504
  - numeric
400
505
  - symbolic
401
506
 
507
+ Rails/I18nLazyLookup:
508
+ Description: 'Checks for places where I18n "lazy" lookup can be used.'
509
+ StyleGuide: 'https://rails.rubystyle.guide/#lazy-lookup'
510
+ Reference: 'https://guides.rubyonrails.org/i18n.html#lazy-lookup'
511
+ Enabled: true
512
+ VersionAdded: '2.14'
513
+ Include:
514
+ - 'controllers/**/*'
515
+
402
516
  Rails/I18nLocaleAssignment:
403
517
  Description: 'Prefer the usage of `I18n.with_locale` instead of manually updating `I18n.locale` value.'
404
518
  Enabled: false
@@ -407,6 +521,19 @@ Rails/I18nLocaleAssignment:
407
521
  - spec/**/*.rb
408
522
  - test/**/*.rb
409
523
 
524
+ Rails/I18nLocaleTexts:
525
+ Description: 'Enforces use of I18n and locale files instead of locale specific strings.'
526
+ StyleGuide: 'https://rails.rubystyle.guide/#locale-texts'
527
+ Enabled: true
528
+ VersionAdded: '2.14'
529
+
530
+ Rails/IgnoredColumnsAssignment:
531
+ Description: 'Looks for assignments of `ignored_columns` that override previous assignments.'
532
+ StyleGuide: 'https://rails.rubystyle.guide/#append-ignored-columns'
533
+ Enabled: false # we don't really use ignored_columns
534
+ SafeAutoCorrect: false
535
+ VersionAdded: '2.17'
536
+
410
537
  Rails/IgnoredSkipActionFilterOption:
411
538
  Description: 'Checks that `if` and `only` (or `except`) are not used together as options of `skip_*` action filter.'
412
539
  Reference: 'https://api.rubyonrails.org/classes/AbstractController/Callbacks/ClassMethods.html#method-i-_normalize_callback_options'
@@ -414,6 +541,7 @@ Rails/IgnoredSkipActionFilterOption:
414
541
  VersionAdded: '0.63'
415
542
  Include:
416
543
  - app/controllers/**/*.rb
544
+ - app/mailers/**/*.rb
417
545
 
418
546
  Rails/IndexBy:
419
547
  Description: 'Prefer `index_by` over `each_with_object`, `to_h`, or `map`.'
@@ -437,17 +565,19 @@ Rails/InverseOf:
437
565
  Description: 'Checks for associations where the inverse cannot be determined automatically.'
438
566
  Enabled: true
439
567
  VersionAdded: '0.52'
568
+ IgnoreScopes: false
440
569
  Include:
441
570
  - app/models/**/*.rb
442
571
 
443
572
  Rails/LexicallyScopedActionFilter:
444
- Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the controller."
573
+ Description: "Checks that methods specified in the filter's `only` or `except` options are explicitly defined in the class."
445
574
  StyleGuide: 'https://rails.rubystyle.guide#lexically-scoped-action-filter'
446
575
  Enabled: true
447
576
  Safe: false
448
577
  VersionAdded: '0.52'
449
578
  Include:
450
579
  - app/controllers/**/*.rb
580
+ - app/mailers/**/*.rb
451
581
 
452
582
  Rails/LinkToBlank:
453
583
  Description: 'Checks that `link_to` with a `target: "_blank"` have a `rel: "noopener"` option passed to them.'
@@ -478,6 +608,13 @@ Rails/MatchRoute:
478
608
  - config/routes.rb
479
609
  - config/routes/**/*.rb
480
610
 
611
+ Rails/MigrationClassName:
612
+ Description: 'The class name of the migration should match its file name.'
613
+ Enabled: true
614
+ VersionAdded: '2.14'
615
+ Include:
616
+ - db/migrate/*.rb
617
+
481
618
  Rails/NegateInclude:
482
619
  Description: 'Prefer `collection.exclude?(obj)` over `!collection.include?(obj)`.'
483
620
  StyleGuide: 'https://rails.rubystyle.guide#exclude'
@@ -504,6 +641,7 @@ Rails/OrderById:
504
641
  Rails/Output:
505
642
  Description: 'Checks for calls to puts, print, etc.'
506
643
  Enabled: false
644
+ SafeAutoCorrect: false
507
645
  VersionAdded: '0.15'
508
646
  VersionChanged: '0.19'
509
647
  Include:
@@ -607,11 +745,25 @@ Rails/RedundantForeignKey:
607
745
  Enabled: true
608
746
  VersionAdded: '2.6'
609
747
 
748
+ Rails/RedundantPresenceValidationOnBelongsTo:
749
+ Description: 'Checks for redundant presence validation on belongs_to association.'
750
+ Enabled: true
751
+ SafeAutoCorrect: false
752
+ VersionAdded: '2.13'
753
+
610
754
  Rails/RedundantReceiverInWithOptions:
611
755
  Description: 'Checks for redundant receiver in `with_options`.'
612
756
  Enabled: true
613
757
  VersionAdded: '0.52'
614
758
 
759
+ Rails/RedundantTravelBack:
760
+ Description: Checks for redundant `travel_back` calls.
761
+ Enabled: true
762
+ VersionAdded: '2.12'
763
+ Include:
764
+ - spec/**/*.rb
765
+ - test/**/*.rb
766
+
615
767
  Rails/ReflectionClassName:
616
768
  Description: 'Use a string for `class_name` option value in the definition of a reflection.'
617
769
  Enabled: true
@@ -633,9 +785,9 @@ Rails/RefuteMethods:
633
785
  Rails/RelativeDateConstant:
634
786
  Description: 'Do not assign relative date to constants.'
635
787
  Enabled: true
788
+ SafeAutoCorrect: false
636
789
  VersionAdded: '0.48'
637
- VersionChanged: '0.59'
638
- AutoCorrect: false
790
+ VersionChanged: '2.13'
639
791
 
640
792
  Rails/RenderInline:
641
793
  Description: 'Prefer using a template over inline rendering.'
@@ -672,15 +824,33 @@ Rails/ReversibleMigration:
672
824
  Reference: 'https://api.rubyonrails.org/classes/ActiveRecord/Migration/CommandRecorder.html'
673
825
  Enabled: true
674
826
  VersionAdded: '0.47'
827
+ VersionChanged: '2.13'
675
828
  Include:
676
- - db/migrate/*.rb
829
+ - db/**/*.rb
677
830
 
678
831
  Rails/ReversibleMigrationMethodDefinition:
679
832
  Description: 'Checks whether the migration implements either a `change` method or both an `up` and a `down` method.'
680
- Enabled: false # If the migration starts with a class definition, no change-, up-, or down-method is recognized, although they exist
833
+ Enabled: false
681
834
  VersionAdded: '2.10'
835
+ VersionChanged: '2.13'
682
836
  Include:
683
- - db/migrate/*.rb
837
+ - db/**/*.rb
838
+
839
+ Rails/RootJoinChain:
840
+ Description: 'Use a single `#join` instead of chaining on `Rails.root` or `Rails.public_path`.'
841
+ Enabled: true
842
+ VersionAdded: '2.13'
843
+
844
+ Rails/RootPathnameMethods:
845
+ Description: 'Use `Rails.root` IO methods instead of passing it to `File`.'
846
+ Enabled: true
847
+ SafeAutoCorrect: false
848
+ VersionAdded: '2.16'
849
+
850
+ Rails/RootPublicPath:
851
+ Description: "Favor `Rails.public_path` over `Rails.root` with `'public'`."
852
+ Enabled: false
853
+ VersionAdded: '2.15'
684
854
 
685
855
  Rails/SafeNavigation:
686
856
  Description: "Use Ruby's safe navigation operator (`&.`) instead of `try!`."
@@ -714,10 +884,18 @@ Rails/SaveBang:
714
884
  AllowedReceivers: []
715
885
  SafeAutoCorrect: false
716
886
 
887
+ Rails/SchemaComment:
888
+ Description: >-
889
+ Enforces the use of the `comment` option when adding a new table or column
890
+ to the database during a migration.
891
+ Enabled: false
892
+ VersionAdded: '2.13'
893
+
717
894
  Rails/ScopeArgs:
718
895
  Description: 'Checks the arguments of ActiveRecord scopes.'
719
896
  Enabled: true
720
897
  VersionAdded: '0.19'
898
+ VersionChanged: '2.12'
721
899
  Include:
722
900
  - app/models/**/*.rb
723
901
 
@@ -767,17 +945,32 @@ Rails/SquishedSQLHeredocs:
767
945
  VersionAdded: '2.8'
768
946
  VersionChanged: '2.9'
769
947
  # Some SQL syntax (e.g. PostgreSQL comments and functions) requires newlines
770
- # to be preserved in order to work, thus auto-correction is not safe.
948
+ # to be preserved in order to work, thus autocorrection is not safe.
771
949
  SafeAutoCorrect: false
772
950
 
951
+ Rails/StripHeredoc:
952
+ Description: 'Enforces the use of squiggly heredoc over `strip_heredoc`.'
953
+ StyleGuide: 'https://rails.rubystyle.guide/#prefer-squiggly-heredoc'
954
+ Enabled: true
955
+ VersionAdded: '2.15'
956
+
957
+ Rails/TableNameAssignment:
958
+ Description: >-
959
+ Do not use `self.table_name =`. Use Inflections or `table_name_prefix` instead.
960
+ StyleGuide: 'https://rails.rubystyle.guide/#keep-ar-defaults'
961
+ Enabled: false
962
+ VersionAdded: '2.14'
963
+ Include:
964
+ - app/models/**/*.rb
965
+
773
966
  Rails/TimeZone:
774
967
  Description: 'Checks the correct usage of time zone aware methods.'
775
968
  StyleGuide: 'https://rails.rubystyle.guide#time'
776
969
  Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
777
970
  Enabled: false
778
- Safe: false
971
+ SafeAutoCorrect: false
779
972
  VersionAdded: '0.30'
780
- VersionChanged: '2.10'
973
+ VersionChanged: '2.13'
781
974
  # The value `strict` means that `Time` should be used with `zone`.
782
975
  # The value `flexible` allows usage of `in_time_zone` instead of `zone`.
783
976
  EnforcedStyle: flexible
@@ -796,6 +989,33 @@ Rails/TimeZoneAssignment:
796
989
  - spec/**/*.rb
797
990
  - test/**/*.rb
798
991
 
992
+ Rails/ToFormattedS:
993
+ Description: 'Checks for consistent uses of `to_fs` or `to_formatted_s`.'
994
+ StyleGuide: 'https://rails.rubystyle.guide/#prefer-to-fs'
995
+ Enabled: true
996
+ EnforcedStyle: to_formatted_s
997
+ SupportedStyles:
998
+ - to_fs
999
+ - to_formatted_s
1000
+ VersionAdded: '2.15'
1001
+
1002
+ Rails/ToSWithArgument:
1003
+ Description: 'Identifies passing any argument to `#to_s`.'
1004
+ Enabled: false
1005
+ Safe: false
1006
+ VersionAdded: '2.16'
1007
+
1008
+ Rails/TopLevelHashWithIndifferentAccess:
1009
+ Description: 'Identifies top-level `HashWithIndifferentAccess`.'
1010
+ Reference: 'https://guides.rubyonrails.org/upgrading_ruby_on_rails.html#top-level-hashwithindifferentaccess-is-soft-deprecated'
1011
+ Enabled: true
1012
+ VersionAdded: '2.16'
1013
+
1014
+ Rails/TransactionExitStatement:
1015
+ Description: 'Avoid the usage of `return`, `break` and `throw` in transaction blocks.'
1016
+ Enabled: true # Get a head start on deprecations: https://blog.saeloun.com/2020/04/06/rails-disallow-return-break-and-throw-to-exit-transaction.html
1017
+ VersionAdded: '2.14'
1018
+
799
1019
  Rails/UniqBeforePluck:
800
1020
  Description: 'Prefer the use of uniq or distinct before pluck.'
801
1021
  Enabled: true
@@ -806,7 +1026,6 @@ Rails/UniqBeforePluck:
806
1026
  - conservative
807
1027
  - aggressive
808
1028
  SafeAutoCorrect: false
809
- AutoCorrect: false
810
1029
 
811
1030
  Rails/UniqueValidationWithoutIndex:
812
1031
  Description: 'Uniqueness validation should be with a unique index.'
@@ -856,12 +1075,29 @@ Rails/WhereExists:
856
1075
  VersionAdded: '2.7'
857
1076
  VersionChanged: '2.10'
858
1077
 
1078
+ Rails/WhereMissing:
1079
+ Description: 'Use `where.missing(...)` to find missing relationship records.'
1080
+ StyleGuide: 'https://rails.rubystyle.guide/#finding-missing-relationship-records'
1081
+ Enabled: true
1082
+ VersionAdded: '2.16'
1083
+
859
1084
  Rails/WhereNot:
860
1085
  Description: 'Use `where.not(...)` instead of manually constructing negated SQL in `where`.'
861
1086
  StyleGuide: 'https://rails.rubystyle.guide/#hash-conditions'
862
1087
  Enabled: true
863
1088
  VersionAdded: '2.8'
864
1089
 
1090
+ Rails/WhereNotWithMultipleConditions:
1091
+ Description: 'Do not use `where.not(...)` with multiple conditions.'
1092
+ Enabled: true
1093
+ VersionAdded: '2.17'
1094
+
865
1095
  # Accept `redirect_to(...) and return` and similar cases.
866
1096
  Style/AndOr:
867
1097
  EnforcedStyle: conditionals
1098
+
1099
+ Style/SymbolProc:
1100
+ AllowedMethods:
1101
+ - define_method
1102
+ - mail
1103
+ - respond_to