Remove buggy auto-correction from Performance/AnyInsteadOfEmpty rule

This commit is contained in:
Sijawusz Pur Rahnama 2023-01-04 02:40:07 +01:00
parent f7cb5bb563
commit 6f0b6ffcd0
2 changed files with 3 additions and 15 deletions

View file

@ -14,14 +14,10 @@ module Ameba::Rule::Performance
end end
it "reports if there is any? call without a block nor argument" do 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? [1, 2, 3].any?
# ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?` # ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?`
CRYSTAL CRYSTAL
expect_correction source, <<-CRYSTAL
![1, 2, 3].empty?
CRYSTAL
end end
it "does not report if source is a spec" do it "does not report if source is a spec" do
@ -32,14 +28,10 @@ module Ameba::Rule::Performance
context "macro" do context "macro" do
it "reports in macro scope" do it "reports in macro scope" do
source = expect_issue subject, <<-CRYSTAL expect_issue subject, <<-CRYSTAL
{{ [1, 2, 3].any? }} {{ [1, 2, 3].any? }}
# ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?` # ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?`
CRYSTAL CRYSTAL
expect_correction source, <<-CRYSTAL
{{ ![1, 2, 3].empty? }}
CRYSTAL
end end
end end
end end

View file

@ -42,14 +42,10 @@ module Ameba::Rule::Performance
return unless node.block.nil? && node.args.empty? return unless node.block.nil? && node.args.empty?
return unless node.obj return unless node.obj
return unless location = node.location
return unless name_location = node.name_location return unless name_location = node.name_location
return unless end_location = name_end_location(node) return unless end_location = name_end_location(node)
issue_for name_location, end_location, MSG do |corrector| issue_for name_location, end_location, MSG
corrector.insert_before(location, '!')
corrector.replace(name_location, end_location, "empty?")
end
end end
end end
end end