mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add Performance/JoinAfterMap rule
This commit is contained in:
parent
06852c490b
commit
a892cd43b0
2 changed files with 106 additions and 0 deletions
58
spec/ameba/rule/performance/join_after_map_spec.cr
Normal file
58
spec/ameba/rule/performance/join_after_map_spec.cr
Normal file
|
@ -0,0 +1,58 @@
|
|||
require "../../../spec_helper"
|
||||
|
||||
module Ameba::Rule::Performance
|
||||
subject = JoinAfterMap.new
|
||||
|
||||
describe JoinAfterMap do
|
||||
it "passes if there is no potential performance improvements" do
|
||||
source = Source.new %(
|
||||
(1..3).join(&.to_s)
|
||||
(1..3).join('.', &.to_s)
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
end
|
||||
|
||||
it "reports if there is map followed by join without a block" do
|
||||
source = Source.new %(
|
||||
(1..3).map(&.to_s).join
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
end
|
||||
|
||||
it "reports if there is map followed by join without a block (with argument)" do
|
||||
source = Source.new %(
|
||||
(1..3).map(&.to_s).join('.')
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
end
|
||||
|
||||
it "reports if there is map followed by join with a block" do
|
||||
source = Source.new %(
|
||||
(1..3).map(&.to_s).join(&.itself)
|
||||
)
|
||||
subject.catch(source).should_not be_valid
|
||||
end
|
||||
|
||||
context "macro" do
|
||||
it "doesn't report in macro scope" do
|
||||
source = Source.new %(
|
||||
{{ [1, 2, 3].map(&.to_s).join }}
|
||||
)
|
||||
subject.catch(source).should be_valid
|
||||
end
|
||||
end
|
||||
|
||||
it "reports rule, pos and message" do
|
||||
s = Source.new %(
|
||||
(1..3).map(&.to_s).join
|
||||
), "source.cr"
|
||||
subject.catch(s).should_not be_valid
|
||||
issue = s.issues.first
|
||||
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:8"
|
||||
issue.end_location.to_s.should eq "source.cr:1:24"
|
||||
issue.message.should eq "Use `join(separator) {...}` instead of `map {...}.join(separator)`"
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue