Class: HamlLint::Linter::ClassesBeforeIds
- Inherits:
-
Linter
- Object
- Linter
- HamlLint::Linter::ClassesBeforeIds
- Includes:
- HamlLint::LinterRegistry
- Defined in:
- lib/haml_lint/linter/classes_before_ids.rb
Overview
Checks that classes are listed before IDs in tags.
Constant Summary collapse
- MSG =
'%s should be listed before %s (%s should precede %s)'
Instance Method Summary collapse
Methods included from HamlLint::LinterRegistry
extract_linters_from, included
Instance Method Details
#visit_tag(node) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/haml_lint/linter/classes_before_ids.rb', line 12 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) corrected = correct_attribute_order(node, components) = format(MSG, *(attribute_type_order + [next_val, current_val])) record_lint(node, , corrected: corrected) break end end |