Sha256: bc679182a916829cd22ca552c618c6007726879a94cda46cdf77e44af9780b44
Contents?: true
Size: 1.07 KB
Versions: 3
Compression:
Stored size: 1.07 KB
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) add_color_lint(node, node.original_string) if color_keyword?(node.original_string) end def visit_script_string(node) return unless node.type == :identifier remove_quoted_strings(node.value).scan(/[a-z]+/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_rgb(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 `#{shortest_hex_form(hex_form)}`") end def color_keyword?(string) !!color_rgb(string) && string != 'transparent' end def color_rgb(string) Sass::Script::Value::Color::COLOR_NAMES[string] end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
scss-lint-0.13.0 | lib/scss_lint/linter/color_keyword.rb |
scss-lint-0.12.1 | lib/scss_lint/linter/color_keyword.rb |
scss-lint-0.12.0 | lib/scss_lint/linter/color_keyword.rb |