Class: ThemeCheck::UnusedSnippet
- Inherits:
-
LiquidCheck
- Object
- Check
- LiquidCheck
- ThemeCheck::UnusedSnippet
- Defined in:
- lib/theme_check/checks/unused_snippet.rb
Constant Summary
Constants inherited from Check
Check::CATEGORIES, Check::SEVERITIES
Instance Attribute Summary
Attributes inherited from Check
Instance Method Summary collapse
-
#initialize ⇒ UnusedSnippet
constructor
A new instance of UnusedSnippet.
- #missing_snippets ⇒ Object
- #on_end ⇒ Object
- #on_include(node) ⇒ Object (also: #on_render)
Methods inherited from LiquidCheck
Methods included from ChecksTracking
Methods included from ParsingHelpers
Methods inherited from Check
all, category, #category, #code_name, doc, #doc, #ignore!, #ignored?, severity, #severity, #to_s, #unignore!
Methods included from JsonHelpers
Constructor Details
#initialize ⇒ UnusedSnippet
Returns a new instance of UnusedSnippet.
9 10 11 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 9 def initialize @used_templates = Set.new end |
Instance Method Details
#missing_snippets ⇒ Object
30 31 32 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 30 def missing_snippets theme.snippets.reject { |t| @used_templates.include?(t.name) } end |
#on_end ⇒ Object
24 25 26 27 28 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 24 def on_end missing_snippets.each do |template| add_offense("This template is not used", template: template) end end |
#on_include(node) ⇒ Object Also known as: on_render
13 14 15 16 17 18 19 20 21 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 13 def on_include(node) if node.value.template_name_expr.is_a?(String) @used_templates << "snippets/#{node.value.template_name_expr}" else # Can't reliably track unused snippets if an expression is used, ignore this check @used_templates.clear ignore! end end |