lpil / dogma

:closed_lock_with_key: A code style linter for Elixir
Other
471 stars 52 forks source link

False error with ComparisonToBoolean and Ecto query? #236

Closed jlee0831 closed 6 years ago

jlee0831 commented 7 years ago

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.

lpil commented 7 years ago

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

jlee0831 commented 7 years ago

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