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
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 @@ struct ContainsOverFilterCountRule: Rule {
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
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 @@ struct ContainsOverFilterIsEmptyRule: Rule {
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
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 @@ -11,6 +11,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