class SCSSLint::Linter::ZeroUnit

Checks for unnecessary units on zero values.

Constants

LENGTH_UNITS
MESSAGE_FORMAT
ZERO_UNIT_REGEX

Public Instance Methods

visit_script_funcall(node) { || ... } click to toggle source
# File lib/scss_lint/linter/zero_unit.rb, line 25
def visit_script_funcall(node)
  # Don't report errors for values within `calc` expressions, since they
  # require units in order to work
  yield unless node.name == 'calc'
end
visit_script_number(node) click to toggle source
# File lib/scss_lint/linter/zero_unit.rb, line 18
def visit_script_number(node)
  length = source_from_range(node.source_range)[ZERO_UNIT_REGEX, 1]
  return unless zero_with_length_units?(length)

  add_lint(node, MESSAGE_FORMAT % length)
end
visit_script_string(node) click to toggle source
# File lib/scss_lint/linter/zero_unit.rb, line 8
def visit_script_string(node)
  return unless node.type == :identifier
  return if node.value.start_with?('calc(')

  node.value.scan(ZERO_UNIT_REGEX) do |match|
    next unless zero_with_length_units?(match.first)
    add_lint(node, MESSAGE_FORMAT % match.first)
  end
end

Private Instance Methods

zero_with_length_units?(string) click to toggle source
# File lib/scss_lint/linter/zero_unit.rb, line 44
def zero_with_length_units?(string)
  string =~ /^0([a-z]+)/ && LENGTH_UNITS.include?(Regexp.last_match(1))
end