Skip to content

Enable SwiftLint rule: redundant_nil_coalescing#25533

Open
mokagio wants to merge 2 commits into
trunkfrom
mokagio/swiftlint-redundant-nil-coalescing
Open

Enable SwiftLint rule: redundant_nil_coalescing#25533
mokagio wants to merge 2 commits into
trunkfrom
mokagio/swiftlint-redundant-nil-coalescing

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 5, 2026

Summary

Enables SwiftLint's redundant_nil_coalescing rule.

The rule flags ?? <default> applied to a non-optional value, which is redundant — the right-hand side can never be reached.

  • Auto-fixed by swiftlint --fix.
  • 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

@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 Warning
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 5, 2026

🤖 Build Failure Analysis

This build has failures. Claude has analyzed them - check the build annotations for details.

@wpmobilebot wpmobilebot modified the milestones: 26.9, 27.0 May 25, 2026
@wpmobilebot
Copy link
Copy Markdown
Contributor

Version 26.9 has now entered code-freeze, so the milestone of this PR has been updated to 27.0.

@mokagio mokagio force-pushed the mokagio/swiftlint-redundant-nil-coalescing branch from 9e50779 to 84f793d Compare May 25, 2026 06:15
mokagio and others added 2 commits May 26, 2026 16:44
The `redundant_nil_coalescing` rule enabled in 356eaa5
treats `?? nil` as syntactically redundant regardless of whether
the LHS is `T?` (truly redundant) or `T??` (essential flatten).
Four sites were flattening `T??` and stopped compiling once the
rule autofix removed them.

Switch each to a form the rule doesn't trip:

- `Dictionary[key, default: nil]` on `[K: V?]` returns `V?` directly,
  avoiding the `T??` intermediate from a raw subscript.
- A `do`/`catch` around `decodeIfPresent` in `JetpackScanThreat`
  preserves "treat malformed value as absent" semantics without
  producing the `T??` that `try?` over a throwing `T?` would.

`bundle exec fastlane ios test` passes (3415 tests, 0 failures).

---

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

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@mokagio mokagio force-pushed the mokagio/swiftlint-redundant-nil-coalescing branch from 84f793d to 09850ba Compare May 26, 2026 10:06
@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 Number32347
VersionPR #25533
Bundle IDcom.jetpack.alpha
Commit09850ba
Installation URL14nc8944j1o38
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 WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number32347
VersionPR #25533
Bundle IDorg.wordpress.alpha
Commit09850ba
Installation URL7tpmtroltr60o
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 27, 2026 05:05
Copilot AI review requested due to automatic review settings May 27, 2026 05:05
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 the SwiftLint redundant_nil_coalescing opt-in rule and applies its auto-fixes across the codebase, removing ?? nil expressions that operate on already-optional values. For dictionary lookups where values are themselves optional (producing nested optionals), the fix switches to subscript(_:default:) with a nil default to preserve the single-optional result type. A semantic-equivalent rewrite of try? ... ?? nil to an explicit do/catch in JetpackScanThreat preserves the prior failure-to-nil behavior.

Changes:

  • Add redundant_nil_coalescing to .swiftlint.yml's only_rules.
  • Apply swiftlint --fix autofixes removing redundant ?? nil across app, modules, and tests.
  • Convert a try? ... ?? nil decode in JetpackScanThreat to an explicit do/catch and switch optional-valued dictionary reads to subscript(_:default: nil).

Reviewed changes

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

Show a summary per file
File Description
.swiftlint.yml Opt in to the new redundant_nil_coalescing rule.
WordPress/Classes/ViewRelated/Support/SupportTableViewController.swift Drop redundant ?? nil after optional chain.
WordPress/Classes/ViewRelated/Reader/Manage/OffsetTableViewHandler.swift Drop redundant ?? nil after Optional.map.
WordPress/Classes/ViewRelated/Reader/Detail/Views/ReaderDetailHeaderView.swift Drop redundant ?? nil from avatarURLForDisplay() assignment.
WordPress/Classes/ViewRelated/Jetpack/Jetpack Scan/JetpackScanCoordinator.swift Drop redundant ?? nil after optional chain.
WordPress/Classes/Stores/StatsPeriodStore.swift Switch nested-optional dictionary read to subscript(_:default: nil).
Tests/WordPressKitTests/WordPressKitTests/Tests/MediaLibraryTestSupport.swift Drop redundant ?? nil from optional helper call.
Tests/KeystoneTests/Tests/Features/Domains/RegisterDomainDetailsViewModelTests.swift Drop redundant ?? nil from optional casts.
Sources/WordPressData/Swift/SiteTaxonomy.swift Switch optional-valued label reads to subscript(_:default: nil).
Modules/Sources/WordPressKitModels/RemoteUser+Likes.swift Drop redundant ?? nil from optional cast.
Modules/Sources/WordPressKit/JetpackScanThreat.swift Replace try? ... ?? nil with explicit do/catch for fixable.
Modules/Sources/WordPressKit/DomainsServiceRemote.swift Drop redundant ?? nil from optional casts.
Modules/Sources/AsyncImageKit/Helpers/ImageSaliencyService.swift Switch nested-optional cache read to subscript(_:default: nil).

💡 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.

4 participants