Sha256: 508c0bda8edaeae0c3e6fd41ea7ad9163b22f2411a6863b08415db04cafdd945

Contents?: true

Size: 753 Bytes

Versions: 1

Compression:

Stored size: 753 Bytes

Contents

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

      node.value.scan(ZERO_UNIT_REGEX) do |match|
        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]

      if node.value == 0 && zero_with_units?(length)
        add_lint(node, MESSAGE_FORMAT % length)
      end
    end

  private

    ZERO_UNIT_REGEX = /\b(0[a-z]+)\b/i

    MESSAGE_FORMAT = '`%s` should be written without units as `0`'

    def zero_with_units?(string)
      string =~ /^0[a-z]+/
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.22.0 lib/scss_lint/linter/zero_unit.rb