module SCSSLint
  # Checks the order of nested items within a rule set.
  class Linter::DeclarationOrder < Linter
    include LinterRegistry

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

    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)
      end

      yield # Continue linting children
    end

    def description
      'Rule sets should start with @extend declarations, followed by ' <<
      'properties and nested rule sets, in that order'
    end

  private

    def important_node?(node)
      DECLARATION_ORDER.include? node.class
    end
  end
end

module SCSSLint
  # Checks the order of nested items within a rule set.
  class Linter::DeclarationOrder < Linter
    include LinterRegistry

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

    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

  private

    MESSAGE =
      'Rule sets should start with @extend declarations, followed by ' <<
      'properties and nested rule sets, in that order'

    def important_node?(node)
      DECLARATION_ORDER.include? node.class
    end
  end
end

Remove description method from DeclarationOrder
Remove description method from DeclarationOrder

The `description` method is being deprecated.

Change-Id: I27efec67970d21e98a1fe3e8db95d6ff4c23090a
Reviewed-on: http://gerrit.causes.com/36726
Tested-by: jenkins <d95b56ce41a2e1ac4cecdd398defd7414407cc08@causes.com>
Reviewed-by: Shane da Silva <6f6e68d1df92f30cb4b3ce35260ddf94a402f33d@causes.com>
