Class: HamlLint::Linter::ConsecutiveSilentScripts
- Inherits:
-
Linter
- Object
- Linter
- HamlLint::Linter::ConsecutiveSilentScripts
- Includes:
- HamlLint::LinterRegistry
- Defined in:
- lib/haml_lint/linter/consecutive_silent_scripts.rb
Overview
Checks for multiple consecutive silent script markers that could be condensed into a :ruby filter block.
Constant Summary collapse
- SILENT_SCRIPT_DETECTOR =
->(child) do child.type == :silent_script && child.children.empty? end
Instance Method Summary collapse
Methods included from HamlLint::LinterRegistry
extract_linters_from, included
Instance Method Details
#after_visit_root(_node) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/haml_lint/linter/consecutive_silent_scripts.rb', line 32 def after_visit_root(_node) super return if merges.empty? apply_autocorrect(merged_source) end |
#visit_silent_script(node) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/haml_lint/linter/consecutive_silent_scripts.rb', line 16 def visit_silent_script(node) return if previously_reported?(node) HamlLint::Utils.for_consecutive_items( possible_group(node), SILENT_SCRIPT_DETECTOR, config['max_consecutive'] + 1, ) do |group| reported_nodes.concat(group) record_lint(group.first, "#{group.count} consecutive Ruby scripts can be merged " \ 'into a single `:ruby` filter', corrected: collect_merge(group)) end end |