Sha256: 4d1e9af2981a7c3340c64cb43ddd6aa9ea93201b514f6bc1d4c6adaa44ae5dbf

Contents?: true

Size: 1.05 KB

Versions: 6

Compression:

Stored size: 1.05 KB

Contents

module SCSSLint
  # Checks for a property declared twice in a rule set.
  class Linter::DuplicateProperty < Linter
    include LinterRegistry

    def visit_rule(node)
      properties = node.children
                       .select { |child| child.is_a?(Sass::Tree::PropNode) }
                       .reject { |prop| prop.name.any? { |item| item.is_a?(Sass::Script::Node) } }

      prop_names = {}

      properties.each do |prop|
        name = prop.name.join

        prop_hash = name
        prop_value =
          case prop.value
          when Sass::Script::Funcall
            prop.value.name
          when Sass::Script::String
            prop.value.value
          else
            prop.value.to_s
          end

        prop_value.to_s.scan(/^(-[^-]+-.+)/) do |vendor_keyword|
          prop_hash << vendor_keyword.first
        end

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scss-lint-0.17.2 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.17.1 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.17.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.16.1 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.16.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.15.0 lib/scss_lint/linter/duplicate_property.rb