class HamlLint::Linter::ClassesBeforeIds
Checks that classes are listed before IDs in tags.
Constants
- MSG
- TYPES_BY_PREFIX
Map of prefixes to the type of tag component
Public Instance Methods
visit_tag(node)
click to toggle source
# File lib/haml_lint/linter/classes_before_ids.rb, line 16 def visit_tag(node) # Convert ".class#id" into [.class, #id] (preserving order) components = node.static_attributes_source.scan(/[.#][^.#]+/) first, second = attribute_prefix_order components.each_cons(2) do |current_val, next_val| next unless next_val.start_with?(first) && current_val.start_with?(second) failure_message = format(MSG, *(attribute_type_order + [next_val, current_val])) record_lint(node, failure_message) break end end
Private Instance Methods
attribute_prefix_order()
click to toggle source
# File lib/haml_lint/linter/classes_before_ids.rb, line 34 def attribute_prefix_order default = %w[. #] default.reverse! if ids_first? default end
attribute_type_order()
click to toggle source
# File lib/haml_lint/linter/classes_before_ids.rb, line 40 def attribute_type_order default = %w[Classes IDs] default.reverse! if ids_first? default end
enforced_style()
click to toggle source
# File lib/haml_lint/linter/classes_before_ids.rb, line 46 def enforced_style config.fetch('EnforcedStyle', 'class') end
ids_first?()
click to toggle source
# File lib/haml_lint/linter/classes_before_ids.rb, line 50 def ids_first? enforced_style == 'id' end