Class: HamlLint::Linter::RepeatedId
- Inherits:
-
HamlLint::Linter
- Object
- HamlLint::Linter
- HamlLint::Linter::RepeatedId
- Includes:
- HamlLint::LinterRegistry
- Defined in:
- lib/haml_lint/linter/repeated_id.rb
Overview
Detects repeated instances of an element ID in a file
Constant Summary collapse
- MESSAGE_FORMAT =
%{Do not repeat id "#%s" on the page}
Instance Attribute Summary
Attributes inherited from HamlLint::Linter
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
Constructor Details
This class inherits a constructor from HamlLint::Linter
Instance Method Details
#visit_root(_node) ⇒ Object
10 11 12 |
# File 'lib/haml_lint/linter/repeated_id.rb', line 10 def visit_root(_node) @id_map = {} end |
#visit_tag(node) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/haml_lint/linter/repeated_id.rb', line 14 def visit_tag(node) id = node.tag_id return unless id && !id.empty? id_map[id] ||= [] nodes = (id_map[id] << node) case nodes.size when 1 then nil when 2 then add_lints_for_first_duplications(nodes) else add_lint(node, id) end end |