From 1a66130ae265d29777073d4fc79540acd8eae76e Mon Sep 17 00:00:00 2001 From: Damir Svrtan Date: Tue, 4 Feb 2020 21:30:26 -0800 Subject: [PATCH] Fix symbol to proc offense detector when a method is invoked on a range or array Fixes the following issue: https://github.com/DamirSvrtan/fasterer/issues/77. Happens when somebody invokes a method with no args on an array or range in a block. Example in the spec. --- lib/fasterer/scanners/method_call_scanner.rb | 1 + spec/support/analyzer/18_block_vs_symbol_to_proc.rb | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/lib/fasterer/scanners/method_call_scanner.rb b/lib/fasterer/scanners/method_call_scanner.rb index 52f3bf0..a8f976e 100644 --- a/lib/fasterer/scanners/method_call_scanner.rb +++ b/lib/fasterer/scanners/method_call_scanner.rb @@ -132,6 +132,7 @@ def check_symbol_to_proc return unless body_method_call.arguments.count.zero? return if body_method_call.has_block? return if body_method_call.receiver.nil? + return if body_method_call.receiver.is_a?(Fasterer::Primitive) return if body_method_call.receiver.name != method_call.block_argument_names.first add_offense(:block_vs_symbol_to_proc) diff --git a/spec/support/analyzer/18_block_vs_symbol_to_proc.rb b/spec/support/analyzer/18_block_vs_symbol_to_proc.rb index a85ef3c..a2b062a 100644 --- a/spec/support/analyzer/18_block_vs_symbol_to_proc.rb +++ b/spec/support/analyzer/18_block_vs_symbol_to_proc.rb @@ -11,6 +11,10 @@ puts route.name end +route_sets.each do |routes| + [].finalize! +end + route_sets.each(&:finalize!) route_sets.each(:oppa) do |route|