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, Check::SEVERITY_VALUES
Instance Attribute Summary
Attributes inherited from Check
#ignored_patterns, #offenses, #options, #theme
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 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 ⇒ UnusedSnippet
Returns a new instance of UnusedSnippet.
10 11 12 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 10 def initialize @used_templates = Set.new end |
Instance Method Details
#missing_snippets ⇒ Object
31 32 33 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 31 def missing_snippets theme.snippets.reject { |t| @used_templates.include?(t.name) } end |
#on_end ⇒ Object
25 26 27 28 29 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 25 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
14 15 16 17 18 19 20 21 22 |
# File 'lib/theme_check/checks/unused_snippet.rb', line 14 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 |