Skip to content

Commit

Permalink
Output dummy puts statements for plain text nodes
Browse files Browse the repository at this point in the history
We were getting false positives about ternary statements from the
`RuboCop` lint for code like the following:

    - if something
      Some plain text
    - else
      Some other plain text

This was because the code being generated ignored plain text nodes, so
it would produce:

    if something
    else
    end

...causing the lint to be reported.

The solution was to output dummy `puts` statements for plain text nodes.

Change-Id: I86f110b32ee3503482c937a6ae673251545aab15
Reviewed-on: http://gerrit.causes.com/45070
Tested-by: jenkins <jenkins@brigade.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
  • Loading branch information
sds committed Dec 5, 2014
1 parent e088c1c commit 2d7ac52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
report lints.
* Fix bug where any `haml` version 4.0.6 or later would not remove the special
end-of-document marker from parse trees
* Fix bug where RuboCop's `Style/OneLineConditional` lint would incorrectly be
reported for HAML code with `if`/`else` statements

## 0.8.0

Expand Down
6 changes: 6 additions & 0 deletions lib/haml_lint/script_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ def visit_root(_node)
yield # Collect lines of code from children
end

def visit_plain(node)
# Comment out the actual text as we don't want to deal with RuboCop
# StringQuotes lints
add_line("puts # #{node.text}", node)
end

def visit_tag(node)
additional_attributes = node.dynamic_attributes_sources

Expand Down
10 changes: 9 additions & 1 deletion spec/haml_lint/script_extractor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
it { should == '' }
end

context 'with plain text' do
let(:haml) { <<-HAML }
Hello world
HAML

it { should == 'puts # Hello world' }
end

context 'with only tags with text content' do
let(:haml) { <<-HAML }
%h1 Hello World
Expand All @@ -20,7 +28,7 @@
%b Ipsum
HAML

it { should == '' }
it { should == 'puts # Lorem' }
end

context 'with a silent script node' do
Expand Down

0 comments on commit 2d7ac52

Please sign in to comment.