Class: HamlLint::Linter::ConsecutiveSilentScripts

Inherits:
HamlLint::Linter show all
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 Attribute Summary

Attributes inherited from HamlLint::Linter

#lints

Instance Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

Methods inherited from HamlLint::Linter

#initialize, #name, #run, #run_or_raise, supports_autocorrect?, #supports_autocorrect?

Methods included from HamlVisitor

#visit, #visit_children

Constructor Details

This class inherits a constructor from HamlLint::Linter

Instance Method Details

#visit_silent_script(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/haml_lint/linter/consecutive_silent_scripts.rb', line 13

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|
    record_lint(group.first,
                "#{group.count} consecutive Ruby scripts can be merged " \
                'into a single `:ruby` filter')
  end
end