class SCSSLint::Linter::NestingDepth

Checks for rule sets nested deeper than a specified maximum depth.

Public Instance Methods

visit_root(_node) { || ... } click to toggle source
# File lib/scss_lint/linter/nesting_depth.rb, line 6
def visit_root(_node)
  @max_depth = config['max_depth']
  @depth = 1
  yield # Continue linting children
end
visit_rule(node) { || ... } click to toggle source
# File lib/scss_lint/linter/nesting_depth.rb, line 12
def visit_rule(node)
  if @depth > @max_depth
    add_lint(node, "Nesting should be no greater than #{@max_depth}, but was #{@depth}")
  else
    # Only continue if we didn't exceed the max depth already (this makes
    # the lint less noisy)
    @depth += 1
    yield # Continue linting children
    @depth -= 1
  end
end