Sha256: b3682b10b6932596d80daf23fdf9503a844d24337353ac5b0e7854a767028586

Contents?: true

Size: 924 Bytes

Versions: 14

Compression:

Stored size: 924 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)
      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

14 entries across 14 versions & 1 rubygems

Version Path
scss-lint-0.20.3 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.20.2 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.20.1 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.20.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.19.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.18.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.17.3 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.17.2 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.17.1 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.17.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.16.1 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.16.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.15.0 lib/scss_lint/linter/declaration_order.rb
scss-lint-0.14.0 lib/scss_lint/linter/declaration_order.rb