Class: SCSSLint::Linter::DeclarationOrder

Inherits:
SCSSLint::Linter
  • Object
show all
Includes:
SCSSLint::LinterRegistry
Defined in:
lib/scss_lint/linter/declaration_order.rb

Overview

Checks the order of nested items within a rule set.

Constant Summary collapse

DECLARATION_ORDER =
[
  Sass::Tree::ExtendNode,
  Sass::Tree::PropNode,
  Sass::Tree::RuleNode,
]

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

#add_lint, #character_at, #initialize, #node_on_single_line, #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

#visit_selector

Constructor Details

This class inherits a constructor from SCSSLint::Linter

Instance Method Details

#visit_rule(node) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/scss_lint/linter/declaration_order.rb', line 12

def visit_rule(node)
  children = node.children.select { |n| important_node?(n) }
                          .map { |n| n.class }

  sorted_children = children.sort do |a, b|
    DECLARATION_ORDER.index(a) <=> DECLARATION_ORDER.index(b)
  end

  if children != sorted_children
    add_lint(node.children.first, MESSAGE)
  end

  yield # Continue linting children
end