credo
credo copied to clipboard
Credo.Check.Warning.ExpensiveEmptyEnumCheck misses some cases
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
Thx for reporting! :+1:
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! 👍