Class: HamlLint::Linter::RepeatedId

Inherits:
Linter
  • Object
show all
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 Method Summary collapse

Methods included from HamlLint::LinterRegistry

extract_linters_from, included

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