Skip to content

Enable SwiftLint rule: empty_count#25434

Merged
mokagio merged 5 commits intotrunkfrom
swiftlint/empty_count
Mar 30, 2026
Merged

Enable SwiftLint rule: empty_count#25434
mokagio merged 5 commits intotrunkfrom
swiftlint/empty_count

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented Mar 24, 2026

Summary

  • Enables the empty_count SwiftLint rule, which prefers checking .isEmpty over comparing .count to zero
  • 101 Swift files updated across the main app, modules, and tests
  • SwiftLint auto-fix handled the bulk of changes; 10 optional-chain false positives were corrected manually (added == true or ?? true where ?.isEmpty returns Optional<Bool>)

Changes

  • Added empty_count to only_rules in .swiftlint.yml
  • Replaced count == 0 / count > 0 / count != 0 patterns with .isEmpty / !.isEmpty
  • Fixed false positives where optional chaining (?.isEmpty) produced Bool? instead of Bool:
    • BlogQuery().blogs(...)?.isEmpty (2 occurrences)
    • blog.inviteLinks?.isEmpty (4 occurrences)
    • fetchedObjects?.isEmpty (3 occurrences)
    • groupedSettings[section]?.isEmpty (1 occurrence)
    • userSelectedCategories?.isEmpty (1 occurrence)

Test plan

  • rake lint passes with zero violations
  • xcodebuild build succeeds (WordPress scheme, iOS Simulator)
  • CI green

Part of the Orchard SwiftLint rollout campaign.

Posted by Claude Code (Opus 4.6) on behalf of @mokagio with approval.

Prefer checking `isEmpty` over comparing `count` to zero.
Part of the Orchard SwiftLint rollout campaign.

---

Generated with the help of Claude Code, https://code.claude.com

Co-Authored-By: Claude Code Opus 4.6 (1M context) <noreply@anthropic.com>
@mokagio mokagio requested a review from a team as a code owner March 24, 2026 00:34
@dangermattic
Copy link
Copy Markdown
Collaborator

dangermattic commented Mar 24, 2026

1 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.

Generated by 🚫 Danger

@mokagio mokagio added the Tooling Build, Release, and Validation Tools label Mar 24, 2026
@mokagio mokagio added this to the 26.9 milestone Mar 24, 2026
mokagio and others added 4 commits March 24, 2026 15:46
`AggregatedDataPoint.count` is an `Int` property, not a collection count.
Revert to `.count != 0` with inline disable.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
Non-collection types with a `.count` property but no `.isEmpty`:
- `ReaderInterestsDataSource`
- `AnyTermWithViewContext`
- `NSMutableOrderedSet`
- Tuple `(count: Int, difference: Int, percentage: Int)`

Found via Jetpack CI build — these targets aren't compiled by the WordPress scheme locally.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
`NSMutableArray` and `UIViewController`-typed `self` in closures have no `.isEmpty`.
All 3 in `ReaderStreamViewController.swift`.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
`NSSet` has no `.isEmpty` — revert to `.count == 0`.

---

Generated with the help of Claude Code, https://claude.ai/code

Co-Authored-By: Claude Code Opus 4.6 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

@wpmobilebot
Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number31757
VersionPR #25434
Bundle IDorg.wordpress.alpha
Commit1551eff
Installation URL6kfrocj2ajn5g
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot
Copy link
Copy Markdown
Contributor

App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number31757
VersionPR #25434
Bundle IDcom.jetpack.alpha
Commit1551eff
Installation URL67fk9kkbbd1fo
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

normalizedData[date] = dataPoint.sum
case .average:
if dataPoint.count > 0 {
// swiftlint:disable:next empty_count
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are nine instances where the rule is bypassed.

I considered getting the agent to refactor the code so that opting out is not necessary:

  Want me to create the follow-up branch with these changes? The plan would be:

  1. Add isEmpty extension on NSSet, NSMutableArray, NSMutableOrderedSet
  2. Add isEmpty to AggregatedDataPoint and ReaderInterestsDataSource
  3. Revert the disable comments for those 5 cases, using .isEmpty instead
  4. Keep the 2 legitimate disables (AnyTermWithViewContext, tuple)

Decided not to go down that path for the moment. In particular, extending Foundation Objective-C types seems like a dead end. We should remove them in favor of Swift implementations instead.

Copy link
Copy Markdown
Contributor

@kean kean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thank you!

@mokagio mokagio added this pull request to the merge queue Mar 30, 2026
Merged via the queue into trunk with commit e9e8600 Mar 30, 2026
27 checks passed
@mokagio mokagio deleted the swiftlint/empty_count branch March 30, 2026 03:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Tooling Build, Release, and Validation Tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants