Sha256: 655db95872f140658b034be096e26b0ac4571599738141cd4c97c3158153e3b6

Contents?: true

Size: 688 Bytes

Versions: 3

Compression:

Stored size: 688 Bytes

Contents

require 'sass'

module SCSSLint
  class Linter::HexLinter < Linter
    include LinterRegistry

    def visit_prop(node)
      if node.value.is_a?(Sass::Script::String) &&
         node.value.to_s =~ /#(\h{3,6})/
        add_lint(node) unless valid_hex?($1)
      end
    end

    def description
      'Hexadecimal color codes should be lowercase and in 3-digit form where possible'
    end

  private

    def valid_hex?(hex)
      [3,6].include?(hex.length) &&
        hex.downcase == hex &&
        !can_be_condensed(hex)
    end

    def can_be_condensed(hex)
      hex.length == 6 &&
        hex[0] == hex[1] &&
        hex[2] == hex[3] &&
        hex[4] == hex[5]
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
scss-lint-0.6.7 lib/scss_lint/linter/hex_linter.rb
scss-lint-0.6.6 lib/scss_lint/linter/hex_linter.rb
scss-lint-0.6.5 lib/scss_lint/linter/hex_linter.rb