Sha256: fcf395b21b5d93a696385d28490037f360a34a06653a935e6570fbf892e2d50b
Contents?: true
Size: 1.28 KB
Versions: 1
Compression:
Stored size: 1.28 KB
Contents
require 'sass' module SCSSLint class Linter::DeclarationOrderLinter < Linter include LinterRegistry DECLARATION_ORDER = [ Sass::Tree::ExtendNode, Sass::Tree::MixinNode, Sass::Tree::PropNode, Sass::Tree::RuleNode, ] class << self def run(engine) lints = [] #engine.tree.each do |node| #if node.is_a?(Sass::Tree::RuleNode) #lints << check_order_of_declarations(node) #end #end #lints.compact end def description 'Rule sets should start with @extend declarations, followed by ' << 'mixins, properties, and nested rule sets, in that order' end private def important_node?(node) case node when *DECLARATION_ORDER true end end def check_order_of_declarations(rule_node) children = rule_node.children.select { |node| important_node?(node) } # Horribly inefficient, but we're not sorting thousands of declarations sorted_children = children.sort do |x,y| DECLARATION_ORDER.index(x.class) <=> DECLARATION_ORDER.index(y.class) end if children != sorted_children return create_lint(children.first) end nil end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
scss-lint-0.1 | lib/scss_lint/linter/declaration_order_linter.rb |