credo icon indicating copy to clipboard operation
credo copied to clipboard

Credo.Check.Warning.ExpensiveEmptyEnumCheck misses some cases

Open idkCpp opened this issue 11 months ago • 2 comments

Environment

  • Credo version (mix credo -v): 1.7.11
  • Erlang/Elixir version (elixir -v): Elixir 1.18.2 (compiled with Erlang/OTP 27)
  • Operating system: Arch-Linux

What were you trying to do?

defmodule Test do
  @moduledoc false

  def test do
    enum = []

    if length(enum) != 0 do
      :error
    end

    if length(enum) > 0 do
      :error
    end

    if length(enum) !== 0 do
      :error
    end
  end
end

Expected outcome

I would expect that the negated conditionals will also be caught by the ExpensiveEmptyEnumCheck. Also since the length of a list cannot be negative, > 0 is functionally the same with != 0 and should therefore also be considered an "expensive empty enum check".

Actual outcome

found no issues

idkCpp avatar Mar 12 '25 15:03 idkCpp

Thx for reporting! :+1:

rrrene avatar Mar 18 '25 04:03 rrrene

Thanks for reporting this 😀 It should be fixed on master (sorry for the long wait 😳).

You can try this by setting the Credo dep to

{:credo, github: "rrrene/credo"}

Please report back if your issue is solved! 👍

rrrene avatar Nov 12 '25 19:11 rrrene