Rule request: Use min() or max() instead of sorted().first or sorted().last #1932
Closed
2 tasks done
Labels
rule-request
Requests for a new rules.
New Issue Checklist
Rule Request
If this is a new rule request, please ignore all sections below this one, format
this issue's title as
Rule Request: [Rule Name]
and describe:Why should this rule be added? Share links to existing discussion about what
the community thinks about this.
First sorting a sequence and then just reading the first or last element is unnecessarily consuming memory and is much slower (
O(n log(n))
) than searching for the minimum element in a sequence (O(n)
).Provide several examples of what would and wouldn't trigger violations.
Just severity.
The rule may lead to false positives on non-sequence API where there is no min/max function. Similar to
first_where
andcontains_over_first_not_nil
this rule should be opt-in.The text was updated successfully, but these errors were encountered: