gems.scss_lint-0.57.0.lib.scss_lint.linter.zero_unit.rb Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sass-maven-plugin Show documentation
Show all versions of sass-maven-plugin Show documentation
A Maven Plugin that compiles Sass files.
# frozen_string_literal: true
module SCSSLint
# Checks for unnecessary units on zero values.
class Linter::ZeroUnit < Linter
include LinterRegistry
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
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
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
private
ZERO_UNIT_REGEX = /
\b
(?
© 2015 - 2025 Weber Informatics LLC | Privacy Policy