class SCSSLint::Linter::SpaceAfterVariableColon

Checks for spaces following the colon that separates a variable's name from its value.

Public Instance Methods

visit_variable(node) click to toggle source
# File lib/scss_lint/linter/space_after_variable_colon.rb, line 7
def visit_variable(node)
  whitespace = whitespace_after_colon(node)

  case config['style']
  when 'no_space'
    check_for_no_spaces(node, whitespace)
  when 'one_space'
    check_for_one_space(node, whitespace)
  when 'at_least_one_space'
    check_for_at_least_one_space(node, whitespace)
  when 'one_space_or_newline'
    check_for_one_space_or_newline(node, whitespace)
  end
end

Private Instance Methods

check_for_at_least_one_space(node, whitespace) click to toggle source
# File lib/scss_lint/linter/space_after_variable_colon.rb, line 34
def check_for_at_least_one_space(node, whitespace)
  return if whitespace.uniq == [' ']
  add_lint(node, 'Colon after variable should be followed by at least one space')
end
check_for_no_spaces(node, whitespace) click to toggle source
# File lib/scss_lint/linter/space_after_variable_colon.rb, line 24
def check_for_no_spaces(node, whitespace)
  return if whitespace == []
  add_lint(node, 'Colon after variable should not be followed by any spaces')
end
check_for_one_space(node, whitespace) click to toggle source
# File lib/scss_lint/linter/space_after_variable_colon.rb, line 29
def check_for_one_space(node, whitespace)
  return if whitespace == [' ']
  add_lint(node, 'Colon after variable should be followed by one space')
end
check_for_one_space_or_newline(node, whitespace) click to toggle source
# File lib/scss_lint/linter/space_after_variable_colon.rb, line 39
def check_for_one_space_or_newline(node, whitespace)
  return if whitespace == [' '] || whitespace == ["\n"]
  return if whitespace[0] == "\n" && whitespace[1..-1].uniq == [' ']
  add_lint(node, 'Colon after variable should be followed by one space or a newline')
end
whitespace_after_colon(node) click to toggle source
# File lib/scss_lint/linter/space_after_variable_colon.rb, line 45
def whitespace_after_colon(node)
  whitespace = []
  offset = 0
  start_pos = node.source_range.start_pos

  # Find the colon after the variable name
  offset = offset_to(start_pos, ':', offset) + 1

  # Count spaces after the colon
  while [' ', "\t", "\n"].include? character_at(start_pos, offset)
    whitespace << character_at(start_pos, offset)
    offset += 1
  end

  whitespace
end