Sha256: 1410da84cb9ad60062074e8b5add58b9be98e3ebb9f83ef53e56bbc78d2af7e1

Contents?: true

Size: 903 Bytes

Versions: 5

Compression:

Stored size: 903 Bytes

Contents

require 'sass'

module SCSSLint
  class Linter::DeclarationOrderLinter < Linter
    include LinterRegistry

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

    def visit_rule(node)
      children = node.children.select { |node| important_node?(node) }.
                               map { |node| node.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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
scss-lint-0.7.1 lib/scss_lint/linter/declaration_order_linter.rb
scss-lint-0.7.0 lib/scss_lint/linter/declaration_order_linter.rb
scss-lint-0.6.7 lib/scss_lint/linter/declaration_order_linter.rb
scss-lint-0.6.6 lib/scss_lint/linter/declaration_order_linter.rb
scss-lint-0.6.5 lib/scss_lint/linter/declaration_order_linter.rb