Merged
Conversation
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>
Collaborator
Generated by 🚫 Danger |
`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>
|
Contributor
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 31757 | |
| Version | PR #25434 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 1551eff | |
| Installation URL | 6kfrocj2ajn5g |
Contributor
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 31757 | |
| Version | PR #25434 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 1551eff | |
| Installation URL | 67fk9kkbbd1fo |
mokagio
commented
Mar 26, 2026
| normalizedData[date] = dataPoint.sum | ||
| case .average: | ||
| if dataPoint.count > 0 { | ||
| // swiftlint:disable:next empty_count |
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.





Summary
empty_countSwiftLint rule, which prefers checking.isEmptyover comparing.countto zero== trueor?? truewhere?.isEmptyreturnsOptional<Bool>)Changes
empty_counttoonly_rulesin.swiftlint.ymlcount == 0/count > 0/count != 0patterns with.isEmpty/!.isEmpty?.isEmpty) producedBool?instead ofBool: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 lintpasses with zero violationsxcodebuild buildsucceeds (WordPress scheme, iOS Simulator)Posted by Claude Code (Opus 4.6) on behalf of @mokagio with approval.