Sha256: f3dc3f13e5a229bbb8ed131b64b7b6b07d7e4cd050ac045c017469e99bb8fccb

Contents?: true

Size: 911 Bytes

Versions: 1

Compression:

Stored size: 911 Bytes

Contents

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(&: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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.29.0 lib/scss_lint/linter/declaration_order.rb