Skip to content

Enable SwiftLint rule: flatmap_over_map_reduce#25529

Open
mokagio wants to merge 1 commit intotrunkfrom
mokagio/swiftlint-flatmap-over-map-reduce
Open

Enable SwiftLint rule: flatmap_over_map_reduce#25529
mokagio wants to merge 1 commit intotrunkfrom
mokagio/swiftlint-flatmap-over-map-reduce

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 5, 2026

Summary

Enables SwiftLint's flatmap_over_map_reduce rule.

The rule prefers flatMap { ... } over map { ... }.reduce([], +) for flattening nested arrays — this avoids materialising an intermediate array of arrays.

  • See commit message for the violation count and any rewrites.
  • The change is type-preserving — 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 `flatMap { ... }`
over `map { ... }.reduce([], +)` for flattening nested arrays —
this avoids materialising an intermediate array of arrays.

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 5, 2026
@mokagio mokagio added this to the 26.9 milestone May 5, 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 Number32105
VersionPR #25529
Bundle IDorg.wordpress.alpha
Commit21dcf30
Installation URL58p85nihdnof0
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 Number32105
VersionPR #25529
Bundle IDcom.jetpack.alpha
Commit21dcf30
Installation URL7bklpau3dosdg
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 01:29
Copilot AI review requested due to automatic review settings May 6, 2026 01:29
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

This PR enables SwiftLint’s flatmap_over_map_reduce rule and updates the one in-repo occurrence to match the preferred flattening pattern, avoiding the intermediate array-of-arrays allocation.

Changes:

  • Enabled the flatmap_over_map_reduce rule in .swiftlint.yml.
  • Replaced map { ... }.reduce([], +) with flatMap { ... } in GutenbergFilesAppMediaSource.getDocumentTypes(...).

Reviewed changes

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

File Description
WordPress/Classes/ViewRelated/Gutenberg/Utils/GutenbergFilesAppMediaSource.swift Updates array-flattening implementation to use flatMap per new SwiftLint rule.
.swiftlint.yml Adds flatmap_over_map_reduce to the opt-in only_rules list.

💡 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