Skip to content

Enable SwiftLint rule: first_where#25525

Merged
mokagio merged 1 commit intotrunkfrom
mokagio/swiftlint-first-where
May 6, 2026
Merged

Enable SwiftLint rule: first_where#25525
mokagio merged 1 commit intotrunkfrom
mokagio/swiftlint-first-where

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 4, 2026

Summary

Enables SwiftLint's first_where rule.

The rule prefers xs.first(where: { ... }) over xs.filter { ... }.first, which is a performance and clarity win (avoids materialising an intermediate array).

  • See commit message for the violation count and any rewrites.
  • The change is type-preserving (Element?Element?) — 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`. The rule prefers
`xs.first(where: { ... })` over `xs.filter { ... }.first`,
which is a performance and clarity win.

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 Number32101
VersionPR #25525
Bundle IDorg.wordpress.alpha
Commit3086b8d
Installation URL5ua47kbc003fo
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 Number32101
VersionPR #25525
Bundle IDcom.jetpack.alpha
Commit3086b8d
Installation URL1iou3utslj528
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 6, 2026 05:19
Copilot AI review requested due to automatic review settings May 6, 2026 05:19
@mokagio mokagio enabled auto-merge May 6, 2026 05:19
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 first_where rule and updates existing call sites to prefer first(where:) over filter { ... }.first, reducing intermediate allocations and improving clarity across app and test code.

Changes:

  • Enabled first_where in .swiftlint.yml.
  • Refactored multiple production call sites from filter(...).first to first(where:).
  • Updated affected unit tests/utilities to match the new preferred pattern.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
WordPress/WordPressShareExtension/Sources/UI/ShareCategoriesPickerViewController.swift Replaced filter(...).first with first(where:) when selecting the default category.
WordPress/WordPressShareExtension/Sources/Services/AppExtensionsService.swift Switched site lookup to first(where:) before checking upload authorization.
WordPress/Classes/ViewRelated/Gutenberg/Processors/GutenbergImgUploadProcessor.swift Uses first(where:) to find the image ID class attribute prefix.
WordPress/Classes/ViewRelated/Gutenberg/Processors/GutenbergGalleryUploadProcessor.swift Uses first(where:) to find the image ID class attribute prefix in gallery processing.
WordPress/Classes/ViewRelated/Domains/Domain registration/RegisterDomainDetails/ViewModel/RegisterDomainDetailsViewModel.swift Uses first(where:) to map country/state codes to display names.
WordPress/Classes/Utility/Universal Links/Migration/MigrationDeepLinkRouter.swift Uses first(where:) for route lookup by deep link path.
WordPress/Classes/Services/JetpackScanService.swift Uses first(where:) when mapping fix status items to threats.
Tests/KeystoneTests/Tests/Services/NotificationSettingsServiceTests.swift Updated stream selection in tests to use first(where:).
Tests/KeystoneTests/Tests/Features/Notifications/NotificationUtility.swift Updated block selection to use first(where:) in test utility.
Tests/KeystoneTests/Tests/Extensions/URLHelpersTests.swift Updated query item lookup to use first(where:).
Modules/Sources/WordPressKit/PlanServiceRemote.swift Updated metadata lookup to use first(where:) in async pipeline.
Modules/Sources/FormattableContentKit/FormattableContent/FormattableContent.swift Updated action lookup to use first(where:).
.swiftlint.yml Enabled the first_where rule under only_rules.

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

// Add the default site to the selected list if it's empty.
var selected = categoryInfo.selectedCategories ?? []
if selected.isEmpty, let defaultCategory = categoryInfo.allCategories?.filter({$0.categoryID == categoryInfo.defaultCategoryID }).first {
if selected.isEmpty, let defaultCategory = categoryInfo.allCategories?.first(where: {$0.categoryID == categoryInfo.defaultCategoryID }) {
func isAuthorizedToUploadMedia(in sites: [RemoteBlog], for selectedSiteID: Int) -> Bool {
let siteID = NSNumber(value: selectedSiteID)
guard let isAuthorizedToUploadFiles = sites.filter({$0.blogID == siteID}).first?.isUploadingFilesAllowed() else {
guard let isAuthorizedToUploadFiles = sites.first(where: {$0.blogID == siteID})?.isUploadingFilesAllowed() else {
Comment on lines 374 to +377
section.rows[safe: addressSectionIndexHelper.stateIndex]?.editableRow?.idValue = domainContactInformation.state
section.rows[safe: addressSectionIndexHelper.stateIndex]?.editableRow?.value = states?.filter {
section.rows[safe: addressSectionIndexHelper.stateIndex]?.editableRow?.value = states?.first(where: {
return $0.code == domainContactInformation.state
}.first?.name
})?.name
Comment on lines 393 to +396
section.rows[safe: CellIndex.ContactInformation.country.rawValue]?.editableRow?.idValue = domainContactInformation.countryCode
section.rows[safe: CellIndex.ContactInformation.country.rawValue]?.editableRow?.value = countries?.filter {
section.rows[safe: CellIndex.ContactInformation.country.rawValue]?.editableRow?.value = countries?.first(where: {
return $0.code == domainContactInformation.countryCode
}.first?.name
})?.name
@mokagio mokagio added this pull request to the merge queue May 6, 2026
Merged via the queue into trunk with commit 61c1839 May 6, 2026
30 checks passed
@mokagio mokagio deleted the mokagio/swiftlint-first-where branch May 6, 2026 10:08
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