Properly report performance rules in macros

closes #102
This commit is contained in:
Vitalii Elenhaupt 2019-05-05 18:04:25 +03:00
parent 2ddf26b8c3
commit 94e1d4567a
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
6 changed files with 51 additions and 2 deletions

View file

@ -48,6 +48,15 @@ module Ameba::Rule::Performance
end
end
context "macro" do
it "reports in macro scope" do
source = Source.new %(
{{ [1, 2, 3].reject { |e| e > 2 }.any? }}
)
subject.catch(source).should_not be_valid
end
end
it "reports rule, pos and message" do
s = Source.new %(
[1, 2, 3].reject { |e| e > 2 }.any?

View file

@ -107,6 +107,15 @@ module Ameba::Rule::Performance
issue.message.should eq "Use `reverse_each.find {...}` instead of `select {...}.last`"
end
context "macro" do
it "doesn't report in macro scope" do
source = Source.new %(
{{[1, 2, 3].select { |e| e > 2 }.last }}
)
subject.catch(source).should be_valid
end
end
it "reports a correct message for last?" do
s = Source.new %(
[1, 2, 3].select { |e| e > 2 }.last?

View file

@ -49,6 +49,15 @@ module Ameba::Rule::Performance
end
end
context "macro" do
it "doesn't report in macro scope" do
source = Source.new %(
{{[1, 2, 3].select { |v| v > 1 }.size}}
)
subject.catch(source).should be_valid
end
end
it "reports rule, pos and message" do
s = Source.new %(
lines.split("\n").reject(&.empty?).size