Sha256: 1e038e7931225991093764f094b87c985bf22e3441c16a3c9e901bd6c395733a

Contents?: true

Size: 778 Bytes

Versions: 1

Compression:

Stored size: 778 Bytes

Contents

module SCSSLint
  class Linter::HexFormat < Linter
    include LinterRegistry

    def visit_script_color(node)
      return unless node.original && node.original.match(HEX_REGEX)

      unless valid_hex_format?(node.original[HEX_REGEX, 1])
        add_hex_lint(node, node.original)
      end
    end

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

      node.value.scan(HEX_REGEX) do |match|
        add_hex_lint(node, match.first) unless valid_hex_format?(match.first)
      end
    end

  private

    HEX_REGEX = /(#\h{3,6})/

    def add_hex_lint(node, hex)
      add_lint(node, "Color `#{hex}` should be written as `#{shortest_hex_form(hex)}`")
    end

    def valid_hex_format?(hex)
      hex == shortest_hex_form(hex)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.10.1 lib/scss_lint/linter/hex_format.rb