Skip to content

Commit 209c3c7

Browse files
Fix Style/Next violations
1 parent 87c4566 commit 209c3c7

File tree

4 files changed

+49
-61
lines changed

4 files changed

+49
-61
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,6 @@ Style/MutableConstant:
197197
- 'lib/fastlane/plugin/wpmreleasetoolkit/version.rb'
198198
- 'spec/release_notes_helper_spec.rb'
199199

200-
# Offense count: 7
201-
# This cop supports safe autocorrection (--autocorrect).
202-
# Configuration parameters: EnforcedStyle, MinBodyLength.
203-
# SupportedStyles: skip_modifier_ifs, always
204-
Style/Next:
205-
Exclude:
206-
- 'lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb'
207-
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb'
208-
- 'lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_download_helper.rb'
209-
210200
# Offense count: 23
211201
# This cop supports unsafe autocorrection (--autocorrect-all).
212202
# Configuration parameters: EnforcedStyle, AllowedMethods, AllowedPatterns.

lib/fastlane/plugin/wpmreleasetoolkit/actions/common/gp_downloadmetadata_action.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ def self.run(params)
2525
downloader.download(loc[1], complete_url, loc[1] == params[:source_locale])
2626
end
2727

28-
if loc.is_a?(String)
29-
UI.message "Downloading language: #{loc}"
30-
complete_url = "#{params[:project_url]}#{loc}/default/export-translations/?filters[status]=current&format=json"
31-
downloader.download(loc, complete_url, loc == params[:source_locale])
32-
end
28+
next unless loc.is_a?(String)
29+
30+
UI.message "Downloading language: #{loc}"
31+
complete_url = "#{params[:project_url]}#{loc}/default/export-translations/?filters[status]=current&format=json"
32+
downloader.download(loc, complete_url, loc == params[:source_locale])
3333
end
3434
end
3535

lib/fastlane/plugin/wpmreleasetoolkit/helper/android/android_localize_helper.rb

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,24 @@ def self.merge_string_node(main_strings_xml, library, lib_string_node)
5454
# Search for the string in the main file
5555
result = :added
5656
main_strings_xml.xpath('//string').each do |main_string_node|
57-
if main_string_node.attr('name') == string_name
58-
# Skip if the string has the content_override tag
59-
return :skipped if skip_string_by_tag?(main_string_node)
60-
61-
# If nodes are equivalent, skip
62-
return :found if lib_string_node =~ main_string_node
63-
64-
# The string needs an update
65-
if main_string_node.attr('tools:ignore').nil?
66-
# No `tools:ignore` attribute; completely replace existing main string node with lib's one
67-
add_xml_attributes!(lib_string_node, library)
68-
main_string_node.replace lib_string_node
69-
else
70-
# Has the `tools:ignore` flag; update the content without touching the other existing attributes
71-
add_xml_attributes!(main_string_node, library)
72-
main_string_node.content = string_content
73-
end
74-
return :updated
57+
next unless main_string_node.attr('name') == string_name
58+
# Skip if the string has the content_override tag
59+
return :skipped if skip_string_by_tag?(main_string_node)
60+
61+
# If nodes are equivalent, skip
62+
return :found if lib_string_node =~ main_string_node
63+
64+
# The string needs an update
65+
if main_string_node.attr('tools:ignore').nil?
66+
# No `tools:ignore` attribute; completely replace existing main string node with lib's one
67+
add_xml_attributes!(lib_string_node, library)
68+
main_string_node.replace lib_string_node
69+
else
70+
# Has the `tools:ignore` flag; update the content without touching the other existing attributes
71+
add_xml_attributes!(main_string_node, library)
72+
main_string_node.content = string_content
7573
end
74+
return :updated
7675
end
7776

7877
# String not found, or removed because needing update and not in the exclusion list: add to the main file
@@ -91,14 +90,13 @@ def self.verify_string(main_strings_xml, library, lib_string_node)
9190

