From 84b368112d51709657e4617efdbbbba7fcf65365 Mon Sep 17 00:00:00 2001 From: Shane da Silva Date: Sat, 13 Sep 2014 21:21:12 -0700 Subject: [PATCH] Fix UnnecessaryStringOutput handling of nested content The linter would incorrectly report lints for tags with nested content containing interpolation, e.g. %tag Some #{interpolated} text This is because the HAML parser treats the nested content as a script node, even though it's not explicitly set as a script. For now, include a special case in the linter. If more situations like this come up, we'll add a special case to the `NodeTransformer` class. Change-Id: I4000489c56d6e9b2f655a3c04154b43315bb64a2 Reviewed-on: http://gerrit.causes.com/42565 Tested-by: jenkins Reviewed-by: Shane da Silva --- lib/haml_lint/linter/unnecessary_string_output.rb | 4 ++++ spec/haml_lint/linter/unnecessary_string_output_spec.rb | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/haml_lint/linter/unnecessary_string_output.rb b/lib/haml_lint/linter/unnecessary_string_output.rb index b9c7fddc..72896251 100644 --- a/lib/haml_lint/linter/unnecessary_string_output.rb +++ b/lib/haml_lint/linter/unnecessary_string_output.rb @@ -18,6 +18,10 @@ def visit_tag(node) end def visit_script(node) + # Some script nodes created by the HAML parser aren't actually script + # nodes declared via the `=` marker. Check for it. + return if node.first_line_source !~ /\s*=/ + if outputs_string_literal?(node) add_lint(node, MESSAGE) end diff --git a/spec/haml_lint/linter/unnecessary_string_output_spec.rb b/spec/haml_lint/linter/unnecessary_string_output_spec.rb index fa24c830..c4ccbe88 100644 --- a/spec/haml_lint/linter/unnecessary_string_output_spec.rb +++ b/spec/haml_lint/linter/unnecessary_string_output_spec.rb @@ -44,4 +44,13 @@ let(:haml) { "= 'hello world'" } it { should report_lint } end + + context 'when tag contains nested text with interpolation' do + let(:haml) { <<-'HAML' } + %tag + Some #{interpolated} text + HAML + + it { should_not report_lint } + end end