Class: PlatformosCheck::TranslationKeyExists
- Inherits:
-
LiquidCheck
- Object
- Check
- LiquidCheck
- PlatformosCheck::TranslationKeyExists
- Defined in:
- lib/platformos_check/checks/translation_key_exists.rb
Overview
Recommends using liquid … % if 5 or more consecutive … % are found.
Constant Summary
Constants inherited from Check
Check::CATEGORIES, Check::SEVERITIES, Check::SEVERITY_VALUES
Instance Attribute Summary
Attributes inherited from Check
#ignored_patterns, #offenses, #options, #platformos_app
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_platformos_app?
Methods included from JsonHelpers
#format_json_parse_error, #pretty_json
Instance Method Details
#on_variable(node) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/platformos_check/checks/translation_key_exists.rb', line 10 def on_variable(node) return unless node.value.name.is_a?(String) return unless node.filters.size == 1 translation_filter = node.filters.detect { |f| TranslationFile::TRANSLATION_FILTERS.include?(f[0]) } return unless translation_filter return unless translation_filter filter_attributes = translation_filter[2] || {} return unless filter_attributes['default'].nil? return if !filter_attributes['scope'].nil? && !filter_attributes['scope'].is_a?(String) lang = filter_attributes['language'].is_a?(String) ? filter_attributes['language'] : @platformos_app.default_language translation_components = node.value.name.split('.') translation_components = filter_attributes['scope'].split('.') + translation_components if filter_attributes['scope'] return add_translation_offense(node:, lang:) if @platformos_app.translations_hash.empty? hash = @platformos_app.translations_hash[lang] || {} index = 0 while translation_components[index] hash = hash[translation_components[index]] if hash.nil? add_translation_offense(node:, lang:) break end index += 1 end end |