Class: SCSSLint::Linter::NestingDepth
- Inherits:
-
SCSSLint::Linter
- Object
- Sass::Tree::Visitors::Base
- SCSSLint::Linter
- SCSSLint::Linter::NestingDepth
- Includes:
- SCSSLint::LinterRegistry
- Defined in:
- lib/scss_lint/linter/nesting_depth.rb
Overview
Checks for rule sets nested deeper than a specified maximum depth.
Constant Summary collapse
- IGNORED_SELECTORS =
[Sass::Selector::Parent, Sass::Selector::Pseudo].freeze
Constants included from Utils
Instance Attribute Summary
Attributes inherited from SCSSLint::Linter
Instance Method Summary collapse
Methods included from SCSSLint::LinterRegistry
extract_linters_from, included
Methods inherited from SCSSLint::Linter
inherited, #initialize, #name, #run
Methods included from Utils
#color?, #color_hex?, #color_keyword?, #color_keyword_to_code, #else_node?, #extract_string_selectors, #node_ancestor, #node_siblings, #pluralize, #previous_node, #remove_quoted_strings, #same_position?
Methods included from SelectorVisitor
Constructor Details
This class inherits a constructor from SCSSLint::Linter
Instance Method Details
#visit_root(_node) ⇒ Object
8 9 10 11 12 |
# File 'lib/scss_lint/linter/nesting_depth.rb', line 8 def visit_root(_node) @max_depth = config['max_depth'] @depth = 1 yield # Continue linting children end |
#visit_rule(node) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/scss_lint/linter/nesting_depth.rb', line 14 def visit_rule(node) return yield if ignore_selectors?(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 |