Skip to content

Commit

Permalink
Fix UnnecessaryStringOutput handling of nested content
Browse files Browse the repository at this point in the history
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 <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
  • Loading branch information
sds committed Sep 14, 2014
1 parent 59575bc commit 84b3681
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/haml_lint/linter/unnecessary_string_output.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/haml_lint/linter/unnecessary_string_output_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 84b3681

Please sign in to comment.