Merged
Conversation
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>
Collaborator
Generated by 🚫 Danger |
Contributor
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 32101 | |
| Version | PR #25525 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 3086b8d | |
| Installation URL | 5ua47kbc003fo |
Contributor
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 32101 | |
| Version | PR #25525 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 3086b8d | |
| Installation URL | 1iou3utslj528 |
Contributor
There was a problem hiding this comment.
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_wherein.swiftlint.yml. - Refactored multiple production call sites from
filter(...).firsttofirst(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 |
crazytonyli
approved these changes
May 6, 2026
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
Enables SwiftLint's
first_whererule.The rule prefers
xs.first(where: { ... })overxs.filter { ... }.first, which is a performance and clarity win (avoids materialising an intermediate array).Element?→Element?) — local build deferred to CI.Part of the Orchard SwiftLint rollout campaign.
Test plan
swiftlint lint --strict --no-cacheis clean against the rule.🤖 Generated with Claude Code