Skip to content

Commit fbbe034

Browse files
committed
Swift linting, part 3
1 parent a483ead commit fbbe034

33 files changed

+548
-141
lines changed

WooCommerce/Classes/Analytics/WooAnalytics.swift

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,25 @@ private extension WooAnalytics {
148148
return
149149
}
150150

151-
NotificationCenter.default.addObserver(self, selector: #selector(trackApplicationOpened), name: UIApplication.didBecomeActiveNotification, object: nil)
152-
NotificationCenter.default.addObserver(self, selector: #selector(trackApplicationClosed), name: UIApplication.didEnterBackgroundNotification, object: nil)
151+
NotificationCenter.default.addObserver(self,
152+
selector: #selector(trackApplicationOpened),
153+
name: UIApplication.didBecomeActiveNotification,
154+
object: nil)
155+
156+
NotificationCenter.default.addObserver(self,
157+
selector: #selector(trackApplicationClosed),
158+
name: UIApplication.didEnterBackgroundNotification,
159+
object: nil)
153160
}
154161

155162
func stopObservingNotifications() {
156-
NotificationCenter.default.removeObserver(self, name: UIApplication.didBecomeActiveNotification, object: nil)
157-
NotificationCenter.default.removeObserver(self, name: UIApplication.didEnterBackgroundNotification, object: nil)
163+
NotificationCenter.default.removeObserver(self,
164+
name: UIApplication.didBecomeActiveNotification,
165+
object: nil)
166+
167+
NotificationCenter.default.removeObserver(self,
168+
name: UIApplication.didEnterBackgroundNotification,
169+
object: nil)
158170
}
159171

160172
@objc func trackApplicationOpened() {

WooCommerce/Classes/AppDelegate.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,23 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
116116
pushNotesManager.registrationDidFail(with: error)
117117
}
118118

119-
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
119+
func application(_ application: UIApplication,
120+
didReceiveRemoteNotification userInfo: [AnyHashable: Any],
121+
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
120122
pushNotesManager.handleNotification(userInfo, completionHandler: completionHandler)
121123
}
122124

123125
func applicationWillResignActive(_ application: UIApplication) {
124-
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
125-
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
126+
// Sent when the application is about to move from active to inactive state.
127+
// This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message)
128+
// or when the user quits the application and it begins the transition to the background state.
129+
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks.
130+
// Games should use this method to pause the game.
126131
}
127132

128133
func applicationDidEnterBackground(_ application: UIApplication) {
129-
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
134+
// Use this method to release shared resources, save user data, invalidate timers,
135+
// and store enough application state information to restore your application to its current state in case it is terminated later.
130136
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
131137
}
132138

@@ -135,7 +141,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
135141
}
136142

137143
func applicationDidBecomeActive(_ application: UIApplication) {
138-
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
144+
// Restart any tasks that were paused (or not yet started) while the application was inactive.
145+
// If the application was previously in the background, optionally refresh the user interface.
139146

140147
RequirementsChecker.checkMinimumWooVersionForDefaultStore()
141148
}

WooCommerce/Classes/Authentication/AuthenticationConstants.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ struct AuthenticationConstants {
66

77
/// Email login instructions.
88
///
9-
static let emailInstructions = NSLocalizedString("Log in with your WordPress.com account email address to manage your WooCommerce stores.", comment: "Sign in instructions on the 'log in using email' screen.")
9+
static let emailInstructions = NSLocalizedString(
10+
"Log in with your WordPress.com account email address to manage your WooCommerce stores.",
11+
comment: "Sign in instructions on the 'log in using email' screen."
12+
)
1013

1114
/// Login with Jetpack instructions.
1215
///
13-
static let jetpackInstructions = NSLocalizedString("Log in with your WordPress.com account email address to manage your WooCommerce stores.", comment: "Sign in instructions on the 'log in using email' screen.")
16+
static let jetpackInstructions = NSLocalizedString(
17+
"Log in with your WordPress.com account email address to manage your WooCommerce stores.",
18+
comment: "Sign in instructions on the 'log in using email' screen."
19+
)
1420

1521
/// Login with site URL instructions.
1622
///
17-
static let siteInstructions = NSLocalizedString("Enter the address of your WooCommerce store you'd like to connect.", comment: "Sign in instructions for logging in with a URL.")
23+
static let siteInstructions = NSLocalizedString(
24+
"Enter the address of your WooCommerce store you'd like to connect.",
25+
comment: "Sign in instructions for logging in with a URL."
26+
)
1827
}

