Skip to content

Enable SwiftLint rule: redundant_nil_coalescing#25533

Draft
mokagio wants to merge 2 commits intotrunkfrom
mokagio/swiftlint-redundant-nil-coalescing
Draft

Enable SwiftLint rule: redundant_nil_coalescing#25533
mokagio wants to merge 2 commits intotrunkfrom
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

Adds the rule to `only_rules`. SwiftLint --fix removed redundant
`?? <value>` operators applied to non-optional expressions.

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

…ening

`swiftlint --fix` removed `?? nil` from expressions where the LHS
was actually a double-optional (`String??`, `CGRect??`, etc.) —
typically from `dict[key]` on a `[K: V?]` dictionary or `.map`
on `Optional<T>` returning `Optional<U>`. The original `?? nil`
flattened the result to a single optional; without it the call
sites get a type error.

For each broken call site: either rewrite to use `flatMap` (when
that produces a clean single-optional) or restore the `?? nil`
with a `swiftlint:disable:next redundant_nil_coalescing`
suppression. The rule's autofix should arguably check for double
optionals before stripping; until it does, this gives a working
build.

---

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

Co-Authored-By: Claude Code Opus 4.7 <noreply@anthropic.com>
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.

3 participants