Class: ThemeCheck::NestedSnippet
- Inherits:
-
LiquidCheck
- Object
- Check
- LiquidCheck
- ThemeCheck::NestedSnippet
- Defined in:
- lib/theme_check/checks/nested_snippet.rb
Overview
Reports deeply nested include … % or render … %
Defined Under Namespace
Classes: TemplateInfo
Constant Summary
Constants inherited from Check
Check::CATEGORIES, Check::SEVERITIES, Check::SEVERITY_VALUES
Instance Attribute Summary
Attributes inherited from Check
#ignored_patterns, #offenses, #options, #theme
Instance Method Summary collapse
-
#initialize(max_nesting_level: 3) ⇒ NestedSnippet
constructor
A new instance of NestedSnippet.
- #on_document(node) ⇒ Object
- #on_end ⇒ Object
- #on_include(node) ⇒ Object (also: #on_render)
Methods included from ChecksTracking
Methods included from ParsingHelpers
Methods inherited from Check
#==, #add_offense, all, can_disable, #can_disable?, categories, #categories, category, #code_name, doc, #doc, docs_url, #ignore!, #ignored?, #severity, severity, #severity=, #severity_value, severity_value, single_file, #single_file?, #to_s, #whole_theme?
Methods included from JsonHelpers
Constructor Details
#initialize(max_nesting_level: 3) ⇒ NestedSnippet
Returns a new instance of NestedSnippet.
23 24 25 26 |
# File 'lib/theme_check/checks/nested_snippet.rb', line 23 def initialize(max_nesting_level: 3) @max_nesting_level = max_nesting_level @templates = {} end |
Instance Method Details
#on_document(node) ⇒ Object
28 29 30 |
# File 'lib/theme_check/checks/nested_snippet.rb', line 28 def on_document(node) @templates[node.template.name] = TemplateInfo.new(Set.new) end |
#on_end ⇒ Object
39 40 41 42 43 44 45 |
# File 'lib/theme_check/checks/nested_snippet.rb', line 39 def on_end @templates.each_pair do |_, info| info.with_deep_nested(@templates, @max_nesting_level) do |node| add_offense("Too many nested snippets", node: node) end end end |
#on_include(node) ⇒ Object Also known as: on_render
32 33 34 35 36 |
# File 'lib/theme_check/checks/nested_snippet.rb', line 32 def on_include(node) if node.value.template_name_expr.is_a?(String) @templates[node.template.name].includes << node end end |