class SCSSLint::Linter::DuplicateProperty

Checks for a property declared twice in a rule set.

Public Instance Methods

check_properties(node) { || ... } click to toggle source
# File lib/scss_lint/linter/duplicate_property.rb, line 6
def check_properties(node)
  static_properties(node).each_with_object({}) do |prop, prop_names|
    prop_key = property_key(prop)

    if existing_prop = prop_names[prop_key]
      add_lint(prop, "Property `#{existing_prop.name.join}` already "\
                     "defined on line #{existing_prop.line}")
    else
      prop_names[prop_key] = prop
    end
  end

  yield # Continue linting children
end
Also aliased as: visit_rule, visit_mixindef
visit_mixindef(node)
Alias for: check_properties
visit_rule(node)
Alias for: check_properties

Private Instance Methods

property_key(prop) click to toggle source

Returns a key identifying the bucket this property and value correspond to for purposes of uniqueness.

# File lib/scss_lint/linter/duplicate_property.rb, line 34
def property_key(prop)
  prop_key = prop.name.join
  prop_value = property_value(prop)

  # Differentiate between values for different vendor prefixes
  prop_value.to_s.scan(/^(-[^-]+-.+)/) do |vendor_keyword|
    prop_key << vendor_keyword.first
  end

  prop_key
end
property_value(prop) click to toggle source
# File lib/scss_lint/linter/duplicate_property.rb, line 46
def property_value(prop)
  case prop.value
  when Sass::Script::Funcall
    prop.value.name
  when Sass::Script::String
  when Sass::Script::Tree::Literal
    prop.value.value
  else
    prop.value.to_s
  end
end
static_properties(node) click to toggle source
# File lib/scss_lint/linter/duplicate_property.rb, line 26
def static_properties(node)
  node.children
      .select { |child| child.is_a?(Sass::Tree::PropNode) }
      .reject { |prop| prop.name.any? { |item| item.is_a?(Sass::Script::Node) } }
end