Skip to content

Commit d64cb7f

Browse files
authored
Improve RuboCop setup and address some violations (#7472)
2 parents 9dbf8d5 + 9629426 commit d64cb7f

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
AllCops:
2+
Exclude:
3+
- DerivedData/**/*
4+
- Pods/**/*
5+
- vendor/**/*
6+
NewCops: enable
7+
18
Metrics/BlockLength:
29
Exclude:
310
- fastlane/Fastfile
@@ -12,6 +19,7 @@ Style/AsciiComments:
1219
Layout/LineLength:
1320
Exclude:
1421
- fastlane/Fastfile
22+
- Podfile
1523

1624
Naming/FileName:
1725
Exclude:

Podfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ post_install do |installer|
327327

328328
# Flag Alpha builds for Tracks
329329
# ============================
330+
# rubocop:disable Style/CombinableLoops
330331
installer.pods_project.targets.each do |target|
331332
next unless target.name == 'Automattic-Tracks-iOS'
332333

@@ -336,4 +337,5 @@ post_install do |installer|
336337
config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] ||= ['$(inherited)', 'ALPHA=1']
337338
end
338339
end
340+
# rubocop:enable Style/CombinableLoops
339341
end

fastlane/Deliverfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ app_identifier 'com.automattic.woocommerce'
1515
screenshots_path './fastlane/promo_screenshots/'
1616

1717
# Make sure to update these keys for a new version
18-
app_version "10.1"
18+
app_version '10.1'
1919

2020
team_id '299112'
2121

fastlane/Fastfile

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ USER_ENV_FILE_PATH = File.join(Dir.home, '.wcios-env.default')
1010
SECRETS_DIR = File.join(Dir.home, '.configure', 'woocommerce-ios', 'secrets')
1111
PROJECT_ENV_FILE_PATH = File.join(SECRETS_DIR, 'project.env')
1212

13+
GHHELPER_REPO = 'woocommerce/woocommerce-ios'
14+
1315
# Constants
1416
PROJECT_ROOT_FOLDER = File.dirname(File.expand_path(__dir__))
1517
RESOURCES_FOLDER = File.join(PROJECT_ROOT_FOLDER, 'WooCommerce', 'Resources')
@@ -89,7 +91,7 @@ GLOTPRESS_TO_ASC_METADATA_LOCALE_CODES = {
8991
'sv' => 'sv',
9092
'tr' => 'tr',
9193
'zh-cn' => 'zh-Hans',
92-
'zh-tw' => 'zh-Hant',
94+
'zh-tw' => 'zh-Hant'
9395
}.freeze
9496

9597
ASC_KEY_PATH = File.join(SECRETS_DIR, 'app_store_connect_fastlane_api_key.json')
@@ -100,7 +102,7 @@ def get_required_env(key)
100102
unless ENV.key?(key)
101103
UI.user_error!("Environment variable '#{key}' is not set. Have you setup #{USER_ENV_FILE_PATH} correctly?")
102104
end
103-
ENV[key]
105+
ENV.fetch(key)
104106
end
105107

106108
before_all do |lane|
@@ -127,17 +129,12 @@ platform :ios do
127129
########################################################################
128130
Dotenv.load(USER_ENV_FILE_PATH)
129131
Dotenv.load(PROJECT_ENV_FILE_PATH)
130-
ENV[GHHELPER_REPO = 'woocommerce/woocommerce-iOS']
131132
ENV['PROJECT_NAME'] = 'WooCommerce'
132133
ENV['PUBLIC_CONFIG_FILE'] = 'config/Version.Public.xcconfig'
133134
ENV['PROJECT_ROOT_FOLDER'] = './'
134135
ENV['APP_STORE_STRINGS_FILE_NAME'] = 'AppStoreStrings.pot'
135136
ENV['FL_RELEASE_TOOLKIT_DEFAULT_BRANCH'] = 'trunk'
136137

137-
# Other defines used across multiple lanes
138-
REPOSITORY_NAME = 'woocommerce-ios'
139-
GH_ORG_NAME = 'woocommerce'
140-
141138
########################################################################
142139
# Release Lanes
143140
########################################################################
@@ -334,7 +331,7 @@ platform :ios do
334331
version = ios_get_app_version
335332
removebranchprotection(repository: GHHELPER_REPO, branch: "release/#{version}")
336333
setfrozentag(repository: GHHELPER_REPO, milestone: version, freeze: false)
337-
create_new_milestone(repository:GHHELPER_REPO, need_appstore_submission: true, milestone_duration:7, number_of_days_from_code_freeze_to_release: 10)
334+
create_new_milestone(repository: GHHELPER_REPO, need_appstore_submission: true, milestone_duration: 7, number_of_days_from_code_freeze_to_release: 10)
338335
close_milestone(repository: GHHELPER_REPO, milestone: version)
339336

340337
# Start the build
@@ -502,7 +499,7 @@ platform :ios do
502499
export_method: 'enterprise',
503500
clean: true,
504501
output_directory: 'build',
505-
export_team_id: ENV['INT_EXPORT_TEAM_ID'],
502+
export_team_id: ENV.fetch('INT_EXPORT_TEAM_ID'),
506503
export_options: { method: 'enterprise', iCloudContainerEnvironment: 'Production' }
507504
)
508505

