Class: ThemeCheck::MatchingSchemaTranslations
- Inherits:
-
LiquidCheck
- Object
- Check
- LiquidCheck
- ThemeCheck::MatchingSchemaTranslations
- Defined in:
- lib/theme_check/checks/matching_schema_translations.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
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
Instance Method Details
#on_schema(node) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/theme_check/checks/matching_schema_translations.rb', line 8 def on_schema(node) schema = JSON.parse(node.value.nodelist.join) # Get all locales used in the schema used_locales = Set.new([theme.default_locale]) visit_object(schema) do |_, locales| used_locales += locales end used_locales = used_locales.to_a # Check all used locales are defined in each localized keys visit_object(schema) do |key, locales| missing = used_locales - locales if missing.any? add_offense("#{key} missing translations for #{missing.join(', ')}", node: node) end end check_locales(schema["locales"], node: node) rescue JSON::ParserError # Ignored, handled in ValidSchema. end |