Skip to content

Commit e9e8600

Browse files
mokagioclaude
andauthored
Enable SwiftLint rule: empty_count (#25434)
* Enable SwiftLint rule: empty_count 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> * Fix false positive on AggregatedDataPoint `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> * Fix 4 more empty_count false positives 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> * Fix 3 more empty_count false positives `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> * Fix NSSet empty_count false positive `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> --------- Co-authored-by: Claude Code Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 133a907 commit e9e8600

102 files changed

Lines changed: 169 additions & 157 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.swiftlint.yml

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

2727
- duplicate_imports
2828

29+
# Prefer checking `isEmpty` over comparing `count` to zero.
30+
- empty_count
31+
2932
# Arguments can be omitted when matching enums with associated types if they
3033
# are not used.
3134
- empty_enum_arguments

Modules/Sources/JetpackStats/Charts/BarChartView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ struct BarChartView: View {
158158

159159
@ChartContentBuilder
160160
private var significantPointAnnotations: some ChartContent {
161-
if tappedDataPoint == nil, let maxPoint = data.significantPoints.currentMax, data.currentData.count > 0 {
161+
if tappedDataPoint == nil, let maxPoint = data.significantPoints.currentMax, !data.currentData.isEmpty {
162162
PointMark(
163163
x: .value("Date", maxPoint.date, unit: data.granularity.component, calendar: context.calendar),
164164
y: .value("Value", maxPoint.value)

Modules/Sources/JetpackStats/Charts/LineChartView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ struct LineChartView: View {
165165

166166
@ChartContentBuilder
167167
private var significantPointAnnotations: some ChartContent {
168-
if let maxPoint = data.significantPoints.currentMax, data.currentData.count > 0 {
168+
if let maxPoint = data.significantPoints.currentMax, !data.currentData.isEmpty {
169169
PointMark(
170170
x: .value("Date", maxPoint.date, unit: data.granularity.component, calendar: context.calendar),
171171
y: .value("Value", maxPoint.value)

Modules/Sources/JetpackStats/Charts/SimpleBarChartView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ struct SimpleBarChartView: View {
102102

103103
@ChartContentBuilder
104104
private var peakAnnotation: some ChartContent {
105-
if let maxPoint = data.currentData.max(by: { $0.value < $1.value }), data.currentData.count > 0 {
105+
if let maxPoint = data.currentData.max(by: { $0.value < $1.value }), !data.currentData.isEmpty {
106106
PointMark(
107107
x: .value("Date", maxPoint.date, unit: data.granularity.component),
108108
y: .value("Value", maxPoint.value)

Modules/Sources/JetpackStats/Screens/TopListScreenView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ struct TopListScreenView: View {
181181

182182
@ViewBuilder
183183
private func listContent(data: TopListData) -> some View {
184-
if data.items.count > 0 {
184+
if !data.items.isEmpty {
185185
listSection(.top10, data: data)
186186
}
187187
if data.items.count > 10 {

Modules/Sources/JetpackStats/Services/Mocks/StatsDataAggregator.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ struct StatsDataAggregator {
6161
case .sum:
6262
normalizedData[date] = dataPoint.sum
6363
case .average:
64-
if dataPoint.count > 0 {
64+
// swiftlint:disable:next empty_count
65+
if dataPoint.count != 0 {
6566
normalizedData[date] = dataPoint.sum / dataPoint.count
6667
}
6768
}

Modules/Sources/JetpackStats/Views/TopList/Rows/TopListExternalLinkRowView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct TopListExternalLinkRowView: View {
1010
.foregroundColor(.primary)
1111
.lineLimit(1)
1212

13-
if item.children.count > 0 {
13+
if !item.children.isEmpty {
1414
Text(Strings.ArchiveSections.itemCount(item.children.count))
1515
.font(.caption)
1616
.foregroundColor(.secondary)

Modules/Sources/UITestsFoundation/Screens/CommentsScreen.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class CommentsScreen: ScreenObject {
6868
public func verifyCommentsListEmpty() -> CommentsScreen {
6969
XCTAssertTrue(emptyImage.waitForExistence(timeout: 3))
7070
XCTAssertTrue(app.staticTexts["Be the first to leave a comment."].isHittable)
71-
XCTAssertTrue(app.cells.containing(.button, identifier: "reply-comment-button").count == 0)
71+
XCTAssertTrue(app.cells.containing(.button, identifier: "reply-comment-button").isEmpty)
7272
return self
7373
}
7474

Modules/Sources/WordPressIntelligence/Utilities/ContentExtractor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public enum ContentExtractor {
2626
public static func extractRelevantText(from content: String) throws -> String {
2727
let doc = try SwiftSoup.parse(content)
2828

29-
guard let body = doc.body(), body.children().count > 0 else {
29+
guard let body = doc.body(), !body.children().isEmpty else {
3030
return content // Return as is
3131
}
3232

Modules/Sources/WordPressKit/JetpackScanThreat.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ public struct JetpackThreatContext {
237237
}
238238
}
239239

240-
return (highlights.count > 0) ? highlights : nil
240+
return (!highlights.isEmpty) ? highlights : nil
241241
}
242242

243243
/// Generates an NSRange from an array

0 commit comments

Comments
 (0)