Enable SwiftLint rule: contains_over_range_nil_comparison#25524
Open
Enable SwiftLint rule: contains_over_range_nil_comparison#25524
Conversation
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>
Contributor
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 32165 | |
| Version | PR #25524 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | 1fe344f | |
| Installation URL | 1is1d4r759opo |
Contributor
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 32165 | |
| Version | PR #25524 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | 1fe344f | |
| Installation URL | 4b7do8eop5sho |
Contributor
There was a problem hiding this comment.
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_comparisonto.swiftlint.ymlonly_rules. - Refactors URL/request matching stubs in test helpers to use
contains. - Updates a few production code paths to use
containsfor 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.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Contributor
🤖 Build Failure AnalysisThis build has failures. Claude has analyzed them - check the build annotations for details. |
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
contains_over_range_nil_comparisonrule.The rule prefers
s.contains(...)overs.range(of:) != nil(and== nil), which is a clarity win.Part of the Orchard SwiftLint rollout campaign.
Test plan
swiftlint lint --strict --no-cacheis clean against the rule.🤖 Generated with Claude Code