Sha256: 04e9b734332b93dd4a5a48e6aa9ec52a59ec86fc3b17f026e1c0278ebcaca89c

Contents?: true

Size: 918 Bytes

Versions: 11

Compression:

Stored size: 918 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 { |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

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
scss-lint-0.28.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.27.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.26.2 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.26.1 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.26.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.25.1 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.25.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.24.1 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.24.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.23.1 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.23.0 lib/scss_lint/linter/declaration_order.rb