diff --git a/spec/ameba/rule/lint/literal_in_interpolation_spec.cr b/spec/ameba/rule/lint/literal_in_interpolation_spec.cr index 0b6bf8cbb..218d94d78 100644 --- a/spec/ameba/rule/lint/literal_in_interpolation_spec.cr +++ b/spec/ameba/rule/lint/literal_in_interpolation_spec.cr @@ -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 diff --git a/src/ameba/rule/lint/literal_in_interpolation.cr b/src/ameba/rule/lint/literal_in_interpolation.cr index 5155a02dd..df674f74f 100644 --- a/src/ameba/rule/lint/literal_in_interpolation.cr +++ b/src/ameba/rule/lint/literal_in_interpolation.cr @@ -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