lib/scss_lint/linter/zero_unit.rb in scss-lint-0.9.0 vs lib/scss_lint/linter/zero_unit.rb in scss-lint-0.10.0
- old
+ new
@@ -1,14 +1,27 @@
module SCSSLint
class Linter::ZeroUnit < Linter
include LinterRegistry
def visit_prop(node)
- line = engine.lines[node.line - 1] if node.line
- add_lint(node) if line =~ /^\s*[\w-]+:\s*0[a-z]+;$/i
+ if node.value.is_a?(Sass::Script::String) &&
+ node.value.type == :identifier
+
+ node.value.value.scan(/\b(0[a-z]+)\b/i) do |match|
+ add_lint(node, MESSAGE_FORMAT % match.first)
+ end
+ end
+
+ yield # Continue visiting children
end
- def description
- 'Properties with a value of zero should be unit-less, e.g. "0" instead of "0px"'
+ def visit_script_number(node)
+ if node.value == 0 && !node.unitless?
+ add_lint(node, MESSAGE_FORMAT % node.original)
+ end
end
+
+ private
+
+ MESSAGE_FORMAT = '`%s` should be written without units as `0`'
end
end