class SCSSLint::Linter::SpaceAfterPropertyColon
Checks for spaces following the colon that separates a property’s name from its value.
Public Instance Methods
visit_prop(node) { || ... }
click to toggle source
# File lib/scss_lint/linter/space_after_property_colon.rb, line 15 def visit_prop(node) spaces = spaces_after_colon(node) case config['style'] when 'no_space' check_for_no_spaces(node, spaces) when 'one_space' check_for_one_space(node, spaces) when 'at_least_one_space' check_for_at_least_one_space(node, spaces) end yield # Continue linting children end
visit_rule(node) { || ... }
click to toggle source
# File lib/scss_lint/linter/space_after_property_colon.rb, line 7 def visit_rule(node) if config['style'] == 'aligned' check_properties_alignment(node) end yield # Continue linting children end
Private Instance Methods
check_for_at_least_one_space(node, spaces)
click to toggle source
# File lib/scss_lint/linter/space_after_property_colon.rb, line 42 def check_for_at_least_one_space(node, spaces) return if spaces >= 1 add_lint(node, 'Colon after property should be followed by at least one space') end
check_for_no_spaces(node, spaces)
click to toggle source
# File lib/scss_lint/linter/space_after_property_colon.rb, line 32 def check_for_no_spaces(node, spaces) return if spaces == 0 add_lint(node, 'Colon after property should not be followed by any spaces') end
check_for_one_space(node, spaces)
click to toggle source
# File lib/scss_lint/linter/space_after_property_colon.rb, line 37 def check_for_one_space(node, spaces) return if spaces == 1 add_lint(node, 'Colon after property should be followed by one space') end
check_properties_alignment(rule_node)
click to toggle source
# File lib/scss_lint/linter/space_after_property_colon.rb, line 47 def check_properties_alignment(rule_node) properties = rule_node.children.select { |node| node.is_a?(Sass::Tree::PropNode) } properties.each_slice(2) do |prop1, prop2| next unless prop2 next unless value_offset(prop1) != value_offset(prop2) add_lint(prop1, 'Property values should be aligned') break end end
spaces_after_colon(node)
click to toggle source
# File lib/scss_lint/linter/space_after_property_colon.rb, line 66 def spaces_after_colon(node) spaces = 0 offset = 1 # Find the colon after the property name while character_at(node.name_source_range.start_pos, offset - 1) != ':' offset += 1 end # Count spaces after the colon while character_at(node.name_source_range.start_pos, offset) == ' ' spaces += 1 offset += 1 end spaces end
value_offset(prop)
click to toggle source
Offset of value for property
# File lib/scss_lint/linter/space_after_property_colon.rb, line 59 def value_offset(prop) src_range = prop.name_source_range src_range.start_pos.offset + (src_range.end_pos.offset - src_range.start_pos.offset) + spaces_after_colon(prop) end