Skip to content

Commit

Permalink
Remove last if let strongSelf = self usages (#23836)
Browse files Browse the repository at this point in the history
* Sort `.swiftlint.yml` rules alphabetically

* Opt into `shorthand_optional_binding` SwiftLint rule

* Address `shorthand_optional_binding` SwiftLint violations

Run via `Pods/SwiftLint/swiftlint lint --fix`
  • Loading branch information
mokagio authored Nov 27, 2024
1 parent 909c645 commit 01a1e97
Show file tree
Hide file tree
Showing 432 changed files with 1,067 additions and 1,066 deletions.
7 changes: 4 additions & 3 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ excluded:
- Modules/.build

opt_in_rules:
- overridden_super_call
- discarded_notification_center_observer
- weak_delegate
- vertical_whitespace
- duplicate_imports
- overridden_super_call
- shorthand_optional_binding
- vertical_whitespace
- weak_delegate

overridden_super_call:
severity: error
Expand Down
2 changes: 1 addition & 1 deletion Modules/Sources/DesignSystem/Gallery/ColorGallery.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private extension Color {
// MARK: - Helpers for Color Gallery
private extension UIColor {
func color(for trait: UITraitCollection?) -> UIColor {
if let trait = trait {
if let trait {
return resolvedColor(with: trait)
}
return self
Expand Down
2 changes: 1 addition & 1 deletion Modules/Sources/WordPressFlux/QueryStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ open class QueryStore<State, Query>: StatefulStore<State>, Unsubscribable {
override public final var state: State {
get {
// If the in-memory State is populated, just return that.
if let inMemoryState = inMemoryState {
if let inMemoryState {
return inMemoryState
}

Expand Down
2 changes: 1 addition & 1 deletion Modules/Sources/WordPressShared/Utility/Debouncer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public final class Debouncer {
}

deinit {
if let timer = timer, timer.fireDate >= Date() {
if let timer, timer.fireDate >= Date() {
timer.invalidate()
callback?()
}
Expand Down
4 changes: 2 additions & 2 deletions Modules/Sources/WordPressShared/Utility/NSDate+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ extension Date {

let absoluteFormatter = DateFormatters.mediumDate

if let timeZone = timeZone {
if let timeZone {
absoluteFormatter.timeZone = timeZone
}

Expand All @@ -145,7 +145,7 @@ extension Date {
/// - Parameter timeZone: An optional time zone used to adjust the date formatters.
public func mediumStringWithTime(timeZone: TimeZone? = nil) -> String {
let formatter = DateFormatters.mediumDateTime
if let timeZone = timeZone {
if let timeZone {
formatter.timeZone = timeZone
}
return formatter.string(from: self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public extension NSNotification.Name {

extension Foundation.Notification {
public func userInfoHasEmail(_ email: String) -> Bool {
guard let userInfo = userInfo,
guard let userInfo,
let notificationEmail = userInfo[GravatarQEAvatarUpdateNotificationKeys.email.rawValue] as? String else {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class BottomSheetViewController: UIViewController {
} else {
modalPresentationStyle = .popover

if let sourceBarButtonItem = sourceBarButtonItem {
if let sourceBarButtonItem {
popoverPresentationController?.barButtonItem = sourceBarButtonItem
} else {
popoverPresentationController?.permittedArrowDirections = arrowDirections
Expand Down Expand Up @@ -129,7 +129,7 @@ public class BottomSheetViewController: UIViewController {
gripButton.heightAnchor.constraint(equalToConstant: Constants.gripHeight)
])

guard let childViewController = childViewController else {
guard let childViewController else {
return
}

Expand Down Expand Up @@ -263,7 +263,7 @@ extension BottomSheetViewController: DrawerPresentable {
}

public func handleDismiss() {
if let childViewController = childViewController {
if let childViewController {
childViewController.handleDismiss()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -536,8 +536,8 @@ extension DrawerPresentationController: UIGestureRecognizerDelegate {

/// Shouldn't happen; should always have container & presented view when tapped
guard
let containerView = containerView,
let presentedView = presentedView,
let containerView,
let presentedView,
currentPosition != .hidden
else {
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ extension UIImage {

cgContext.restoreGState()

if let border = border {
if let border {
border.setStroke()
path.stroke()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension UIImageView {
/// - email: associated email of the new gravatar
@objc public func updateGravatar(image: UIImage, email: String?) {
self.image = image
guard let email = email else {
guard let email else {
return
}
NotificationCenter.default.post(name: .GravatarImageUpdateNotification, object: self, userInfo: [Defaults.emailKey: email, Defaults.imageKey: image])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ public extension UIImageView {
@objc func downloadImage(from url: URL?, placeholderImage: UIImage? = nil, success: ((UIImage) -> Void)? = nil, failure: ((Error?) -> Void)? = nil) {
// Ideally speaking, this method should *not* receive an Optional URL. But we're doing so, for convenience.
// If the actual URL was nil, at least we set the Placeholder Image. Capicci?
guard let url = url else {
guard let url else {
cancelImageDownload()

if let placeholderImage = placeholderImage {
if let placeholderImage {
self.image = placeholderImage
}

Expand Down Expand Up @@ -67,7 +67,7 @@ public extension UIImageView {
}

guard let url = request.url else {
if let placeholderImage = placeholderImage {
if let placeholderImage {
image = placeholderImage
}

Expand All @@ -82,12 +82,12 @@ public extension UIImageView {

// Using the placeholder only makes sense if we know we're going to download an image
// that's not immediately available to us.
if let placeholderImage = placeholderImage {
if let placeholderImage {
self.image = placeholderImage
}

let task = URLSession.shared.dataTask(with: request, completionHandler: { [weak self] data, response, error in
guard let data = data, let image = UIImage(data: data, scale: UIScreen.main.scale) else {
guard let data, let image = UIImage(data: data, scale: UIScreen.main.scale) else {
DispatchQueue.main.async {
failure?(error)
self?.downloadTask = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ extension UITableViewController {
self.tableView.deselectRow(at: indexPath, animated: true)
}
let completionBlock: (UIViewControllerTransitionCoordinatorContext?) -> Void = { [unowned self] context in
if let context = context,
if let context,
context.isCancelled {
self.tableView.selectRow(at: indexPath, animated: true, scrollPosition: .none)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open class FancyAlertPresentationController: UIPresentationController, UIViewCon
}(UIView())

override open func presentationTransitionWillBegin() {
guard let containerView = containerView else { return }
guard let containerView else { return }

containerView.addSubview(dimmingView)
containerView.pinSubviewToAllEdges(dimmingView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ open class FancyAlertViewController: UIViewController {

private func updateViewConfiguration() {
guard isViewLoaded else { return }
guard let configuration = configuration else { return }
guard let configuration else { return }

buttonHandlers.removeAll()

Expand Down Expand Up @@ -349,7 +349,7 @@ open class FancyAlertViewController: UIViewController {
}

private func update(_ button: UIButton, with buttonConfig: Config.ButtonConfig?) {
guard let buttonConfig = buttonConfig else {
guard let buttonConfig else {
button.isHiddenInStackView = true
return
}
Expand All @@ -361,7 +361,7 @@ open class FancyAlertViewController: UIViewController {
}

private func updateBottomSwitch(with config: Config.SwitchConfig?) {
guard let config = config else {
guard let config else {
alertView.bottomSwitchStackView.isHiddenInStackView = true
return
}
Expand Down
2 changes: 1 addition & 1 deletion Modules/Sources/WordPressUI/FancyAlert/FancyButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ open class FancyButton: UIButton {
// wrap appropriately including insets above and below.
//
open override var intrinsicContentSize: CGSize {
guard let titleLabel = titleLabel else {
guard let titleLabel else {
return super.intrinsicContentSize
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ open class FlingableViewHandler: NSObject {
// Check for the view leaving the screen
pushBehavior.action = { [weak self] in
guard let strongSelf = self,
let referenceView = referenceView else { return }
let referenceView else { return }

if !view.frame.intersects(referenceView.bounds) {
strongSelf.animator.removeAllBehaviors()
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Extensions/Array+Page.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension Array where Element == Page {
/// - Parameter pageId: Page id
/// - Returns: If the Page exists or not
func containsPage(for pageId: Int?) -> Bool {
guard let pageId = pageId else {
guard let pageId else {
return false
}

Expand Down
4 changes: 2 additions & 2 deletions WordPress/Classes/Extensions/Array.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ extension Array {
forEach { (element) in
let value = transforming(element)
if currentValue != value {
if let currentValue = currentValue {
if let currentValue {
result.append((currentValue, currentGroup))
}
currentValue = value
currentGroup = []
}
currentGroup.append(element)
}
if let currentValue = currentValue {
if let currentValue {
result.append((currentValue, currentGroup))
}
return result
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Extensions/CLPlacemark+Formatting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ extension CLPlacemark {
if let zipCode = postalCode {
address.append(", " + zipCode)
}
if let country = country {
if let country {
address.append(", " + country)
}
return address
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension UIColor {
}

func color(for trait: UITraitCollection?) -> UIColor {
if let trait = trait {
if let trait {
return resolvedColor(with: trait)
}
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,14 +117,14 @@ extension WPStyleGuide {
}

class func configureTableViewColors(view: UIView?) {
guard let view = view else {
guard let view else {
return
}
view.backgroundColor = .systemBackground
}

class func configureTableViewColors(tableView: UITableView?) {
guard let tableView = tableView else {
guard let tableView else {
return
}

Expand All @@ -140,7 +140,7 @@ extension WPStyleGuide {

@objc
class func configureTableViewCell(_ cell: UITableViewCell?) {
guard let cell = cell else {
guard let cell else {
return
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Extensions/Comment+Interface.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension Comment {
/// as well!
///
@objc func relativeDateSectionIdentifier() -> String? {
guard let dateCreated = dateCreated else {
guard let dateCreated else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ extension NSAttributedString {
// set via CSS). So we'll look for a paragraph style specified for the
// body of the text, so we can copy it use its text alignment.
let paragraphStyle = NSMutableParagraphStyle()
if let attributes = attributes,
if let attributes,
let bodyAttributes = attributes[.BodyAttribute],
let pStyle = bodyAttributes[.paragraphStyle] as? NSParagraphStyle {
paragraphStyle.setParagraphStyle(pStyle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ extension NSFetchedResultsController {
/// Returns whether an indexPath represents the last row in it's section, or not
///
@objc func isLastIndexPathInSection(_ indexPath: IndexPath) -> Bool {
guard let sections = sections else {
guard let sections else {
return false
}

Expand All @@ -19,7 +19,7 @@ extension NSFetchedResultsController {
/// Otherwise, null will be returned.
///
@objc func managedObject(atUnsafe indexPath: IndexPath) -> NSManagedObject? {
guard let sections = sections else {
guard let sections else {
return nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ extension NSMutableAttributedString {
/// - attributes: Collection of attributes to be applied on the matched strings
///
public func applyAttributes(toQuotes attributes: [NSAttributedString.Key: Any]?) {
guard let attributes = attributes else {
guard let attributes else {
return
}
let rawString = self.string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ private class OneTimeObserver {
}

func run(_ notification: Foundation.Notification) {
if let observer = observer {
if let observer {
NotificationCenter.default.removeObserver(observer)
}
action(notification)
Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Extensions/Post+BloggingPrompts.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Foundation
extension Post {

func prepareForPrompt(_ prompt: BloggingPrompt?) {
guard let prompt = prompt else {
guard let prompt else {
return
}

Expand Down
2 changes: 1 addition & 1 deletion WordPress/Classes/Extensions/URL+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ extension URL {
}

var isHostedAtWPCom: Bool {
guard let host = host else {
guard let host else {
return false
}

Expand Down
6 changes: 3 additions & 3 deletions WordPress/Classes/Models/AbstractPost+Searchable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ extension AbstractPost: SearchableItemConvertable {
}

var searchIdentifier: String? {
guard let postID = postID, postID.intValue > 0 else {
guard let postID, postID.intValue > 0 else {
return nil
}
return postID.stringValue
Expand Down Expand Up @@ -55,7 +55,7 @@ extension AbstractPost: SearchableItemConvertable {
fileprivate extension AbstractPost {
func generateKeywordsFromContent() -> [String]? {
var keywords: [String]? = nil
if let postTitle = postTitle {
if let postTitle {
// Try to generate some keywords from the title...
keywords = postTitle.components(separatedBy: " ").map({ $0.trimmingCharacters(in: .whitespacesAndNewlines) })
} else if !contentPreviewForDisplay().isEmpty {
Expand All @@ -68,7 +68,7 @@ fileprivate extension AbstractPost {
func generateTitle(from postTitle: String?) -> String {
let noTitleText = NSLocalizedString("No Title", comment: "Label used for posts without a title in spotlight search.")
var title = "(\(noTitleText))"
if let postTitle = postTitle, !postTitle.isEmpty {
if let postTitle, !postTitle.isEmpty {
title = postTitle
}

Expand Down
Loading

0 comments on commit 01a1e97

Please sign in to comment.