Class: ThemeCheck::DeprecatedGlobalAppBlockType

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

Constant Summary collapse

INVALID_GLOBAL_APP_BLOCK_TYPE =
"@global"
VALID_GLOBAL_APP_BLOCK_TYPE =
"@app"

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

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

Instance Method Details

#on_case(node) ⇒ Object



24
25
26
27
28
# File 'lib/theme_check/checks/deprecated_global_app_block_type.rb', line 24

def on_case(node)
  if node.value == INVALID_GLOBAL_APP_BLOCK_TYPE
    report_offense(node)
  end
end

#on_condition(node) ⇒ Object



30
31
32
33
34
# File 'lib/theme_check/checks/deprecated_global_app_block_type.rb', line 30

def on_condition(node)
  if node.value.right == INVALID_GLOBAL_APP_BLOCK_TYPE || node.value.left == INVALID_GLOBAL_APP_BLOCK_TYPE
    report_offense(node)
  end
end

#on_schema(node) ⇒ Object



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

def on_schema(node)
  schema = JSON.parse(node.value.nodelist.join)

  if block_types_from(schema).include?(INVALID_GLOBAL_APP_BLOCK_TYPE)
    add_offense(
      "Deprecated '#{INVALID_GLOBAL_APP_BLOCK_TYPE}' block type defined in the schema, use '#{VALID_GLOBAL_APP_BLOCK_TYPE}' block type instead.",
      node: node
    )
  end
rescue JSON::ParserError
  # Ignored, handled in ValidSchema.
end

#on_variable(node) ⇒ Object



36
37
38
39
40
# File 'lib/theme_check/checks/deprecated_global_app_block_type.rb', line 36

def on_variable(node)
  if node.value.name == INVALID_GLOBAL_APP_BLOCK_TYPE
    report_offense(node)
  end
end