From 6f0b6ffcd0776efcf397f6162a850f897bcdd92c Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 4 Jan 2023 02:40:07 +0100 Subject: [PATCH] Remove buggy auto-correction from `Performance/AnyInsteadOfEmpty` rule --- .../rule/performance/any_instead_of_empty_spec.cr | 12 ++---------- src/ameba/rule/performance/any_instead_of_empty.cr | 6 +----- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/spec/ameba/rule/performance/any_instead_of_empty_spec.cr b/spec/ameba/rule/performance/any_instead_of_empty_spec.cr index 1812c5dc..7d4827b9 100644 --- a/spec/ameba/rule/performance/any_instead_of_empty_spec.cr +++ b/spec/ameba/rule/performance/any_instead_of_empty_spec.cr @@ -14,14 +14,10 @@ module Ameba::Rule::Performance end it "reports if there is any? call without a block nor argument" do - source = expect_issue subject, <<-CRYSTAL + expect_issue subject, <<-CRYSTAL [1, 2, 3].any? # ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?` CRYSTAL - - expect_correction source, <<-CRYSTAL - ![1, 2, 3].empty? - CRYSTAL end it "does not report if source is a spec" do @@ -32,14 +28,10 @@ module Ameba::Rule::Performance context "macro" do it "reports in macro scope" do - source = expect_issue subject, <<-CRYSTAL + expect_issue subject, <<-CRYSTAL {{ [1, 2, 3].any? }} # ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?` CRYSTAL - - expect_correction source, <<-CRYSTAL - {{ ![1, 2, 3].empty? }} - CRYSTAL end end end diff --git a/src/ameba/rule/performance/any_instead_of_empty.cr b/src/ameba/rule/performance/any_instead_of_empty.cr index 9e8d41ee..cee76ef6 100644 --- a/src/ameba/rule/performance/any_instead_of_empty.cr +++ b/src/ameba/rule/performance/any_instead_of_empty.cr @@ -42,14 +42,10 @@ module Ameba::Rule::Performance return unless node.block.nil? && node.args.empty? return unless node.obj - return unless location = node.location return unless name_location = node.name_location return unless end_location = name_end_location(node) - issue_for name_location, end_location, MSG do |corrector| - corrector.insert_before(location, '!') - corrector.replace(name_location, end_location, "empty?") - end + issue_for name_location, end_location, MSG end end end