diff --git a/CHANGELOG.md b/CHANGELOG.md index 0dd5817a..f1199f3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/haml_lint/script_extractor.rb b/lib/haml_lint/script_extractor.rb index 733cbfee..dc14abdc 100644 --- a/lib/haml_lint/script_extractor.rb +++ b/lib/haml_lint/script_extractor.rb @@ -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 diff --git a/spec/haml_lint/script_extractor_spec.rb b/spec/haml_lint/script_extractor_spec.rb index f43fbcf9..7b15b939 100644 --- a/spec/haml_lint/script_extractor_spec.rb +++ b/spec/haml_lint/script_extractor_spec.rb @@ -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 @@ -20,7 +28,7 @@ %b Ipsum HAML - it { should == '' } + it { should == 'puts # Lorem' } end context 'with a silent script node' do