Credence.Pattern.NoSortThenReverseUnfixable
(credence v0.4.1)
Copy Markdown
Readability rule: Detects the variable-mediated pattern of assigning
Enum.sort/1,2 to a variable and then calling Enum.reverse/1 on that
variable later in the same scope.
This pattern cannot be safely auto-fixed because the sorted variable may be referenced in other expressions that expect ascending order, and a correct fix would require coordinated multi-site refactoring with scope analysis.
Bad
sorted = Enum.sort(nums)
[min1, min2 | _] = sorted
[max1, max2, max3 | _] = Enum.reverse(sorted)Good
sorted = Enum.sort(nums)
[min1, min2 | _] = sorted
[max1, max2, max3 | _] = Enum.sort(nums, :desc)