Add some more rule rationales by mildm8nnered · Pull Request #6308 · realm/SwiftLint · GitHub
Skip to content

Add some more rule rationales#6308

Draft
mildm8nnered wants to merge 8 commits intorealm:mainfrom
mildm8nnered:mildm8nnered-add-more-rationales
Draft

Add some more rule rationales#6308
mildm8nnered wants to merge 8 commits intorealm:mainfrom
mildm8nnered:mildm8nnered-add-more-rationales

Conversation

@mildm8nnered
Copy link
Copy Markdown
Collaborator

No description provided.

@mildm8nnered mildm8nnered requested a review from Copilot October 17, 2025 10:46
@SwiftLintBot
Copy link
Copy Markdown

SwiftLintBot commented Oct 17, 2025

Copy link
Copy Markdown

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

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

Comment on lines +12 to +13
`filter` always needs to scan the entire collection, whereas `contains` can exit early as
soon as a match is found.
Copy link

Copilot AI Oct 17, 2025

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.

Suggested change

Copilot uses AI. Check for mistakes.
Comment thread Source/SwiftLintBuiltInRules/Rules/Idiomatic/LegacyNSGeometryFunctionsRule.swift Outdated
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-more-rationales branch from 1e762d8 to 1b0566a Compare November 28, 2025 14:14
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-more-rationales branch from 39c9d97 to 2a3b161 Compare December 13, 2025 13:40
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-more-rationales branch from 2a3b161 to 714ff0a Compare December 25, 2025 13:00
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-more-rationales branch from 4fc238b to 4a4e1c0 Compare January 23, 2026 00:44
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-add-more-rationales branch from 4a4e1c0 to 70f6495 Compare April 10, 2026 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants