To me this feels like a good use of credo or similar linter, not something that the Elixir compiler itself should warn about. `assert %{} = x` isn't the most idiomatic way to match but it isn't incoherent or invalid, just probably not best practice.
On Tuesday, August 16, 2022 at 5:55:09 AM UTC-4 woj...@wojtekmach.pl wrote: > Hi, > > Developers can easily shoot themselves in the foot if they write: > > assert %{} = x > > but really what they meant was to write: > > assert %{} == x > > The mistake is writing `=` instead of `==`, an easy one to make. The > difference is of course that the former will succeed on _any_ map and the > latter will _only_ succeed on an _empty_ map. > > I'd like to propose ExUnit warn on `assert %{} = x` and tell users to > instead write `assert is_map(x)`. > > Thoughts? > > P.S. In my projects I'd either write `assert actual == expected` OR > `assert expected = actual` and never `assert expected == actual` exactly > because it is easy to make the mistake. Maybe there is a Credo check to > enforce such style. > -- You received this message because you are subscribed to the Google Groups "elixir-lang-core" group. To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-core+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/b70a4bb4-14d4-4ea3-8b49-45b408abf750n%40googlegroups.com.