lpil / dogma

:closed_lock_with_key: A code style linter for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

False error with ComparisonToBoolean and Ecto query?

jlee0831 opened this issue · comments

I created a function on an Ecto model as follows:

  def not_foo?(query \\ SomeModel) do
    from r in query,
    where: r.foo == false
  end

This caused dogma to fail with: ComparisonToBoolean: Comparison to a boolean is pointless. This seems to be incorrect, although perhaps theres another way of writing that query that I don't understand yet.

Hm. In Ecto's DSL it isn't pointless it seems. Perhaps we can try and detect if we're in this DSL somehow.

It seems there is an alternative syntax, although most examples I've seen use the original syntax above. Anyhow, this seems like it is a reasonable workaround for my situation:

  def not_foo?(query \\ SomeModel) do
    from r in query,
    where: not(r.foo)
  end