Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Commit

Permalink
Fix TranslationKeyExists.on_end issue (#587)
Browse files Browse the repository at this point in the history
We had a bug if the key path existed but "ended" early.

Fixes #571
  • Loading branch information
charlespwd authored Jun 6, 2022
1 parent 3c56597 commit d760624
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/theme_check/checks/translation_key_exists.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def on_end

def key_exists?(key, pointer)
key.split(".").each do |token|
return false unless pointer.is_a?(Hash)
return false unless pointer.key?(token)
pointer = pointer[token]
end
Expand Down
18 changes: 18 additions & 0 deletions test/checks/translation_key_exists_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,22 @@ def test_creates_nested_missing_keys

assert_equal(expected, actual)
end

def test_handles_key_conflicts
theme = make_theme(
"locales/en.default.json" => JSON.dump({
product: { quantity: "TODO" },
}),
"templates/index.liquid" => <<~END,
{{"product.quantity.decrease" | t}}
END
)

analyzer = ThemeCheck::Analyzer.new(theme, [ThemeCheck::TranslationKeyExists.new], true)
analyzer.analyze_theme

assert_offenses(<<~END, analyzer.offenses)
'product.quantity.decrease' does not have a matching entry in 'locales/en.default.json' at templates/index.liquid:1
END
end
end

0 comments on commit d760624

Please sign in to comment.