WooCommerce/Classes/Authentication/Epilogue/StorePickerViewController.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,13 @@ private extension StorePickerViewController {
314314
/// Displays the Error Notice for the version check.
315315
///
316316
func displayVersionCheckErrorNotice(siteID: Int, siteName: String) {
317-
let message = String.localizedStringWithFormat(NSLocalizedString("Unable to successfully connect to %@",
318-
comment: "On the site picker screen, the error displayed when connecting to a site fails. It reads: Unable to successfully connect to {site name}"), siteName)
317+
let message = String.localizedStringWithFormat(
318+
NSLocalizedString(
319+
"Unable to successfully connect to %@",
320+
comment: "On the site picker screen, the error displayed when connecting to a site fails. It reads: Unable to successfully connect to {site name}"
321+
),
322+
siteName
323+
)
319324
let actionTitle = NSLocalizedString("Retry", comment: "Retry Action")
320325
let notice = Notice(title: message, feedbackType: .error, actionTitle: actionTitle) { [weak self] in
321326
self?.displaySiteWCRequirementWarningIfNeeded(siteID: siteID, siteName: siteName)

WooCommerce/Classes/Authentication/Prologue/LoginPrologueViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,10 @@ private extension LoginPrologueViewController {
152152
/// Returns the Disclaimer Attributed Text (which contains a link to the Jetpack Setup URL).
153153
///
154154
var disclaimerAttributedText: NSAttributedString {
155-
let disclaimerText = NSLocalizedString("This app requires Jetpack to connect to your Store. <br /> Read the <a href=\"https://jetpack.com/support/getting-started-with-jetpack/\">configuration instructions</a>.", comment: "Login Disclaimer Text and Jetpack config instructions. It reads: 'This app requires Jetpack to connect to your Store. Read the configuration instructions.' and it links to a web page on the words 'configuration instructions'. Place the second sentence after the `<br />` tag. Place the noun, 'configuration instructions' between the opening `<a` tag and the closing `</a>` tags. If a literal translation of 'Read the configuration instructions' does not make sense in your language, please use a contextually appropriate substitution. For example, you can translate it to say 'See: instructions' or any alternative that sounds natural in your language.")
155+
let disclaimerText = NSLocalizedString(
156+
"This app requires Jetpack to connect to your Store. <br /> Read the <a href=\"https://jetpack.com/support/getting-started-with-jetpack/\">configuration instructions</a>.",
157+
comment: "Login Disclaimer Text and Jetpack config instructions. It reads: 'This app requires Jetpack to connect to your Store. Read the configuration instructions.' and it links to a web page on the words 'configuration instructions'. Place the second sentence after the `<br />` tag. Place the noun, 'configuration instructions' between the opening `<a` tag and the closing `</a>` tags. If a literal translation of 'Read the configuration instructions' does not make sense in your language, please use a contextually appropriate substitution. For example, you can translate it to say 'See: instructions' or any alternative that sounds natural in your language."
158+
)
156159
let disclaimerAttributes: [NSAttributedString.Key: Any] = [
157160
.font: UIFont.font(forStyle: .caption1, weight: .thin),
158161
.foregroundColor: UIColor.white

WooCommerce/Classes/Extensions/Date+Woo.swift

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,29 @@ extension Date {
7272
private extension Date {
7373

7474
enum Strings {
75-
static let presentDeicticExpression = NSLocalizedString("Updated moments ago", comment: "Deictic expression for a data update that occurred in the very recent past - similar to 'Updated just now'")
76-
static let singularMinuteUpdateStatment = NSLocalizedString("Updated %ld minute ago", comment: "Singular of 'minute' — date and time string that represents the time interval since last data update when exactly 1 minute ago. Usage example: Updated 1 minute ago")
77-
static let pluralMinuteUpdateStatment = NSLocalizedString("Updated %ld minutes ago", comment: "Plural of 'minute' — date and time string that represents the time interval since last data update when greater than 1 minute ago. Usage example: Updated 55 minutes ago")
78-
static let singularHourUpdateStatment = NSLocalizedString("Updated %ld hour ago", comment: "Singular of 'hour' — date and time string that represents the time interval since last data update when exactly 1 hour ago. Usage example: Updated 1 hour ago")
79-
static let pluralHourUpdateStatment = NSLocalizedString("Updated %ld hours ago", comment: "Plural of 'hour' — date and time string that represents the time interval since last data update when greater than 1 hour ago. Usage example: Updated 14 hours ago")
80-
static let longFormUpdateStatement = NSLocalizedString("Updated on %@", comment: "A specific date and time string which represents when the data was last updated. Usage example: Updated on Jan 22, 2019 3:31PM")
75+
static let presentDeicticExpression = NSLocalizedString(
76+
"Updated moments ago",
77+
comment: "Deictic expression for a data update that occurred in the very recent past - similar to 'Updated just now'"
78+
)
79+
static let singularMinuteUpdateStatment = NSLocalizedString(
80+
"Updated %ld minute ago",
81+
comment: "Singular of 'minute' — date and time string that represents the time interval since last data update when exactly 1 minute ago. Usage example: Updated 1 minute ago"
82+
)
83+
static let pluralMinuteUpdateStatment = NSLocalizedString(
84+
"Updated %ld minutes ago",
85+
comment: "Plural of 'minute' — date and time string that represents the time interval since last data update when greater than 1 minute ago. Usage example: Updated 55 minutes ago"
86+
)
87+
static let singularHourUpdateStatment = NSLocalizedString(
88+
"Updated %ld hour ago",
89+
comment: "Singular of 'hour' — date and time string that represents the time interval since last data update when exactly 1 hour ago. Usage example: Updated 1 hour ago"
90+
)
91+
static let pluralHourUpdateStatment = NSLocalizedString(
92+
"Updated %ld hours ago",
93+
comment: "Plural of 'hour' — date and time string that represents the time interval since last data update when greater than 1 hour ago. Usage example: Updated 14 hours ago"
94+
)
95+
static let longFormUpdateStatement = NSLocalizedString(
96+
"Updated on %@",
97+
comment: "A specific date and time string which represents when the data was last updated. Usage example: Updated on Jan 22, 2019 3:31PM"
98+
)
8199
}
82100
}

WooCommerce/Classes/Extensions/String+HTML.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ extension String {
3131
var htmlToAttributedString: NSAttributedString {
3232
guard let data = data(using: .utf8) else { return NSAttributedString() }
3333
do {
34-
return try NSAttributedString(data: data, options: [.documentType: NSAttributedString.DocumentType.html, .characterEncoding: String.Encoding.utf8.rawValue], documentAttributes: nil)
34+
return try NSAttributedString(data: data,
35+
options: [.documentType: NSAttributedString.DocumentType.html,
36+
.characterEncoding: String.Encoding.utf8.rawValue],
37+
documentAttributes: nil)
3538
} catch {
3639
DDLogError("Error: unable to convert HTML data to an attributed string")
3740
return NSAttributedString()

WooCommerce/Classes/ViewRelated/Dashboard/DashboardViewController.swift

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,19 @@ private extension DashboardViewController {
8080
}
8181

8282
private func configureTitle() {
83-
let myStore = NSLocalizedString("My store", comment: "Title of the bottom tab item that presents the user's store dashboard, and default title for the store dashboard")
83+
let myStore = NSLocalizedString(
84+
"My store",
85+
comment: "Title of the bottom tab item that presents the user's store dashboard, and default title for the store dashboard"
86+
)
8487
title = StoresManager.shared.sessionManager.defaultSite?.name ?? myStore
8588
tabBarItem.title = myStore
8689
}
8790

8891
private func resetTitle() {
89-
let myStore = NSLocalizedString("My store", comment: "Title of the bottom tab item that presents the user's store dashboard, and default title for the store dashboard")
92+
let myStore = NSLocalizedString(
93+
"My store",
94+
comment: "Title of the bottom tab item that presents the user's store dashboard, and default title for the store dashboard"
95+
)
9096
title = myStore
9197
tabBarItem.title = myStore
9298
}
@@ -99,7 +105,10 @@ private extension DashboardViewController {
99105
rightBarButton.tintColor = .white
100106
rightBarButton.accessibilityLabel = NSLocalizedString("Settings", comment: "Accessibility label for the Settings button.")
101107
rightBarButton.accessibilityTraits = .button
102-
rightBarButton.accessibilityHint = NSLocalizedString("Navigates to Settings.", comment: "VoiceOver accessibility hint, informing the user the button can be used to navigate to the Settings screen.")
108+
rightBarButton.accessibilityHint = NSLocalizedString(
109+
"Navigates to Settings.",
110+
comment: "VoiceOver accessibility hint, informing the user the button can be used to navigate to the Settings screen."
111+
)
103112
navigationItem.setRightBarButton(rightBarButton, animated: false)
104113

105114
// Don't show the Dashboard title in the next-view's back button

WooCommerce/Classes/ViewRelated/Dashboard/MyStore/Cells/NoPeriodDataTableViewCell.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ class NoPeriodDataTableViewCell: UITableViewCell {
1212
@IBOutlet private var legendLabel: UILabel! {
1313
didSet {
1414
legendLabel.applySubheadlineStyle()
15-
legendLabel.text = NSLocalizedString("No activity this period", comment: "Default text for Top Performers section when no data exists for a given period.")
15+
legendLabel.text = NSLocalizedString(
16+
"No activity this period",
17+
comment: "Default text for Top Performers section when no data exists for a given period."
18+
)
1619
}
1720
}
1821
}

WooCommerce/Classes/ViewRelated/Dashboard/MyStore/Cells/ProductTableViewCell.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ class ProductTableViewCell: UITableViewCell {
5353
extension ProductTableViewCell {
5454
func configure(_ statsItem: TopEarnerStatsItem?) {
5555
nameText = statsItem?.productName
56-
detailText = String.localizedStringWithFormat( NSLocalizedString("Total Product Order: %ld", comment: "Top performers — label for the total number of products ordered"), statsItem?.quantity ?? 0)
56+
detailText = String.localizedStringWithFormat(
57+
NSLocalizedString("Total Product Order: %ld",
58+
comment: "Top performers — label for the total number of products ordered"),
59+
statsItem?.quantity ?? 0
60+
)
5761
priceText = statsItem?.formattedTotalString
5862

5963
if let productURLString = statsItem?.imageUrl {

0 commit comments

Comments
 (0)