From 2b8728acb9e6883f60da95b186b115dcbe6df9cb Mon Sep 17 00:00:00 2001 From: Damir Svrtan Date: Mon, 13 Mar 2023 22:25:11 -0700 Subject: [PATCH] Fix select first with arguments vs detect --- CHANGELOG.md | 4 ++++ lib/fasterer/scanners/method_call_scanner.rb | 1 + lib/fasterer/version.rb | 2 +- spec/support/analyzer/12_select_first_vs_detect.rb | 2 ++ 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fee00f1..2898c30 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 0.10.1 + +- There has been a [bug report #99](https://github.com/DamirSvrtan/fasterer/issues/99) that the `select_first_vs_detect` reports false positives when first gets an argument passed in. If there is an argument passed in, the detect method is not suitable, since it always returns the first element matching (can't return multiple items). + ## 0.10.0 - Due to issues while setting up builds with Github Actions, I have dropped Ruby 2.2 support. It's EOL date was 2018-03-31, and I don't have the bandwidth to support deprecated Ruby versions. The only reason at this point why Ruby versions 2.3, 2.4 and 2.5 are supported is because they still work with other dependencies, so it's no effort currently to support them. Once they become issues, they'll probably be dropped. diff --git a/lib/fasterer/scanners/method_call_scanner.rb b/lib/fasterer/scanners/method_call_scanner.rb index a8f976e..a020c8d 100644 --- a/lib/fasterer/scanners/method_call_scanner.rb +++ b/lib/fasterer/scanners/method_call_scanner.rb @@ -86,6 +86,7 @@ def check_first_offense add_offense(:shuffle_first_vs_sample) when :select return unless method_call.receiver.has_block? + return if method_call.arguments.count > 0 add_offense(:select_first_vs_detect) end diff --git a/lib/fasterer/version.rb b/lib/fasterer/version.rb index b1666ef..d88db48 100644 --- a/lib/fasterer/version.rb +++ b/lib/fasterer/version.rb @@ -1,3 +1,3 @@ module Fasterer - VERSION = '0.10.0' + VERSION = '0.10.1' end diff --git a/spec/support/analyzer/12_select_first_vs_detect.rb b/spec/support/analyzer/12_select_first_vs_detect.rb index 9abc135..ede960e 100644 --- a/spec/support/analyzer/12_select_first_vs_detect.rb +++ b/spec/support/analyzer/12_select_first_vs_detect.rb @@ -9,3 +9,5 @@ ARRAY.select(&:zero?).first ActiveRecordRelation.new.select('name').first + +ARRAY.select { |x| x.eql?(15) }.first(5) \ No newline at end of file