@@ -540,7 +537,7 @@ platform :ios do
540537

541538
comment_on_pr(
542539
project: 'woocommerce/woocommerce-ios',
543-
pr_number: Integer(ENV['BUILDKITE_PULL_REQUEST']),
540+
pr_number: Integer(ENV.fetch('BUILDKITE_PULL_REQUEST')),
544541
reuse_identifier: 'installable-build-link',
545542
body: comment_body
546543
)
@@ -727,7 +724,7 @@ platform :ios do
727724
runtime = SimCtl.runtime(name: "iOS #{SIMULATOR_VERSION}")
728725
devicetype = SimCtl.devicetype(name: device)
729726

730-
device = SimCtl.create_device device, devicetype, runtime
727+
SimCtl.create_device(device, devicetype, runtime)
731728
end
732729
end
733730

@@ -793,11 +790,11 @@ platform :ios do
793790
# FIXME: Replace this with a call to the future replacement of `gp_downloadmetadata` once it's implemented in the release-toolkit (see paaHJt-31O-p2).
794791
locales_map = GLOTPRESS_TO_ASC_METADATA_LOCALE_CODES
795792
target_files = {
796-
"v#{ios_get_app_version}-whats-new": { desc: "release_notes.txt", max_size: 4000 },
797-
app_store_name: { desc: "name.txt", max_size: 30 },
798-
app_store_subtitle: { desc: "subtitle.txt", max_size: 30 },
799-
app_store_desc: { desc: "description.txt", max_size: 4000 },
800-
app_store_keywords: { desc: "keywords.txt", max_size: 100 },
793+
"v#{ios_get_app_version}-whats-new": { desc: 'release_notes.txt', max_size: 4000 },
794+
app_store_name: { desc: 'name.txt', max_size: 30 },
795+
app_store_subtitle: { desc: 'subtitle.txt', max_size: 30 },
796+
app_store_desc: { desc: 'description.txt', max_size: 4000 },
797+
app_store_keywords: { desc: 'keywords.txt', max_size: 100 }
801798
}
802799

803800
gp_downloadmetadata(
@@ -811,14 +808,17 @@ platform :ios do
811808
# Ensure that none of the `.txt` files in `en-US` would accidentally override our originals in `default`
812809
target_files.values.map { |h| h[:desc] }.each do |file|
813810
en_file_path = File.join(metadata_directory, 'en-US', file)
814-
UI.user_error!("File `#{en_file_path}` would override the same one in `#{metadata_directory}/default`, but `default/` is the source of truth. " \
815-
+ "Delete the `#{en_file_path}` file, ensure the `default/` one has the expected original copy, and try again.") if File.exist?(en_file_path)
811+
if File.exist?(en_file_path)
812+
UI.user_error!("File `#{en_file_path}` would override the same one in `#{metadata_directory}/default`, but `default/` is the source of truth. " \
813+
+ "Delete the `#{en_file_path}` file, ensure the `default/` one has the expected original copy, and try again.")
814+
end
816815
end
817816

818817
# Ensure even empty locale folders have an empty `.gitkeep` file (in case we don't have any translation at all ready for some locales)
819-
locales_map.values.each do |locale|
818+
locales_map.each_value do |locale|
820819
gitkeep = File.join(metadata_directory, locale, '.gitkeep')
821820
next if File.exist?(gitkeep)
821+
822822
FileUtils.mkdir_p(File.dirname(gitkeep))
823823
FileUtils.touch(gitkeep)
824824
files_to_commit.append(gitkeep)
@@ -966,11 +966,11 @@ platform :ios do
966966
'Pods/WordPress*/',
967967
'Storage/Storage/',
968968
'Networking/Networking/',
969-
'Hardware/Hardware/',
969+
'Hardware/Hardware/'
970970
],
971971
exclude: [
972972
'*Vendor*',
973-
'WooCommerce/WooCommerceTests/**', # Some unit tests include localized strings, but we don't want to crowd GlotPress with them
973+
'WooCommerce/WooCommerceTests/**' # Some unit tests include localized strings, but we don't want to crowd GlotPress with them
974974
],
975975
output_dir: en_lproj_path
976976
)
@@ -1081,10 +1081,10 @@ end
10811081
# Generates Installable Build Version Numbers in a Buildkite-specific way
10821082
# -----------------------------------------------------------------------------------
10831083
def generate_installable_build_number
1084-
if ENV['BUILDKITE']
1085-
commit = ENV['BUILDKITE_COMMIT'][0, 7]
1086-
branch = ENV['BUILDKITE_BRANCH']
1087-
pr_num = ENV['BUILDKITE_PULL_REQUEST']
1084+
if ENV.key?('BUILDKITE')
1085+
commit = ENV.fetch('BUILDKITE_COMMIT')[0, 7]
1086+
branch = ENV.fetch('BUILDKITE_BRANCH')
1087+
pr_num = ENV.fetch('BUILDKITE_PULL_REQUEST')
10881088

10891089
pr_num == 'false' ? "#{branch}-#{commit}" : "pr#{pr_num}-#{commit}"
10901090
else

0 commit comments

Comments
 (0)