Class: SCSSLint::Linter::ColorKeyword

Inherits:
SCSSLint::Linter
  • Object
show all
Includes:
SCSSLint::LinterRegistry
Defined in:
lib/scss_lint/linter/color_keyword.rb

Overview

Checks for uses of a color keyword instead of the preferred hexadecimal form.

Constant Summary collapse

COLOR_REGEX =
/(#?[a-f0-9]{3,6}|[a-z]+)/i

Instance Attribute Summary

Attributes inherited from SCSSLint::Linter

#config, #engine, #lints

Instance Method Summary collapse

Methods included from SCSSLint::LinterRegistry

extract_linters_from, included

Methods inherited from SCSSLint::Linter

#initialize, #name, #run

Methods included from Utils

#extract_string_selectors, #node_siblings, #pluralize, #previous_node, #remove_quoted_strings, #same_position?

Methods included from SelectorVisitor

#visit_selector

Constructor Details

This class inherits a constructor from SCSSLint::Linter

Instance Method Details

#visit_script_color(node) ⇒ Object


9
10
11
12
# File 'lib/scss_lint/linter/color_keyword.rb', line 9

def visit_script_color(node)
  color = source_from_range(node.source_range)[COLOR_REGEX, 1]
  add_color_lint(node, color) if color_keyword?(color)
end

#visit_script_string(node) ⇒ Object


14
15
16
17
18
19
20
# File 'lib/scss_lint/linter/color_keyword.rb', line 14

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