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.
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. |
There was a problem hiding this comment.
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. |
Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyNSGeometryFunctionsRule.swift
Outdated
Show resolved
Hide resolved
1e762d8 to
1b0566a
Compare
39c9d97 to
2a3b161
Compare
2a3b161 to
714ff0a
Compare
4fc238b to
4a4e1c0
Compare
No description provided.