Sha256: dc759274bd41cac8f88fd091639593d76647d83a878cc2281fa332f29c01cd01

Contents?: true

Size: 542 Bytes

Versions: 23

Compression:

Stored size: 542 Bytes

Contents

module SCSSLint
  # Checks for invalid hexadecimal colors.
  class Linter::HexValidation < Linter
    include LinterRegistry

    def visit_script_string(node)
      return unless node.type == :identifier

      node.value.scan(/(?:\W|^)(#\h+)(?:\W|$)/) do |match|
        check_hex(match.first, node)
      end
    end

  private

    HEX_REGEX = /(#(\h{3}|\h{6}|\h{8}))(?!\h)/

    def check_hex(hex, node)
      return if HEX_REGEX.match(hex)
      add_lint(node, "Colors must have either three or six digits: `#{hex}`")
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
scss_lint-0.43.1 lib/scss_lint/linter/hex_validation.rb
scss_lint-0.43.0 lib/scss_lint/linter/hex_validation.rb
scss_lint-0.42.2 lib/scss_lint/linter/hex_validation.rb