2021-01-17 15:41:34 +00:00
|
|
|
require "../../../spec_helper"
|
|
|
|
|
|
|
|
module Ameba::Rule::Lint
|
|
|
|
subject = DuplicatedRequire.new
|
|
|
|
|
|
|
|
describe DuplicatedRequire do
|
|
|
|
it "passes if there are no duplicated requires" do
|
2021-11-06 13:15:19 +00:00
|
|
|
expect_no_issues subject, <<-CRYSTAL
|
2021-01-17 15:41:34 +00:00
|
|
|
require "math"
|
|
|
|
require "big"
|
|
|
|
require "big/big_decimal"
|
2021-11-06 13:15:19 +00:00
|
|
|
CRYSTAL
|
2021-01-17 15:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "reports if there are a duplicated requires" do
|
2021-11-06 13:15:19 +00:00
|
|
|
source = expect_issue subject, <<-CRYSTAL
|
2021-01-17 15:41:34 +00:00
|
|
|
require "big"
|
|
|
|
require "math"
|
|
|
|
require "big"
|
2021-10-22 17:54:39 +00:00
|
|
|
# ^{} error: Duplicated require of `big`
|
2021-11-06 13:15:19 +00:00
|
|
|
CRYSTAL
|
|
|
|
|
|
|
|
expect_no_corrections source
|
2021-01-17 15:41:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "reports rule, pos and message" do
|
|
|
|
source = Source.new %(
|
|
|
|
require "./thing"
|
|
|
|
require "./thing"
|
|
|
|
require "./another_thing"
|
|
|
|
require "./another_thing"
|
|
|
|
), "source.cr"
|
|
|
|
|
|
|
|
subject.catch(source).should_not be_valid
|
|
|
|
|
|
|
|
issue = source.issues.first
|
|
|
|
issue.rule.should_not be_nil
|
|
|
|
issue.location.to_s.should eq "source.cr:2:1"
|
|
|
|
issue.end_location.to_s.should eq ""
|
|
|
|
issue.message.should eq "Duplicated require of `./thing`"
|
|
|
|
|
|
|
|
issue = source.issues.last
|
|
|
|
issue.rule.should_not be_nil
|
|
|
|
issue.location.to_s.should eq "source.cr:4:1"
|
|
|
|
issue.end_location.to_s.should eq ""
|
|
|
|
issue.message.should eq "Duplicated require of `./another_thing`"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|