Class: ThemeCheck::MatchingTranslations

Inherits:
JsonCheck show all
Defined in:
lib/theme_check/checks/matching_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 inherited from JsonCheck

#add_offense

Methods included from ChecksTracking

#inherited

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

#initializeMatchingTranslations

Returns a new instance of MatchingTranslations.



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

def initialize
  @files = []
end

Instance Method Details

#on_endObject



21
22
23
24
25
26
27
28
# File 'lib/theme_check/checks/matching_translations.rb', line 21

def on_end
  return unless @theme.default_locale_json&.content

  @files.each do |file|
    diff = LocaleDiff.new(@theme.default_locale_json.content, file.content)
    diff.add_as_offenses(self, template: file)
  end
end

#on_file(file) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/theme_check/checks/matching_translations.rb', line 13

def on_file(file)
  return unless file.name.start_with?("locales/")
  return unless file.content.is_a?(Hash)
  return if file.name == @theme.default_locale_json&.name

  @files << file
end