class HamlLint::Linter::RepeatedId
Detects repeated instances of an element ID in a file
Constants
- MESSAGE_FORMAT
Attributes
id_map[R]
Public Instance Methods
visit_root(_node)
click to toggle source
# File lib/haml_lint/linter/repeated_id.rb, line 9 def visit_root(_node) @id_map = Hash.new { |hash, key| hash[key] = [] } end
visit_tag(node)
click to toggle source
# File lib/haml_lint/linter/repeated_id.rb, line 13 def visit_tag(node) id = node.tag_id return unless id && !id.empty? 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
Private Instance Methods
add_lint(node, id)
click to toggle source
# File lib/haml_lint/linter/repeated_id.rb, line 29 def add_lint(node, id) record_lint(node, MESSAGE_FORMAT % id) end
add_lints_for_first_duplications(nodes)
click to toggle source
# File lib/haml_lint/linter/repeated_id.rb, line 33 def add_lints_for_first_duplications(nodes) nodes.each { |node| add_lint(node, node.tag_id) } end