Class: SCSSLint::Linter::PropertySortOrder
- Inherits:
-
SCSSLint::Linter
- Object
- Sass::Tree::Visitors::Base
- SCSSLint::Linter
- SCSSLint::Linter::PropertySortOrder
- Includes:
- SCSSLint::LinterRegistry
- Defined in:
- lib/scss_lint/linter/property_sort_order.rb
Overview
Checks the declaration order of properties.
Instance Attribute Summary
Attributes inherited from SCSSLint::Linter
Instance Method Summary collapse
Methods included from SCSSLint::LinterRegistry
extract_linters_from, included
Methods inherited from SCSSLint::Linter
#add_lint, #character_at, #initialize, #run, #source_from_range, #visit, #visit_children
Methods included from Utils
#can_be_condensed?, #extract_string_selectors, #pluralize, #previous_node, #remove_quoted_strings, #shortest_hex_form
Methods included from SelectorVisitor
Constructor Details
This class inherits a constructor from SCSSLint::Linter
Instance Method Details
#description ⇒ Object
32 33 34 35 |
# File 'lib/scss_lint/linter/property_sort_order.rb', line 32 def description 'Properties should be sorted in order, with ' << 'vendor-prefixed extensions before the standardized CSS property' end |
#visit_rule(node) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/scss_lint/linter/property_sort_order.rb', line 6 def visit_rule(node) # Ignore properties that contain interpolation sortable_props = node.children.select do |child| child.is_a?(Sass::Tree::PropNode) && child.name.all? { |part| part.is_a?(String) } end sortable_prop_names = sortable_props.map { |child| child.name.join } sorted_prop_names = sortable_prop_names.map do |name| /^(?<vendor>-\w+(-osx)?-)?(?<property>.+)/ =~ name { name: name, vendor: vendor, property: property } end.sort { |a, b| compare_properties(a, b) } .map { |fields| fields[:name] } sorted_prop_names.each_with_index do |name, index| # Report the first property out of order with the sorted list if name != sortable_prop_names[index] add_lint(sortable_props[index]) break end end yield # Continue linting children end |