Class: ThemeCheck::TranslationKeyExists

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

Constant Summary

Constants inherited from Check

Check::CATEGORIES, Check::SEVERITIES

Instance Attribute Summary

Attributes inherited from Check

#offenses, #options, #theme

Instance Method Summary collapse

Methods inherited from LiquidCheck

#add_offense

Methods included from ChecksTracking

#inherited

Methods included from ParsingHelpers

#outside_of_strings

Methods inherited from Check

all, can_disable, #can_disable?, category, #category, #code_name, doc, #doc, #ignore!, #ignored?, #severity, severity, #to_s, #unignore!

Methods included from JsonHelpers

#format_json_parse_error

Instance Method Details

#on_variable(node) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/theme_check/checks/translation_key_exists.rb', line 7

def on_variable(node)
  return unless @theme.default_locale_json&.content&.is_a?(Hash)

  return unless node.value.filters.any? { |name, _| name == "t" || name == "translate" }
  return unless (key_node = node.children.first)
  return unless key_node.value.is_a?(String)

  unless key_exists?(key_node.value)
    add_offense(
      "'#{key_node.value}' does not have a matching entry in '#{@theme.default_locale_json.relative_path}'",
      node: node,
      markup: key_node.value,
    )
  end
end