Sha256: 24a356b55cfc81b5755648037a8f33e7df20753ea4990dd87cbe25374289367d

Contents?: true

Size: 853 Bytes

Versions: 1

Compression:

Stored size: 853 Bytes

Contents

module SCSSLint
  # Checks for identical root selectors.
  class Linter::DuplicateRoot < Linter
    include LinterRegistry

    def visit_root(node)
      # Root rules are evaluated per document, so use new hashes for eash file
      @roots = {}
      yield # Continue linting children
    end

    def visit_rule(node)
      if @roots[node.rule]
        add_lint node.line,
                 "Merge root rule `#{node.rule.join}` with identical " \
                 "rule on line #{@roots[node.rule].line}"
      else
        @roots[node.rule] = node
      end

      # Don't yield so we only check one level deep
    end

    # Define stubs so we don't check rules nested in other constructs
    %w[
      directive
      media
      mixin
      mixindef
    ].each do |node_type|
      define_method("visit_#{node_type}") { |*args| }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
scss-lint-0.23.1 lib/scss_lint/linter/duplicate_root.rb