@@ -78,6 +78,11 @@ skip_after_filter :do_stuff
78
78
Checks that ActiveRecord aliases are not used. The direct method names
79
79
are more clear and easier to read.
80
80
81
+ === Safety
82
+
83
+ This cop is unsafe because custom `update_attributes` method call was changed to
84
+ `update` but the method name remained same in the method definition.
85
+
81
86
=== Examples
82
87
83
88
[source,ruby]
@@ -309,7 +314,12 @@ after_update_commit :log_update_action
309
314
| 2.5
310
315
|===
311
316
312
- This cop checks that controllers subclass ApplicationController.
317
+ This cop checks that controllers subclass `ApplicationController`.
318
+
319
+ === Safety
320
+
321
+ This cop's autocorrection is unsafe because it may let the logic from `ApplicationController`
322
+ sneak into a controller that is not purposed to inherit logic common among other controllers.
313
323
314
324
=== Examples
315
325
338
348
| 2.5
339
349
|===
340
350
341
- This cop checks that jobs subclass ApplicationJob with Rails 5.0.
351
+ This cop checks that jobs subclass `ApplicationJob` with Rails 5.0.
352
+
353
+ === Safety
354
+
355
+ This cop's autocorrection is unsafe because it may let the logic from `ApplicationJob`
356
+ sneak into a job that is not purposed to inherit logic common among other jobs.
342
357
343
358
=== Examples
344
359
367
382
| 2.5
368
383
|===
369
384
370
- This cop checks that mailers subclass ApplicationMailer with Rails 5.0.
385
+ This cop checks that mailers subclass `ApplicationMailer` with Rails 5.0.
386
+
387
+ === Safety
388
+
389
+ This cop's autocorrection is unsafe because it may let the logic from `ApplicationMailer`
390
+ sneak into a mailer that is not purposed to inherit logic common among other mailers.
371
391
372
392
=== Examples
373
393
396
416
| 2.5
397
417
|===
398
418
399
- This cop checks that models subclass ApplicationRecord with Rails 5.0.
419
+ This cop checks that models subclass `ApplicationRecord` with Rails 5.0.
420
+
421
+ === Safety
422
+
423
+ This cop's autocorrection is unsafe because it may let the logic from `ApplicationRecord`
424
+ sneak into an Active Record model that is not purposed to inherit logic common among other
425
+ Active Record models.
400
426
401
427
=== Examples
402
428
@@ -432,6 +458,13 @@ quoted asterisk (e.g. <tt>`my_model`.`*`</tt>). This causes the
432
458
database to look for a column named <tt>`*`</tt> (or `"*"`) as opposed
433
459
to expanding the column list as one would likely expect.
434
460
461
+ === Safety
462
+
463
+ This cop's autocorrection is unsafe because it turns a quoted `*` into
464
+ an SQL `*`, unquoted. `*` is a valid column name in certain databases
465
+ supported by Rails, and even though it is usually a mistake,
466
+ it might denote legitimate access to a column named `*`.
467
+
435
468
=== Examples
436
469
437
470
[source,ruby]
@@ -637,15 +670,17 @@ end
637
670
This cop checks for code that can be written with simpler conditionals
638
671
using `Object#blank?` defined by Active Support.
639
672
640
- This cop is marked as unsafe auto-correction, because `' '.empty?` returns false,
641
- but `' '.blank?` returns true. Therefore, auto-correction is not compatible
642
- if the receiver is a non-empty blank string, tab, or newline meta characters.
643
-
644
673
Interaction with `Style/UnlessElse`:
645
674
The configuration of `NotPresent` will not produce an offense in the
646
675
context of `unless else` if `Style/UnlessElse` is inabled. This is
647
676
to prevent interference between the auto-correction of the two cops.
648
677
678
+ === Safety
679
+
680
+ This cop is unsafe auto-correction, because `' '.empty?` returns false,
681
+ but `' '.blank?` returns true. Therefore, auto-correction is not compatible
682
+ if the receiver is a non-empty blank string, tab, or newline meta characters.
683
+
649
684
=== Examples
650
685
651
686
==== NilOrEmpty: true (default)
@@ -1187,6 +1222,11 @@ This cop checks dynamic `find_by_*` methods.
1187
1222
Use `find_by` instead of dynamic method.
1188
1223
See. https://rails.rubystyle.guide#find_by
1189
1224
1225
+ === Safety
1226
+
1227
+ It is certainly unsafe when not configured properly, i.e. user-defined `find_by_xxx`
1228
+ method is not added to cop's `AllowedMethods`.
1229
+
1190
1230
=== Examples
1191
1231
1192
1232
[source,ruby]
@@ -2407,6 +2447,8 @@ end
2407
2447
This cop checks that methods specified in the filter's `only` or
2408
2448
`except` options are defined within the same class or module.
2409
2449
2450
+ === Safety
2451
+
2410
2452
You can technically specify methods of superclass or methods added by
2411
2453
mixins on the filter, but these can confuse developers. If you specify
2412
2454
methods that are defined in other classes or modules, you should
@@ -2563,6 +2605,11 @@ This cop enforces that mailer names end with `Mailer` suffix.
2563
2605
Without the `Mailer` suffix it isn't immediately apparent what's a mailer
2564
2606
and which views are related to the mailer.
2565
2607
2608
+ === Safety
2609
+
2610
+ This cop's autocorrection is unsafe because renaming a constant is
2611
+ always an unsafe operation.
2612
+
2566
2613
=== Examples
2567
2614
2568
2615
[source,ruby]
@@ -2658,8 +2705,10 @@ match 'photos/:id', to: 'photos#show', via: :all
2658
2705
This cop enforces the use of `collection.exclude?(obj)`
2659
2706
over `!collection.include?(obj)`.
2660
2707
2661
- It is marked as unsafe by default because false positive will occur for
2662
- a receiver object that do not have `exclude?` method. (e.g. `IPAddr`)
2708
+ === Safety
2709
+
2710
+ This cop is unsafe because false positive will occur for
2711
+ receiver objects that do not have an `exclude?` method. (e.g. `IPAddr`)
2663
2712
2664
2713
=== Examples
2665
2714
@@ -2769,6 +2818,11 @@ scope :chronological, -> { order(created_at: :asc) }
2769
2818
2770
2819
This cop checks for the use of output calls like puts and print
2771
2820
2821
+ === Safety
2822
+
2823
+ This cop's autocorrection is unsafe because depending on the Rails log level configuration,
2824
+ changing from `puts` to `Rails.logger.debug` could result in no output being shown.
2825
+
2772
2826
=== Examples
2773
2827
2774
2828
[source,ruby]
@@ -2886,6 +2940,14 @@ Using `pluck` followed by `first` creates an intermediate array, which
2886
2940
`pick` avoids. When called on an Active Record relation, `pick` adds a
2887
2941
limit to the query so that only one value is fetched from the database.
2888
2942
2943
+ === Safety
2944
+
2945
+ This cop is unsafe because `pluck` is defined on both `ActiveRecord::Relation` and `Enumerable`,
2946
+ whereas `pick` is only defined on `ActiveRecord::Relation` in Rails 6.0. This was addressed
2947
+ in Rails 6.1 via rails/rails#38760, at which point the cop is safe.
2948
+
2949
+ See: https://github.com/rubocop/rubocop-rails/pull/249
2950
+
2889
2951
=== Examples
2890
2952
2891
2953
[source,ruby]
@@ -2952,6 +3014,10 @@ Post.published.pluck(:title)
2952
3014
2953
3015
This cop enforces the use of `ids` over `pluck(:id)` and `pluck(primary_key)`.
2954
3016
3017
+ === Safety
3018
+
3019
+ This cop is unsafe if the receiver object is not an Active Record object.
3020
+
2955
3021
=== Examples
2956
3022
2957
3023
[source,ruby]
@@ -2995,11 +3061,13 @@ and can be replaced with `select`.
2995
3061
Since `pluck` is an eager method and hits the database immediately,
2996
3062
using `select` helps to avoid additional database queries.
2997
3063
2998
- This cop has two different enforcement modes. When the EnforcedStyle
2999
- is conservative (the default) then only calls to `pluck` on a constant
3064
+ This cop has two different enforcement modes. When the ` EnforcedStyle`
3065
+ is ` conservative` (the default) then only calls to `pluck` on a constant
3000
3066
(i.e. a model class) in the `where` is used as offenses.
3001
3067
3002
- When the EnforcedStyle is aggressive then all calls to `pluck` in the
3068
+ === Safety
3069
+
3070
+ When the `EnforcedStyle` is `aggressive` then all calls to `pluck` in the
3003
3071
`where` is used as offenses. This may lead to false positives
3004
3072
as the cop cannot replace to `select` between calls to `pluck` on an
3005
3073
`ActiveRecord::Relation` instance vs a call to `pluck` on an `Array` instance.
@@ -3231,6 +3299,12 @@ following conditions:
3231
3299
* The task does not need application code.
3232
3300
* The task invokes the `:environment` task.
3233
3301
3302
+ === Safety
3303
+
3304
+ Probably not a problem in most cases, but it is possible that calling `:environment` task
3305
+ will break a behavior. It's also slower. E.g. some task that only needs one gem to be
3306
+ loaded to run will run significantly faster without loading the whole application.
3307
+
3234
3308
=== Examples
3235
3309
3236
3310
[source,ruby]
@@ -3533,7 +3607,10 @@ end
3533
3607
3534
3608
This cop checks if the value of the option `class_name`, in
3535
3609
the definition of a reflection is a string.
3536
- It is marked as unsafe because it cannot be determined whether
3610
+
3611
+ === Safety
3612
+
3613
+ This cop is unsafe because it cannot be determined whether
3537
3614
constant or method return value specified to `class_name` is a string.
3538
3615
3539
3616
=== Examples
@@ -4206,10 +4283,20 @@ foo&.bar { |e| e.baz }
4206
4283
This cop checks to make sure safe navigation isn't used with `blank?` in
4207
4284
a conditional.
4208
4285
4286
+ === Safety
4287
+
4209
4288
While the safe navigation operator is generally a good idea, when
4210
4289
checking `foo&.blank?` in a conditional, `foo` being `nil` will actually
4211
4290
do the opposite of what the author intends.
4212
4291
4292
+ For example:
4293
+
4294
+ [source,ruby]
4295
+ ----
4296
+ foo&.blank? #=> nil
4297
+ foo.blank? #=> true
4298
+ ----
4299
+
4213
4300
=== Examples
4214
4301
4215
4302
[source,ruby]
@@ -4257,6 +4344,26 @@ that behavior can be turned off with `AllowImplicitReturn: false`.
4257
4344
You can permit receivers that are giving false positives with
4258
4345
`AllowedReceivers: []`
4259
4346
4347
+ === Safety
4348
+
4349
+ This cop's autocorrection is unsafe because a custom `update` method call would be changed to `update!`,
4350
+ but the method name in the definition would be unchanged.
4351
+
4352
+ [source,ruby]
4353
+ ----
4354
+ # Original code
4355
+ def update_attributes
4356
+ end
4357
+
4358
+ update_attributes
4359
+
4360
+ # After running rubocop --safe-auto-correct
4361
+ def update_attributes
4362
+ end
4363
+
4364
+ update
4365
+ ----
4366
+
4260
4367
=== Examples
4261
4368
4262
4369
[source,ruby]
@@ -4552,6 +4659,9 @@ user.touch
4552
4659
|===
4553
4660
4554
4661
Checks SQL heredocs to use `.squish`.
4662
+
4663
+ === Safety
4664
+
4555
4665
Some SQL syntax (e.g. PostgreSQL comments and functions) requires newlines
4556
4666
to be preserved in order to work, thus auto-correction for this cop is not safe.
4557
4667
@@ -4617,6 +4727,10 @@ then only use of `Time.zone` is allowed.
4617
4727
When EnforcedStyle is 'flexible' then it's also allowed
4618
4728
to use `Time#in_time_zone`.
4619
4729
4730
+ === Safety
4731
+
4732
+ This cop's autocorrection is unsafe because it may change handling time.
4733
+
4620
4734
=== Examples
4621
4735
4622
4736
[source,ruby]
@@ -4743,6 +4857,8 @@ as the cop cannot distinguish between calls to pluck on an
4743
4857
ActiveRecord::Relation vs a call to pluck on an
4744
4858
ActiveRecord::Associations::CollectionProxy.
4745
4859
4860
+ === Safety
4861
+
4746
4862
This cop is unsafe because the behavior may change depending on the
4747
4863
database collation.
4748
4864
Autocorrect is disabled by default for this cop since it may generate
@@ -4993,6 +5109,11 @@ validates :foo, uniqueness: true
4993
5109
This cop identifies places where manually constructed SQL
4994
5110
in `where` can be replaced with `where(attribute: value)`.
4995
5111
5112
+ === Safety
5113
+
5114
+ This cop's autocorrection is unsafe because is may change SQL.
5115
+ See: https://github.com/rubocop/rubocop-rails/issues/403
5116
+
4996
5117
=== Examples
4997
5118
4998
5119
[source,ruby]
@@ -5036,6 +5157,8 @@ then the cop enforces `exists?(...)` over `where(...).exists?`.
5036
5157
When EnforcedStyle is 'where' then the cop enforces
5037
5158
`where(...).exists?` over `exists?(...)`.
5038
5159
5160
+ === Safety
5161
+
5039
5162
This cop is unsafe for auto-correction because the behavior may change on the following case:
5040
5163
5041
5164
[source,ruby]
0 commit comments