Class: HamlLint::Linter::ClassesBeforeIds
- Inherits:
-
HamlLint::Linter
- Object
- HamlLint::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 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
autocorrect_priority, autocorrect_safe?, #initialize, #name, ruby_parser, #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_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 |