Skip to content

Enable SwiftLint rule: contains_over_first_not_nil#25523

Open
mokagio wants to merge 1 commit intotrunkfrom
mokagio/swiftlint-contains-over-first-not-nil
Open

Enable SwiftLint rule: contains_over_first_not_nil#25523
mokagio wants to merge 1 commit intotrunkfrom
mokagio/swiftlint-contains-over-first-not-nil

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 4, 2026

Summary

Enables SwiftLint's contains_over_first_not_nil rule and rewrites the 13 existing violations.

The rule prefers xs.contains { ... } over xs.first(where: { ... }) != nil (and the firstIndex variant), which is a performance and clarity win.

  • 13 violations fixed across 9 files.
  • 0 suppressions.
  • Some inverted forms (first { } == nil) were rewritten with !contains / allSatisfy depending on what reads cleanest.
  • The rewrite is type-preserving (Bool→Bool) — local build deferred to CI.

Part of the Orchard SwiftLint rollout campaign.

Test plan

  • CI build is green.
  • swiftlint lint --strict --no-cache is clean against the rule.

🤖 Generated with Claude Code

Adds the rule to `only_rules` and rewrites the 13 existing violations:

- `xs.first(where: { ... }) != nil` → `xs.contains(where: { ... })`
- `xs.first { ... } == nil` patterns rewritten using the equivalent
  `!contains` / `allSatisfy` form, depending on what reads cleanest.

The rewrite is type-preserving (Bool→Bool) — local build deferred to CI.

Part of the Orchard SwiftLint rollout campaign.

---

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

Co-Authored-By: Claude Code Opus 4.7 <noreply@anthropic.com>
@mokagio mokagio self-assigned this May 4, 2026
@mokagio mokagio added this to the 26.9 milestone May 4, 2026
@dangermattic
Copy link
Copy Markdown
Collaborator

1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@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 Number32099
VersionPR #25523
Bundle IDorg.wordpress.alpha
Commit86157be
Installation URL77jeinuoimd60
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 Number32099
VersionPR #25523
Bundle IDcom.jetpack.alpha
Commit86157be
Installation URL0nqsd7tkl6tjg
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@mokagio mokagio marked this pull request as ready for review May 8, 2026 05:43
Copilot AI review requested due to automatic review settings May 8, 2026 05:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Enables SwiftLint’s contains_over_first_not_nil opt-in rule and updates existing boolean checks to use contains(where:) (or equivalent !contains / allSatisfy) instead of first(where:) != nil / == nil, improving clarity and avoiding intermediate optional handling across the app and data layers.

Changes:

  • Enabled the contains_over_first_not_nil SwiftLint rule in .swiftlint.yml.
  • Replaced first(where:) != nil patterns with contains(where:) across multiple UI and store files.
  • Rewrote inverted forms (first(...) == nil) to !contains / allSatisfy in a few status-aggregation helpers.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.swiftlint.yml Opts into contains_over_first_not_nil to enforce the preferred pattern moving forward.
WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift Uses contains(where:) for Automattic email detection.
WordPress/Classes/ViewRelated/Stats/Insights/TabbedTotalsCell.swift Uses !contains(where:) to determine whether any tab has data.
WordPress/Classes/ViewRelated/Notifications/Controllers/NotificationsViewController/NotificationsViewController.swift Uses contains(where:) to enable/disable “Mark All As Read”.
WordPress/Classes/Stores/StatsStore+Cache.swift Uses contains(where:) to determine whether any requested type has cached data.
WordPress/Classes/Stores/StatsRevampStore.swift Uses contains(where:) in fetching status aggregation logic.
WordPress/Classes/Stores/StatsPeriodStore.swift Uses allSatisfy for “none loading” / “all error” status checks.
WordPress/Classes/Stores/StatsInsightsStore.swift Uses contains(where:) (and !contains) on reflected status lists for fetching state checks.
WordPress/Classes/Extensions/NSFetchedResultsController+Helpers.swift Uses contains(where:) on sections to determine emptiness.
Sources/WordPressData/Swift/AbstractPost.swift Uses contains(where:) to detect permanently failed media.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants