Sha256: a611feda453b0a00278b53016d899dc3fee87eda166e0770e2f354e7dd673ced

Contents?: true

Size: 1.26 KB

Versions: 15

Compression:

Stored size: 1.26 KB

Contents

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

    def visit_rule(node)
      check_properties(node)
    end

    def visit_mixindef(node)
      check_properties(node)
    end

  private

    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

    def check_properties(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 = property_value(prop)

        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

15 entries across 15 versions & 1 rubygems

Version Path
scss-lint-0.30.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.29.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.28.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.27.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.26.2 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.26.1 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.26.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.25.1 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.25.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.24.1 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.24.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.23.1 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.23.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.22.0 lib/scss_lint/linter/duplicate_property.rb
scss-lint-0.21.0 lib/scss_lint/linter/duplicate_property.rb