Class: SCSSLint::Linter::ColorVariable
- Inherits:
-
SCSSLint::Linter
- Object
- Sass::Tree::Visitors::Base
- SCSSLint::Linter
- SCSSLint::Linter::ColorVariable
- Includes:
- SCSSLint::LinterRegistry
- Defined in:
- lib/scss_lint/linter/color_variable.rb
Overview
Ensures color literals are used only in variable declarations.
Constant Summary
Constants included from Utils
Instance Attribute Summary
Attributes inherited from SCSSLint::Linter
Instance Method Summary collapse
Methods included from SCSSLint::LinterRegistry
extract_linters_from, included
Methods inherited from SCSSLint::Linter
Methods included from Utils
#color?, #color_hex?, #color_keyword?, #color_keyword_to_code, #extract_string_selectors, #node_ancestor, #node_siblings, #pluralize, #previous_node, #remove_quoted_strings, #same_position?
Methods included from SelectorVisitor
Constructor Details
This class inherits a constructor from SCSSLint::Linter
Instance Method Details
#visit_script_color(node) ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/scss_lint/linter/color_variable.rb', line 6 def visit_script_color(node) return if in_variable_declaration?(node) || in_map_declaration?(node) || in_rgba_function_call?(node) # Source range sometimes includes closing parenthesis, so extract it color = source_from_range(node.source_range)[/(#?[a-z0-9]+)/i, 1] record_lint(node, color) if color?(color) end |
#visit_script_string(node) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/scss_lint/linter/color_variable.rb', line 17 def visit_script_string(node) return if literal_string?(node) remove_quoted_strings(node.value) .scan(/(^|\s)(#[a-f0-9]+|[a-z]+)(?=\s|$)/i) .select { |_, word| color?(word) } .each { |_, color| record_lint(node, color) } end |