-
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?
Changes from 3 commits
0745d06
911d99e
97fd3fc
54d674e
a1067bc
1e762d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -8,6 +8,10 @@ struct ContainsOverFirstNotNilRule: Rule { | |||||||
| 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 | ||||||||
| soon as a match is found. | ||||||||
|
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. | |
| 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. |
Uh oh!
There was an error while loading. Please reload this page.