Class: SCSSLint::Linter::PropertySortOrder

Inherits:
SCSSLint::Linter
  • Object
show all
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

#config, #engine, #lints

Instance Method Summary collapse

Methods included from SCSSLint::LinterRegistry

extract_linters_from, included

Methods inherited from SCSSLint::Linter

#initialize, #name, #run

Methods included from Utils

#extract_string_selectors, #node_siblings, #pluralize, #previous_node, #remove_quoted_strings, #same_position?

Methods included from SelectorVisitor

#visit_selector

Constructor Details

This class inherits a constructor from SCSSLint::Linter

Instance Method Details

#check_sort_order(node) ⇒ Object Also known as: visit_media, visit_mixin, visit_rule


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/scss_lint/linter/property_sort_order.rb', line 11

def check_sort_order(node)
  sortable_props = node.children.select do |child|
    child.is_a?(Sass::Tree::PropNode) && !ignore_property?(child)
  end

  sortable_prop_info = sortable_props
    .map { |child| child.name.join }
    .map do |name|
      /^(?<vendor>-\w+(-osx)?-)?(?<property>.+)/ =~ name
      { name: name, vendor: vendor, property: property }
    end

  sorted_props = sortable_prop_info
    .sort { |a, b| compare_properties(a, b) }

  sorted_props.each_with_index do |prop, index|
    next unless prop != sortable_prop_info[index]

    add_lint(sortable_props[index], lint_message(sorted_props))
    break
  end

  yield # Continue linting children
end

#visit_if(node, &block) ⇒ Object


40
41
42
43
# File 'lib/scss_lint/linter/property_sort_order.rb', line 40

def visit_if(node, &block)
  check_sort_order(node, &block)
  visit(node.else) if node.else
end

#visit_root(_node) ⇒ Object


6
7
8
9
# File 'lib/scss_lint/linter/property_sort_order.rb', line 6

def visit_root(_node)
  @preferred_order = extract_preferred_order_from_config
  yield
end