Class: SCSSLint::Linter::NestingDepth

Inherits:
SCSSLint::Linter
  • Object
show all
Includes:
SCSSLint::LinterRegistry
Defined in:
lib/scss_lint/linter/nesting_depth.rb

Overview

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

Instance Attribute Summary

Attributes inherited from SCSSLint::Linter

#config, #engine, #lints

Instance Method Summary collapse

Methods included from SCSSLint::LinterRegistry

extract_linters_from, included

Methods inherited from SCSSLint::Linter

#initialize, #name, #run

Methods included from Utils

#extract_string_selectors, #node_siblings, #pluralize, #previous_node, #remove_quoted_strings, #same_position?

Methods included from SelectorVisitor

#visit_selector

Constructor Details

This class inherits a constructor from SCSSLint::Linter

Instance Method Details

#visit_root(_node) ⇒ Object


6
7
8
9
10
# 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) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
# 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