Fix Performance/ExcessiveAllocations to exclude each calls without a block

This commit is contained in:
Sijawusz Pur Rahnama 2023-06-30 21:44:47 +02:00
parent 21051acfff
commit 29e29b8e1d
2 changed files with 2 additions and 1 deletions

View file

@ -6,6 +6,7 @@ module Ameba::Rule::Performance
describe ExcessiveAllocations do
it "passes if there is no potential performance improvements" do
expect_no_issues subject, <<-CRYSTAL
"Alice".chars.each
"Alice".chars.each(arg) { |c| puts c }
"Alice".chars(arg).each { |c| puts c }
"Alice\nBob".lines.each(arg) { |l| puts l }

View file

@ -52,7 +52,7 @@ module Ameba::Rule::Performance
end
def test(source, node : Crystal::Call)
return unless node.name == "each" && node.args.empty?
return unless node.name == "each" && node.args.empty? && node.block
return unless (obj = node.obj).is_a?(Crystal::Call)
return unless obj.args.empty? && obj.block.nil?
return unless method = call_names[obj.name]?