Merge pull request #268 from crystal-ameba/fix-issue-267

Fix regression in `AnyInsteadOfEmpty` rule
This commit is contained in:
Sijawusz Pur Rahnama 2022-04-22 16:43:11 +02:00 committed by GitHub
commit f0bf89f85f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View file

@ -16,7 +16,7 @@ module Ameba::Rule::Performance
it "reports if there is any? call without a block nor argument" do
source = expect_issue subject, <<-CRYSTAL
[1, 2, 3].any?
# ^^^^^^^^^^^^ error: Use `!{...}.empty?` instead of `{...}.any?`
# ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?`
CRYSTAL
expect_correction source, <<-CRYSTAL
@ -34,7 +34,7 @@ module Ameba::Rule::Performance
it "reports in macro scope" do
source = expect_issue subject, <<-CRYSTAL
{{ [1, 2, 3].any? }}
# ^^^^^^^^^^^^^^ error: Use `!{...}.empty?` instead of `{...}.any?`
# ^^^^ error: Use `!{...}.empty?` instead of `{...}.any?`
CRYSTAL
expect_correction source, <<-CRYSTAL
@ -51,7 +51,7 @@ module Ameba::Rule::Performance
issue = source.issues.first
issue.rule.should_not be_nil
issue.location.to_s.should eq "source.cr:1:1"
issue.location.to_s.should eq "source.cr:1:11"
issue.end_location.to_s.should eq "source.cr:1:14"
issue.message.should eq "Use `!{...}.empty?` instead of `{...}.any?`"
end

View file

@ -45,7 +45,7 @@ module Ameba::Rule::Performance
return unless name_location = node.name_location
return unless end_location = name_end_location(node)
issue_for location, end_location, MSG do |corrector|
issue_for name_location, end_location, MSG do |corrector|
corrector.insert_before(location, '!')
corrector.replace(name_location, end_location, "empty?")
end