You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Similar to contains_over_first_not_nil (#1846) but for strings
Why should this rule be added? It’s more idiomatic to ask whether the collection contains the element. Checking whether the range of the substring is nil is a more Obj-C way of doing it (e.g. with range.location == NSNotFound)
Provide several examples of what would and wouldn't trigger violations.
Triggering:
if items.range(of: item)!=nil{// items contains item}
if items.range(of: item)==nil{// notice the negation of the previous example// items does not contain item}
Not triggering:
if item.contains(item){// items contains item}
if !items.contains(item){// notice the negation of the previous example// items does not contain item}
Should the rule be configurable, if so what parameters should be configurable? I don’t think it needs to be configurable.
Should the rule be opt-in or enabled by default? Why? I think it should be on by default. It’s always clearer, in my opinion, to express your intent in checking containment, rather than grabbing the index and checking if it’s nil. Plus, it saves on the calculation and storage allocation for the range, which isn’t much, but is probably more than a Bool.
The text was updated successfully, but these errors were encountered:
ZevEisenberg
changed the title
Rule request: use contains() instead of index(of:) != nil
Rule request: use contains() instead of range(of:) != nil
Jun 4, 2019
New Issue Checklist
New rule request
Similar to
contains_over_first_not_nil
(#1846) but for stringsrange.location == NSNotFound
)Triggering:
Not triggering:
Bool
.The text was updated successfully, but these errors were encountered: