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
|
||||
|
||||
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
|
||||
s.issues.size.should eq 2
|
||||
|
||||
issue = s.issues.first
|
||||
issue.rule.should_not be_nil
|
||||
issue.location.to_s.should eq "source.cr:1:1"
|
||||
issue.end_location.to_s.should eq "source.cr:1:6"
|
||||
issue.location.to_s.should eq "source.cr:1:11"
|
||||
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"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,9 +26,9 @@ module Ameba::Rule::Lint
|
|||
MSG = "Literal value found in interpolation"
|
||||
|
||||
def test(source, node : Crystal::StringInterpolation)
|
||||
found = node.expressions.any? { |e| !e.is_a?(Crystal::StringLiteral) && literal?(e) }
|
||||
return unless found
|
||||
issue_for node, MSG
|
||||
node.expressions
|
||||
.select { |e| !e.is_a?(Crystal::StringLiteral) && literal?(e) }
|
||||
.each { |n| issue_for n, MSG }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue