Skip to content

Commit cf66d6c

Browse files
authored
Enable SwiftLint rule: toggle_bool (#25504)
Prefer `someBool.toggle()` over `someBool = !someBool`. 12 violations auto-fixed; no manual changes required. Part of the Orchard SwiftLint rollout campaign.
1 parent 1e92de4 commit cf66d6c

8 files changed

Lines changed: 15 additions & 12 deletions

File tree

.swiftlint.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ only_rules:
6262

6363
- shorthand_optional_binding
6464

65+
# Prefer `someBool.toggle()` over `someBool = !someBool`.
66+
- toggle_bool
67+
6568
# Files should have a single trailing newline.
6669
- trailing_newline
6770

Sources/WordPressAuthenticator/Helpers/UnifiedAuth/ViewRelated/ReusableViews/TextFieldTableViewCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ private extension TextFieldTableViewCell {
173173
}
174174

175175
@objc func secureTextEntryToggleAction(_ sender: Any) {
176-
textField.isSecureTextEntry = !textField.isSecureTextEntry
176+
textField.isSecureTextEntry.toggle()
177177

178178
// Save and re-apply the current selection range to save the cursor position
179179
let currentTextRange = textField.selectedTextRange

WordPress/Classes/ViewRelated/Blog/Sharing/SharingButtonsViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class SharingButtonsViewController: UITableViewController {
406406
switchCell.onChange = { [weak self] newValue in
407407
guard let self else { return }
408408
WPAnalytics.track(.sharingButtonsEditSharingButtonsToggled, properties: ["checked": newValue as Any], blog: self.blog)
409-
self.buttonsSection.editing = !self.buttonsSection.editing
409+
self.buttonsSection.editing.toggle()
410410
self.updateButtonOrderAfterEditing()
411411
self.reloadButtons()
412412
}
@@ -452,7 +452,7 @@ class SharingButtonsViewController: UITableViewController {
452452
guard let self else { return }
453453
WPAnalytics.track(.sharingButtonsEditMoreButtonToggled, properties: ["checked": newValue as Any], blog: self.blog)
454454
self.updateButtonOrderAfterEditing()
455-
self.moreSection.editing = !self.moreSection.editing
455+
self.moreSection.editing.toggle()
456456
self.reloadButtons()
457457
}
458458
}

WordPress/Classes/ViewRelated/Cells/ExpandableCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class ExpandableCell: WPReusableTableViewCell, NibLoadable {
5353
}
5454

5555
public func toggle() {
56-
expanded = !expanded
56+
expanded.toggle()
5757
}
5858

5959
private func setupSubviews() {

WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationSettingsViewController.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -582,10 +582,10 @@ extension NotificationSettingsViewController {
582582
let section = self.section(at: index.section)
583583
switch section {
584584
case .blog:
585-
displayBlogMoreWasAccepted = !displayBlogMoreWasAccepted
585+
displayBlogMoreWasAccepted.toggle()
586586

587587
case .followedSites:
588-
displayFollowedMoreWasAccepted = !displayFollowedMoreWasAccepted
588+
displayFollowedMoreWasAccepted.toggle()
589589

590590
default:
591591
return

WordPress/Classes/ViewRelated/Notifications/Views/NoteBlockUserTableViewCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class NoteBlockUserTableViewCell: NoteBlockTableViewCell {
9696
if let listener = isFollowOn ? onUnfollowClick : onFollowClick {
9797
listener()
9898
}
99-
isFollowOn = !isFollowOn
99+
isFollowOn.toggle()
100100
}
101101
}
102102

WordPress/Classes/ViewRelated/Plugins/ViewModels/PluginViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ class PluginViewModel: Observable {
383383
expandedText: setHTMLTextAttributes(text),
384384
expanded: descriptionExpandedStatus,
385385
action: { [unowned self] row in
386-
self.descriptionExpandedStatus = !self.descriptionExpandedStatus
386+
self.descriptionExpandedStatus.toggle()
387387
(row as? ExpandableRow)?.expanded = self.descriptionExpandedStatus
388388
},
389389
onLinkTap: { [unowned self] url in
@@ -399,7 +399,7 @@ class PluginViewModel: Observable {
399399
expandedText: setHTMLTextAttributes(text),
400400
expanded: installationExpandedStatus,
401401
action: { [unowned self] row in
402-
self.installationExpandedStatus = !self.installationExpandedStatus
402+
self.installationExpandedStatus.toggle()
403403
(row as? ExpandableRow)?.expanded = self.installationExpandedStatus
404404
},
405405
onLinkTap: { [unowned self] url in
@@ -415,7 +415,7 @@ class PluginViewModel: Observable {
415415
expandedText: setHTMLTextAttributes(text),
416416
expanded: changeLogExpandedStatus,
417417
action: { [unowned self] row in
418-
self.changeLogExpandedStatus = !self.changeLogExpandedStatus
418+
self.changeLogExpandedStatus.toggle()
419419
(row as? ExpandableRow)?.expanded = self.changeLogExpandedStatus
420420
},
421421
onLinkTap: { [unowned self] url in
@@ -431,7 +431,7 @@ class PluginViewModel: Observable {
431431
expandedText: setHTMLTextAttributes(text),
432432
expanded: faqExpandedStatus,
433433
action: { [unowned self] row in
434-
self.faqExpandedStatus = !self.faqExpandedStatus
434+
self.faqExpandedStatus.toggle()
435435
(row as? ExpandableRow)?.expanded = self.faqExpandedStatus
436436
},
437437
onLinkTap: { [unowned self] url in

WordPress/Classes/ViewRelated/Reader/Cards/Tags View/ReaderTopicCollectionViewCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ extension ReaderTopicCollectionViewCoordinator: UICollectionViewDelegateFlowLayo
206206
return
207207
}
208208

209-
layout.isExpanded = !layout.isExpanded
209+
layout.isExpanded.toggle()
210210
layout.invalidateLayout()
211211

212212
WPAnalytics.trackReader(.readerChipsMoreToggled)

0 commit comments

Comments
 (0)