mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Lint/LiteralInInterpolation: properly report node position
This commit is contained in:
parent
441e7fa2bb
commit
04497feeed
2 changed files with 15 additions and 6 deletions
|
@ -29,13 +29,22 @@ module Ameba::Rule::Lint
|
||||||
end
|
end
|
||||||
|
|
||||||
it "reports rule, pos and message" do
|
it "reports rule, pos and message" do
|
||||||
s = Source.new %q("#{4}"), "source.cr"
|
s = Source.new %q(
|
||||||
|
"Hello, #{:world} from #{:ameba}"
|
||||||
|
), "source.cr"
|
||||||
subject.catch(s).should_not be_valid
|
subject.catch(s).should_not be_valid
|
||||||
|
s.issues.size.should eq 2
|
||||||
|
|
||||||
issue = s.issues.first
|
issue = s.issues.first
|
||||||
issue.rule.should_not be_nil
|
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:6"
|
issue.end_location.to_s.should eq "source.cr:1:16"
|
||||||
|
issue.message.should eq "Literal value found in interpolation"
|
||||||
|
|
||||||
|
issue = s.issues.last
|
||||||
|
issue.rule.should_not be_nil
|
||||||
|
issue.location.to_s.should eq "source.cr:1:26"
|
||||||
|
issue.end_location.to_s.should eq "source.cr:1:31"
|
||||||
issue.message.should eq "Literal value found in interpolation"
|
issue.message.should eq "Literal value found in interpolation"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,9 +26,9 @@ module Ameba::Rule::Lint
|
||||||
MSG = "Literal value found in interpolation"
|
MSG = "Literal value found in interpolation"
|
||||||
|
|
||||||
def test(source, node : Crystal::StringInterpolation)
|
def test(source, node : Crystal::StringInterpolation)
|
||||||
found = node.expressions.any? { |e| !e.is_a?(Crystal::StringLiteral) && literal?(e) }
|
node.expressions
|
||||||
return unless found
|
.select { |e| !e.is_a?(Crystal::StringLiteral) && literal?(e) }
|
||||||
issue_for node, MSG
|
.each { |n| issue_for n, MSG }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue