Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ let package = Package(
],
swiftSettings: swiftFeatures + strictConcurrency
),
.testTarget(
.target(
name: "TestHelpers",
dependencies: [
"SwiftLintFramework"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ struct LegacyNSGeometryFunctionsRule: Rule {
identifier: "legacy_nsgeometry_functions",
name: "Legacy NSGeometry Functions",
description: "Struct extension properties and methods are preferred over legacy functions",
rationale: """
The CGRect extension properties are a more modern API (and are available on NSRect, which
is a typealias for CGRect), and are supported on all Swift platforms.

The legacy functions are only supported on macOS and Mac Catalyst.
""",
kind: .idiomatic,
nonTriggeringExamples: [
Example("rect.width"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
identifier: "contains_over_filter_count",
name: "Contains over Filter Count",
description: "Prefer `contains` over comparing `filter(where:).count` to 0",
rationale: """
`filter` always needs to scan the entire collection, whereas `contains` can exit early as

Check failure on line 12 in Source/SwiftLintBuiltInRules/Rules/Performance/ContainsOverFilterCountRule.swift

View workflow job for this annotation

GitHub Actions / Swift

Lines should not have trailing whitespace (trailing_whitespace)
soon as a match is found.
""",
kind: .performance,
nonTriggeringExamples: [">", "==", "!="].flatMap { operation in
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
identifier: "contains_over_filter_is_empty",
name: "Contains over Filter is Empty",
description: "Prefer `contains` over using `filter(where:).isEmpty`",
rationale: """
`filter` always needs to scan the entire collection, whereas `contains` can exit early as

Check failure on line 12 in Source/SwiftLintBuiltInRules/Rules/Performance/ContainsOverFilterIsEmptyRule.swift

View workflow job for this annotation

GitHub Actions / Swift

Lines should not have trailing whitespace (trailing_whitespace)
soon as a match is found.
""",
kind: .performance,
nonTriggeringExamples: [">", "==", "!="].flatMap { operation in
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
identifier: "contains_over_first_not_nil",
name: "Contains over First not Nil",
description: "Prefer `contains` over `first(where:) != nil` and `firstIndex(where:) != nil`.",
rationale: """
`filter` always needs to scan the entire collection, whereas `contains` can exit early as

Check failure on line 12 in Source/SwiftLintBuiltInRules/Rules/Performance/ContainsOverFirstNotNilRule.swift

View workflow job for this annotation

GitHub Actions / Swift

Lines should not have trailing whitespace (trailing_whitespace)
soon as a match is found.
Comment on lines +12 to +13
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
`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.

Copilot uses AI. Check for mistakes.
""",
kind: .performance,
nonTriggeringExamples: ["first", "firstIndex"].flatMap { method in
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ struct EmptyCountRule: Rule {
identifier: "empty_count",
name: "Empty Count",
description: "Prefer checking `isEmpty` over comparing `count` to zero",
rationale: """
For collections that do not conform to `RandomAccessCollection`, `count` is an O(n) operation,
whereas `isEmpty` is O(1).
""",
kind: .performance,
nonTriggeringExamples: [
Example("var count = 0"),
Expand Down
Loading