diff --git a/lib/i18n/tasks/data/tree/node.rb b/lib/i18n/tasks/data/tree/node.rb index 2c26c6f6..5cf86d2a 100644 --- a/lib/i18n/tasks/data/tree/node.rb +++ b/lib/i18n/tasks/data/tree/node.rb @@ -10,14 +10,17 @@ class Node # rubocop:disable Metrics/ClassLength attr_accessor :value attr_reader :key, :children, :parent - def initialize(key:, value: nil, data: nil, parent: nil, children: nil) + # rubocop:disable Metrics/ParameterLists + def initialize(key:, value: nil, data: nil, parent: nil, children: nil, warn_about_add_children_to_leaf: true) @key = key @key = @key.to_s.freeze if @key @value = value @data = data @parent = parent + @warn_about_add_children_to_leaf = warn_about_add_children_to_leaf self.children = (children if children) end + # rubocop:enable Metrics/ParameterLists def attributes { key: @key, value: @value, data: @data.try(:clone), parent: @parent, children: @children } @@ -34,7 +37,11 @@ def children=(children) when NilClass nil else - Siblings.new(nodes: children, parent: self) + Siblings.new( + nodes: children, + parent: self, + warn_about_add_children_to_leaf: @warn_about_add_children_to_leaf + ) end dirty! end diff --git a/lib/i18n/tasks/data/tree/siblings.rb b/lib/i18n/tasks/data/tree/siblings.rb index 2b376837..e5e31e95 100644 --- a/lib/i18n/tasks/data/tree/siblings.rb +++ b/lib/i18n/tasks/data/tree/siblings.rb @@ -105,7 +105,12 @@ def set(full_key, node) if rest unless child - child = Node.new(key: key_part, parent: parent, children: []) + child = Node.new( + key: key_part, + parent: parent, + children: [], + warn_about_add_children_to_leaf: @warn_add_children_to_leaf + ) append! child end unless child.children diff --git a/spec/used_keys_spec.rb b/spec/used_keys_spec.rb index e5eb82e0..07439d7d 100644 --- a/spec/used_keys_spec.rb +++ b/spec/used_keys_spec.rb @@ -9,8 +9,8 @@ div = t 'a' p = t 'a' h1 = t 'b' -h2 = t 'c' -h3 = t 'c.underneath_c' +h2 = t 'c.layer' +h3 = t 'c.layer.underneath_c' SLIM end