Class: SCSSLint::Linter::PropertyUnits

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

Overview

Check for allowed units

Constant Summary

Constants included from Utils

Utils::COLOR_REGEX

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

#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

#visit_selector

Constructor Details

This class inherits a constructor from SCSSLint::Linter

Instance Method Details

#visit_prop(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/scss_lint/linter/property_units.rb', line 13

def visit_prop(node)
  property = node.name.join

  # Handle nested properties by ensuring the full name is extracted
  if @nested_under
    property = "#{@nested_under}-#{property}"
  end

  if node.value.respond_to?(:value) &&
     units = node.value.value.to_s[/(?:^|\s)(?:\d+|\d*\.?\d+)([a-z%]+)/i, 1]
    check_units(node, property, units)
  end

  @nested_under = property
  yield # Continue linting nested properties
  @nested_under = nil
end

#visit_root(_node) ⇒ Object



6
7
8
9
10
11
# File 'lib/scss_lint/linter/property_units.rb', line 6

def visit_root(_node)
  @globally_allowed_units = config['global'].to_set
  @allowed_units_for_property = config['properties']

  yield # Continue linting children
end