From 83b47e3ff4892b0440fe76221a8f4b1c2c1c547d Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden <ewoud@kohlvanwijngaarden.nl> Date: Thu, 26 Jan 2023 16:05:57 +0100 Subject: [PATCH] [Fix #336] Expand the safety warning on Performance/Detect In addition to the external library activerecord, the built in Hash class also has compatibility issues. --- lib/rubocop/cop/performance/detect.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/rubocop/cop/performance/detect.rb b/lib/rubocop/cop/performance/detect.rb index 1cee1e8d93..8367c4db79 100644 --- a/lib/rubocop/cop/performance/detect.rb +++ b/lib/rubocop/cop/performance/detect.rb @@ -8,9 +8,12 @@ module Performance # `detect` instead. # # @safety - # This cop is unsafe because is has known compatibility issues with `ActiveRecord` and other - # frameworks. `ActiveRecord` does not implement a `detect` method and `find` has its own - # meaning. Correcting `ActiveRecord` methods with this cop should be considered unsafe. + # This cop is unsafe because is assumes the class implements the + # `Enumerable` interface, but can't reliably detect this. This creates + # known compatibility issues with `Hash`, `ActiveRecord` and other + # frameworks. `Hash` and `ActiveRecord` do not implement a `detect` + # method and `find` has its own meaning. Correcting `Hash` and + # `ActiveRecord` methods with this cop should be considered unsafe. # # @example # # bad