Skip to content

Commit 1276344

Browse files
committed
Merge get_keys_from_strings into find_duplicated_keys
See suggestion at #342 (comment) I liked each method doing a different thing, but this keeps things more compact 🤷‍♂️ Besides, we can easily split if we need the isolated functionality in the future. YANGI.
1 parent 29c89f4 commit 1276344

File tree

1 file changed

+6
-18
lines changed

1 file changed

+6
-18
lines changed

lib/fastlane/plugin/wpmreleasetoolkit/helper/ios/ios_strings_file_validation_helper.rb

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,13 @@ class StringsFileValidationHelper
6060
}
6161
}.freeze
6262

63-
# Returns all the keys in the given `.strings` file, and the line(s) at
64-
# which they are defined.
63+
# Inspects the given `.strings` file for duplicated keys, returning them
64+
# if any.
6565
#
6666
# @param [String] file The path to the file to inspect.
67-
# @return [<Hash>] A `Hash` with keys the key values read from the
68-
# `.strings` file. The value of each entry is an array with the
69-
# line numbers where the key occurs.
70-
def self.get_keys_from_strings(file:)
67+
# @return [Hash<String, Array<Int>] Hash with the dublipcated keys.
68+
# Each element has the duplicated key (from the `.strings`) as key and an array of line numbers where the key occurs as value.
69+
def self.find_duplicated_keys(file:)
7170
keys_with_lines = Hash.new([])
7271

7372
state = State.new(context: :root, buffer: StringIO.new, in_escaped_ctx: false, found_key: nil)
@@ -105,18 +104,7 @@ def self.get_keys_from_strings(file:)
105104
end
106105
end
107106

108-
keys_with_lines
109-
end
110-
111-
# Inspects the given `.strings` file for duplicated keys, returning them
112-
# if any.
113-
#
114-
# @param [String] file The path to the file to inspect.
115-
# @return [Array<Hash>] Array of all the duplicated keys. Each entry is a
116-
# a `Hash` with keys: `key` for the key value and `lines` with an
117-
# array of line numbers at which the key occurs.
118-
def self.find_duplicated_keys(file:)
119-
get_keys_from_strings(file: file).keep_if { |_, lines| lines.count > 1 }
107+
keys_with_lines.keep_if { |_, lines| lines.count > 1 }
120108
end
121109
end
122110
end

0 commit comments

Comments
 (0)