Skip to content

Commit

Permalink
Fix ConsecutiveSilentScripts with control statements
Browse files Browse the repository at this point in the history
If a user had multiple control statements with nested HAML, a lint would
incorrectly be reported.

Fix by making the detector ignore scripts with nested HAML.

Change-Id: I29015a07eba94a880b19e6a6f293ff8d284eacd3
Reviewed-on: http://gerrit.causes.com/43372
Tested-by: jenkins <jenkins@causes.com>
Reviewed-by: Shane da Silva <shane.dasilva@brigade.com>
  • Loading branch information
sds committed Oct 7, 2014
1 parent 09462b5 commit 1a6d9dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# HAML-Lint Changelog

## master (unreleased)

* Fix bug in `ConsecutiveSilentScripts` where control statements with nested
HAML would incorrectly be reported as silent scripts

## 0.7.0

* New lint `UnnecessaryInterpolation` checks for interpolation in inline
Expand Down
6 changes: 4 additions & 2 deletions lib/haml_lint/linter/consecutive_silent_scripts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ module HamlLint
class Linter::ConsecutiveSilentScripts < Linter
include LinterRegistry

SCRIPT_DETECTOR = ->(child) { child.type == :silent_script }
SILENT_SCRIPT_DETECTOR = ->(child) do
child.type == :silent_script && child.children.empty?
end

def visit_root(node)
HamlLint::Utils.find_consecutive(
node.children,
config['max_consecutive'] + 1,
SCRIPT_DETECTOR,
SILENT_SCRIPT_DETECTOR,
) do |group|
add_lint(group.first,
"#{group.count} consecutive Ruby scripts can be merged into " \
Expand Down
16 changes: 16 additions & 0 deletions spec/haml_lint/linter/consecutive_silent_scripts_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@
it { should report_lint line: 1 }
it { should_not report_lint line: 2 }
it { should_not report_lint line: 3 }

context 'and they contain nested content that results in output' do
let(:haml) { <<-HAML }
- if expression
= some_output
%br
- if expression2
= some_output2
%br
- if expression3
= some_output3
%br
HAML

it { should_not report_lint }
end
end
end

Expand Down

0 comments on commit 1a6d9dc

Please sign in to comment.