rrrene / credo

A static code analysis tool for the Elixir language with a focus on code consistency and teaching.
http://credo-ci.org/
MIT License
4.91k stars 414 forks source link

fix: negated_is_nil when nested in guards #1096

Closed pdm-jd closed 9 months ago

pdm-jd commented 9 months ago

If a custom guard uses not is_nil(foo), the number of issues reported by Credo.Check.Refactor.NegatedIsNil increases significantly.

For instance, this would report three violations.

defguard custom_guard(value) when not is_nil(value)

def bar(foo, baz) when not is_nil(foo) and custom_guard(baz) do
end

This change ensures only a maximum of one issue per part of the guard will be reported. See the added tests for examples.

pdm-jd commented 9 months ago

Oof, https://github.com/rrrene/credo/pull/1094 beat me too it.

rrrene commented 8 months ago

@pdm-jd Still glad you took the time :+1: