mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Apply review sugggestions
This commit is contained in:
parent
d7795c0d7d
commit
2cedd72b09
2 changed files with 39 additions and 26 deletions
|
@ -4,63 +4,70 @@ module Ameba
|
||||||
describe Source do
|
describe Source do
|
||||||
describe ".new" do
|
describe ".new" do
|
||||||
it "allows to create a source by code and path" do
|
it "allows to create a source by code and path" do
|
||||||
s = Source.new("code", "path")
|
source = Source.new "code", "path"
|
||||||
s.path.should eq "path"
|
source.path.should eq "path"
|
||||||
s.code.should eq "code"
|
source.code.should eq "code"
|
||||||
s.lines.should eq ["code"]
|
source.lines.should eq ["code"]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#fullpath" do
|
describe "#fullpath" do
|
||||||
it "returns a relative path of the source" do
|
it "returns a relative path of the source" do
|
||||||
s = Source.new "", "./source_spec.cr"
|
source = Source.new "", "./source_spec.cr"
|
||||||
s.fullpath.should contain "source_spec.cr"
|
source.fullpath.should contain "source_spec.cr"
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns fullpath if path is blank" do
|
it "returns fullpath if path is blank" do
|
||||||
s = Source.new "", ""
|
source = Source.new "", ""
|
||||||
s.fullpath.should_not be_nil
|
source.fullpath.should_not be_nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#spec?" do
|
describe "#spec?" do
|
||||||
it "returns true if the source is a spec file" do
|
it "returns true if the source is a spec file" do
|
||||||
s = Source.new "", "./source_spec.cr"
|
source = Source.new "", "./source_spec.cr"
|
||||||
s.spec?.should be_true
|
source.spec?.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if the source is not a spec file" do
|
it "returns false if the source is not a spec file" do
|
||||||
s = Source.new "", "./source.cr"
|
source = Source.new "", "./source.cr"
|
||||||
s.spec?.should be_false
|
source.spec?.should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#matches_path?" do
|
describe "#matches_path?" do
|
||||||
it "returns true if source's path is matched" do
|
it "returns true if source's path is matched" do
|
||||||
s = Source.new "", "source.cr"
|
source = Source.new "", "source.cr"
|
||||||
s.matches_path?("source.cr").should be_true
|
source.matches_path?("source.cr").should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns false if source's path is not matched" do
|
it "returns false if source's path is not matched" do
|
||||||
s = Source.new "", "source.cr"
|
source = Source.new "", "source.cr"
|
||||||
s.matches_path?("new_source.cr").should be_false
|
source.matches_path?("new_source.cr").should be_false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "#pos" do
|
describe "#pos" do
|
||||||
it "works" do
|
it "works" do
|
||||||
s = Source.new <<-EOS
|
source = Source.new <<-CRYSTAL
|
||||||
foo
|
foo
|
||||||
bar
|
bar
|
||||||
fizz
|
fizz
|
||||||
buzz
|
buzz
|
||||||
EOS
|
CRYSTAL
|
||||||
loc = Crystal::Location.new("", 2, 1)
|
|
||||||
end_loc = Crystal::Location.new("", 3, 4)
|
location = Crystal::Location.new("", 2, 1)
|
||||||
s.code[s.pos(loc)...s.pos(end_loc, end: true)].should eq <<-EOS
|
end_location = Crystal::Location.new("", 3, 4)
|
||||||
|
|
||||||
|
range = Range.new(
|
||||||
|
source.pos(location),
|
||||||
|
source.pos(end_location, end: true),
|
||||||
|
exclusive: true
|
||||||
|
)
|
||||||
|
source.code[range].should eq <<-CRYSTAL
|
||||||
bar
|
bar
|
||||||
fizz
|
fizz
|
||||||
EOS
|
CRYSTAL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -51,10 +51,16 @@ module Ameba::Rule::Style
|
||||||
|
|
||||||
def test(source, node : Crystal::Unless)
|
def test(source, node : Crystal::Unless)
|
||||||
return if node.else.nop?
|
return if node.else.nop?
|
||||||
return unless location = node.location
|
|
||||||
return unless cond_end_location = node.cond.end_location
|
location = node.location
|
||||||
return unless else_location = node.else_location
|
cond_end_location = node.cond.end_location
|
||||||
return unless end_location = node.end_location
|
else_location = node.else_location
|
||||||
|
end_location = node.end_location
|
||||||
|
|
||||||
|
unless location && cond_end_location && else_location && end_location
|
||||||
|
issue_for node, MSG
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
issue_for node, MSG do |corrector|
|
issue_for node, MSG do |corrector|
|
||||||
keyword_begin_pos = source.pos(location)
|
keyword_begin_pos = source.pos(location)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue