-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add some more rule rationales #6308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add some more rule rationales #6308
Conversation
Here's an example of your CHANGELOG entry: * Add some more rule rationales.
[mildm8nnered](https://github.com/mildm8nnered)
[#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)note: There are two invisible spaces after the entry's text. Generated by 🚫 Danger |
There was a problem hiding this 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 adds rationale documentation to several SwiftLint rules, explaining why certain coding patterns are preferred over others. The rationales primarily focus on performance benefits and API modernization.
Key Changes
- Added performance-related rationales to five rules that recommend using more efficient alternatives
- Added API modernization rationale to the legacy NSGeometry functions rule
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| EmptyCountRule.swift | Added rationale explaining O(1) vs O(n) performance difference between isEmpty and count |
| ContainsOverRangeNilComparisonRule.swift | Added rationale explaining early exit benefits of contains over range(of:) |
| ContainsOverFirstNotNilRule.swift | Added rationale explaining early exit benefits of contains over first(where:) |
| ContainsOverFilterIsEmptyRule.swift | Added rationale explaining early exit benefits of contains over filter |
| ContainsOverFilterCountRule.swift | Added rationale explaining early exit benefits of contains over filter |
| LegacyNSGeometryFunctionsRule.swift | Added rationale explaining modern API benefits and cross-platform support |
Source/SwiftLintBuiltInRules/Rules/Performance/ContainsOverRangeNilComparisonRule.swift
Outdated
Show resolved
Hide resolved
| `filter` always needs to scan the entire collection, whereas `contains` can exit early as | ||
| soon as a match is found. |
Copilot
AI
Oct 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rationale incorrectly mentions filter when it should refer to first(where:) and firstIndex(where:). The rule is about these methods, not filter. Update the rationale to correctly explain that first(where:) and firstIndex(where:) already support early exit, but using contains is more semantically clear when you only need to check for existence.
| `filter` always needs to scan the entire collection, whereas `contains` can exit early as | |
| soon as a match is found. | |
| While `first(where:)` and `firstIndex(where:)` already support early exit, using `contains` is more semantically clear when you only need to check for the existence of an element matching a predicate. |
No description provided.