Skip to content

Enable SwiftLint rule: contains_over_range_nil_comparison#25524

Open
mokagio wants to merge 2 commits intotrunkfrom
mokagio/swiftlint-contains-over-range-nil-comparison
Open

Enable SwiftLint rule: contains_over_range_nil_comparison#25524
mokagio wants to merge 2 commits intotrunkfrom
mokagio/swiftlint-contains-over-range-nil-comparison

Conversation

@mokagio
Copy link
Copy Markdown
Contributor

@mokagio mokagio commented May 4, 2026

Summary

Enables SwiftLint's contains_over_range_nil_comparison rule.

The rule prefers s.contains(...) over s.range(of:) != nil (and == nil), which is a clarity win.

  • See commit message for the violation count and any rewrites.
  • The change is type-preserving (Bool→Bool) — 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
`s.contains(...)` over `s.range(of:) != nil`
(and the `== nil` inverse), which is a 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
@wpmobilebot
Copy link
Copy Markdown
Contributor

wpmobilebot commented May 4, 2026

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 Number32165
VersionPR #25524
Bundle IDcom.jetpack.alpha
Commit1fe344f
Installation URL1is1d4r759opo
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

wpmobilebot commented May 4, 2026

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 Number32165
VersionPR #25524
Bundle IDorg.wordpress.alpha
Commit1fe344f
Installation URL4b7do8eop5sho
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 7, 2026 01:02
Copilot AI review requested due to automatic review settings May 7, 2026 01:02
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 contains_over_range_nil_comparison opt-in rule and updates existing code to prefer String.contains(...) over range(of:) != nil / == nil, improving clarity while preserving boolean semantics.

Changes:

  • Adds contains_over_range_nil_comparison to .swiftlint.yml only_rules.
  • Refactors URL/request matching stubs in test helpers to use contains.
  • Updates a few production code paths to use contains for substring checks.

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
Tests/WordPressKitTests/WordPressKitTests/Tests/RemoteTestCase.swift Replaces range(of:) != nil endpoint matching with contains(...) ?? false in stub helpers.
Tests/KeystoneTests/Tests/Services/NotificationSettingsServiceTests.swift Updates stub condition to use contains(...) ?? false for endpoint matching.
Tests/KeystoneTests/Helpers/OHHTTPStubs+Helpers.swift Updates shared stubbing helper to use contains(...) ?? false.
Sources/WordPressAuthenticator/Helpers/Authenticator/WordPressAuthenticator.swift Replaces range(of:) != nil with contains when normalizing http:// to https://.
Modules/Sources/WordPressKit/WordPressOrgXMLRPCValidator.swift Replaces range(of:) != nil checks with contains when detecting specific redirect HTML markers.
.swiftlint.yml Enables the contains_over_range_nil_comparison SwiftLint rule.

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

Comment thread Tests/KeystoneTests/Tests/Services/NotificationSettingsServiceTests.swift Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@mokagio mokagio enabled auto-merge May 7, 2026 04:45
@wpmobilebot
Copy link
Copy Markdown
Contributor

🤖 Build Failure Analysis

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

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