Credence.Rule.NoSortThenAt (credence v0.3.2)

Copy Markdown

Performance rule (fixable subset): Detects Enum.sort |> Enum.at(index) where the index is a literal 0 or -1. These can be safely replaced with Enum.min/1 or Enum.max/1, avoiding the O(n log n) sort entirely.

Bad (fixable)

Enum.sort(nums, :desc) |> Enum.at(0)
Enum.at(Enum.sort(nums), 0)
Enum.sort(nums, :asc) |> Enum.at(-1)

Good

Enum.max(nums)
Enum.min(nums)
Enum.max(nums)

Not auto-fixed (delegated to LLM)

Variable indices such as Enum.sort(nums) |> Enum.at(k - 1) or custom comparators are still flagged by check/2 but require human/LLM judgement to rewrite.