lib/scss_lint/linter/shorthand_linter.rb in scss-lint-0.6.7 vs lib/scss_lint/linter/shorthand_linter.rb in scss-lint-0.7.0

- old
+ new

@@ -3,16 +3,22 @@ module SCSSLint class Linter::ShorthandLinter < Linter include LinterRegistry def visit_prop(node) - unless SHORTHANDABLE_PROPERTIES.include? node.name.first.to_s - return - end + return unless SHORTHANDABLE_PROPERTIES.include? node.name.first.to_s - if node.value.to_sass.strip =~ /\A(\S+\s+\S+(\s+\S+){0,2})\Z/ - add_lint(node) unless valid_shorthand?($1) + case node.value + when Sass::Script::List + items = node.value.children + if (2..4).member?(items.count) + add_lint(node) unless valid_shorthand?(*items.map(&:to_sass)) + end + when Sass::Script::String + if node.value.to_sass.strip =~ /\A(\S+\s+\S+(\s+\S+){0,2})\Z/ + add_lint(node) unless valid_shorthand?(*$1.split(/\s+/)) + end end end def description 'Property values should use the shortest shorthand syntax allowed' @@ -25,13 +31,10 @@ border-style border-width margin padding] - def valid_shorthand?(shorthand) - values = shorthand.split(/\s+/) - top, right, bottom, left = values - + def valid_shorthand?(top, right, bottom = nil, left = nil) if top == right && right == bottom && bottom == left false elsif top == right && bottom.nil? && left.nil? false elsif top == bottom && right == left