class SCSSLint::Linter::BemDepth
Checks for BEM selectors with more elements than a specified maximum number.
Public Instance Methods
visit_class(klass)
click to toggle source
# File lib/scss_lint/linter/bem_depth.rb, line 11 def visit_class(klass) check_depth(klass, 'selectors') end
visit_placeholder(placeholder)
click to toggle source
# File lib/scss_lint/linter/bem_depth.rb, line 15 def visit_placeholder(placeholder) check_depth(placeholder, 'placeholders') end
visit_root(_node) { || ... }
click to toggle source
# File lib/scss_lint/linter/bem_depth.rb, line 6 def visit_root(_node) @max_elements = config['max_elements'] yield # Continue linting children end
Private Instance Methods
check_depth(node, plural_type)
click to toggle source
# File lib/scss_lint/linter/bem_depth.rb, line 21 def check_depth(node, plural_type) selector = node.name parts = selector.split('__') num_elements = (parts[1..-1] || []).length return if num_elements <= @max_elements found_elements = pluralize(@max_elements, 'element') add_lint(node, "BEM #{plural_type} should have no more than #{found_elements}, " \ "but `#{selector}` has #{num_elements}") end