Sha256: 6792b90dca5166eb3a57887d6e4f28b53316e8ac0338f5d2a1162d9433dd0e6b
Contents?: true
Size: 959 Bytes
Versions: 8
Compression:
Stored size: 959 Bytes
Contents
module SCSSLint # Checks for uses of a color keyword instead of the preferred hexadecimal # form. class Linter::ColorKeyword < Linter include LinterRegistry def visit_script_color(node) word = source_from_range(node.source_range)[/([a-z]+)/i, 1] add_color_lint(node, word) if color_keyword?(word) end def visit_script_string(node) return unless node.type == :identifier remove_quoted_strings(node.value).scan(/(^|\s)([a-z]+)(?=\s|$)/i) do |_, word| add_color_lint(node, word) if color_keyword?(word) end end private def add_color_lint(node, original) hex_form = Sass::Script::Value::Color.new(color_keyword_to_code(original)).tap do |color| color.options = {} # `inspect` requires options to be set end.inspect add_lint(node, "Color `#{original}` should be written in hexadecimal form " \ "as `#{hex_form}`") end end end
Version data entries
8 entries across 8 versions & 3 rubygems