class SCSSLint::Linter::HexNotation

Checks if hexadecimal colors are written lowercase / uppercase.

Constants

HEX_REGEX

Public Instance Methods

visit_script_color(node) click to toggle source
# File lib/scss_lint/linter/hex_notation.rb, line 8
def visit_script_color(node)
  return unless hex = source_from_range(node.source_range)[HEX_REGEX, 1]
  check_hex(hex, node)
end
visit_script_string(node) click to toggle source
# File lib/scss_lint/linter/hex_notation.rb, line 13
def visit_script_string(node)
  return unless node.type == :identifier

  node.value.scan(HEX_REGEX) do |match|
    check_hex(match.first, node)
  end
end

Private Instance Methods

check_hex(hex, node) click to toggle source
# File lib/scss_lint/linter/hex_notation.rb, line 23
def check_hex(hex, node)
  return if expected(hex) == hex

  add_lint(node, "Color `#{hex}` should be written as `#{expected(hex)}`")
end
expected(color) click to toggle source
# File lib/scss_lint/linter/hex_notation.rb, line 29
def expected(color)
  return color.downcase if lowercase_style?
  color.upcase
end
lowercase_style?() click to toggle source
# File lib/scss_lint/linter/hex_notation.rb, line 34
def lowercase_style?
  config['style'] == 'lowercase'
end