Sha256: 775b29ce2cd3324775b04b52df7773ffe6d880ae900f33c8adf829736258042a

Contents?: true

Size: 1.21 KB

Versions: 40

Compression:

Stored size: 1.21 KB

Contents

module SCSSLint
  # Checks that the number of properties in a rule set is under a defined limit.
  class Linter::PropertyCount < Linter
    include LinterRegistry

    def visit_root(_node)
      @property_count = {} # Lookup table of counts for rule sets
      @max = config['max_properties']
      yield # Continue linting children
    end

    def visit_rule(node)
      count = property_count(node)

      if count > @max
        add_lint node,
                 "Rule set contains (#{count}/#{@max}) properties" \
                 "#{' (including properties in nested rule sets)' if config['include_nested']}"

        # Don't lint nested rule sets as we already have them in the count
        return if config['include_nested']
      end

      yield # Lint nested rule sets
    end

  private

    def property_count(rule_node)
      @property_count[rule_node] ||=
        begin
          count = rule_node.children.count { |node| node.is_a?(Sass::Tree::PropNode) }

          if config['include_nested']
            count += rule_node.children.inject(0) do |sum, node|
              node.is_a?(Sass::Tree::RuleNode) ? sum + property_count(node) : sum
            end
          end

          count
        end
    end
  end
end

Version data entries

40 entries across 40 versions & 3 rubygems

Version Path
scss_lint-0.60.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.59.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.58.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.57.1 lib/scss_lint/linter/property_count.rb
scss_lint-0.57.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.56.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.55.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.54.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.53.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.52.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.51.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.50.3 lib/scss_lint/linter/property_count.rb
scss_lint-0.50.2 lib/scss_lint/linter/property_count.rb
scss_lint-0.50.1 lib/scss_lint/linter/property_count.rb
scss_lint-0.50.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.49.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.48.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.47.1 lib/scss_lint/linter/property_count.rb
scss_lint-0.47.0 lib/scss_lint/linter/property_count.rb
scss_lint-0.46.0 lib/scss_lint/linter/property_count.rb