Class: ThemeCheck::UnusedAssign
- Inherits:
-
LiquidCheck
- Object
- Check
- LiquidCheck
- ThemeCheck::UnusedAssign
- Defined in:
- lib/theme_check/checks/unused_assign.rb
Overview
Checks unused assign x = … %
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 ⇒ UnusedAssign
constructor
A new instance of UnusedAssign.
- #on_assign(node) ⇒ Object
- #on_document(node) ⇒ Object
- #on_end ⇒ Object
- #on_include(node) ⇒ Object
- #on_variable_lookup(node) ⇒ Object
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 ⇒ UnusedAssign
Returns a new instance of UnusedAssign.
23 24 25 |
# File 'lib/theme_check/checks/unused_assign.rb', line 23 def initialize @templates = {} end |
Instance Method Details
#on_assign(node) ⇒ Object
31 32 33 |
# File 'lib/theme_check/checks/unused_assign.rb', line 31 def on_assign(node) @templates[node.template.name].assign_nodes[node.value.to] = node end |
#on_document(node) ⇒ Object
27 28 29 |
# File 'lib/theme_check/checks/unused_assign.rb', line 27 def on_document(node) @templates[node.template.name] = TemplateInfo.new(Set.new, {}, Set.new) end |
#on_end ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/theme_check/checks/unused_assign.rb', line 45 def on_end @templates.each_pair do |_, info| used = info.collect_used_assigns(@templates) info.assign_nodes.each_pair do |name, node| unless used.include?(name) add_offense("`#{name}` is never used", node: node) end end end end |
#on_include(node) ⇒ Object
35 36 37 38 39 |
# File 'lib/theme_check/checks/unused_assign.rb', line 35 def on_include(node) if node.value.template_name_expr.is_a?(String) @templates[node.template.name].includes << "snippets/#{node.value.template_name_expr}" end end |
#on_variable_lookup(node) ⇒ Object
41 42 43 |
# File 'lib/theme_check/checks/unused_assign.rb', line 41 def on_variable_lookup(node) @templates[node.template.name].used_assigns << node.value.name end |