9291
# Search for the string in the main file
9392
main_strings_xml.xpath('//string').each do |main_string_node|
94-
if main_string_node.attr('name') == string_name
95-
# Skip if the string has the content_override tag
96-
return if skip_string_by_tag?(main_string_node)
93+
next unless main_string_node.attr('name') == string_name
94+
# Skip if the string has the content_override tag
95+
return if skip_string_by_tag?(main_string_node)
9796

98-
# Check if up-to-date
99-
UI.user_error!("String #{string_name} [#{string_content}] has been updated in the main file but not in the library #{library[:library]}.") if main_string_node.content != string_content
100-
return
101-
end
97+
# Check if up-to-date
98+
UI.user_error!("String #{string_name} [#{string_content}] has been updated in the main file but not in the library #{library[:library]}.") if main_string_node.content != string_content
99+
return
102100
end
103101

104102
# String not found and not in the exclusion list
@@ -180,22 +178,22 @@ def self.verify_lib(main, library, source_diff)
180178

181179
def self.verify_local_diff(main, library, main_strings, lib_strings)
182180
`git diff #{main}`.each_line do |line|
183-
if line.start_with?('+ ') || line.start_with?('- ')
184-
diffs = line.gsub(/\s+/m, ' ').strip.split
185-
diffs.each do |diff|
186-
verify_diff(diff, main_strings, lib_strings, library)
187-
end
181+
next unless line.start_with?('+ ') || line.start_with?('- ')
182+
183+
diffs = line.gsub(/\s+/m, ' ').strip.split
184+
diffs.each do |diff|
185+
verify_diff(diff, main_strings, lib_strings, library)
188186
end
189187
end
190188
end
191189

192190
def self.verify_pr_diff(main, library, main_strings, lib_strings, source_diff)
193191
source_diff.each_line do |line|
194-
if line.start_with?('+ ') || line.start_with?('- ')
195-
diffs = line.gsub(/\s+/m, ' ').strip.split
196-
diffs.each do |diff|
197-
verify_diff(diff, main_strings, lib_strings, library)
198-
end
192+
next unless line.start_with?('+ ') || line.start_with?('- ')
193+
194+
diffs = line.gsub(/\s+/m, ' ').strip.split
195+
diffs.each do |diff|
196+
verify_diff(diff, main_strings, lib_strings, library)
199197
end
200198
end
201199
end

lib/fastlane/plugin/wpmreleasetoolkit/helper/metadata_download_helper.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ def parse_data(target_locale, loc_data, is_source)
3838
source = d[0].split(/\u0004/).last
3939

4040
target_files.each do |file|
41-
if file[0].to_s == key
42-
data = file[1]
43-
msg = is_source ? source : d[1].first || '' # In the JSON, each Hash value is an array, with zero or one entry
44-
update_key(target_locale, key, file, data, msg)
45-
end
41+
next unless file[0].to_s == key
42+
43+
data = file[1]
44+
msg = is_source ? source : d[1].first || '' # In the JSON, each Hash value is an array, with zero or one entry
45+
update_key(target_locale, key, file, data, msg)
4646
end
4747
end
4848
end
@@ -55,12 +55,12 @@ def reparse_alternates(target_locale, loc_data, is_source)
5555

5656
@alternates.each do |file|
5757
puts "Data: #{file[0]} - key: #{key}"
58-
if file[0].to_s == key
59-
puts "Alternate: #{key}"
60-
data = file[1]
61-
msg = is_source ? source : d[1].first || '' # In the JSON, each Hash value is an array, with zero or one entry
62-
update_key(target_locale, key, file, data, msg)
63-
end
58+
next unless file[0].to_s == key
59+
60+
puts "Alternate: #{key}"
61+
data = file[1]
62+
msg = is_source ? source : d[1].first || '' # In the JSON, each Hash value is an array, with zero or one entry
63+
update_key(target_locale, key, file, data, msg)
6464
end
6565
end
6666
end

0 commit comments

Comments
 (0)