Class: ThemeCheck::ContentForHeaderModification

Inherits:
LiquidCheck show all
Defined in:
lib/theme_check/checks/content_for_header_modification.rb

Constant Summary

Constants inherited from Check

ThemeCheck::Check::CATEGORIES, ThemeCheck::Check::SEVERITIES, ThemeCheck::Check::SEVERITY_VALUES

Instance Attribute Summary

Attributes inherited from Check

#ignored_patterns, #offenses, #options, #theme

Instance Method Summary collapse

Methods included from ChecksTracking

#inherited

Methods included from ParsingHelpers

#outside_of_strings

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

#format_json_parse_error

Constructor Details

#initializeContentForHeaderModification

Returns a new instance of ContentForHeaderModification.



8
9
10
11
# File 'lib/theme_check/checks/content_for_header_modification.rb', line 8

def initialize
  @in_assign = false
  @in_capture = false
end

Instance Method Details

#after_assign(_node) ⇒ Object



29
30
31
# File 'lib/theme_check/checks/content_for_header_modification.rb', line 29

def after_assign(_node)
  @in_assign = false
end

#after_capture(_node) ⇒ Object



37
38
39
# File 'lib/theme_check/checks/content_for_header_modification.rb', line 37

def after_capture(_node)
  @in_capture = false
end

#on_assign(_node) ⇒ Object



25
26
27
# File 'lib/theme_check/checks/content_for_header_modification.rb', line 25

def on_assign(_node)
  @in_assign = true
end

#on_capture(_node) ⇒ Object



33
34
35
# File 'lib/theme_check/checks/content_for_header_modification.rb', line 33

def on_capture(_node)
  @in_capture = true
end

#on_variable(node) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/theme_check/checks/content_for_header_modification.rb', line 13

def on_variable(node)
  return unless node.value.name.is_a?(Liquid::VariableLookup)
  return unless node.value.name.name == "content_for_header"

  if @in_assign || @in_capture || node.value.filters.any?
    add_offense(
      "Do not rely on the content of `content_for_header`",
      node: node,
    )
  end
end