devonestes / assertions

Helpful assertions for ExUnit
MIT License
143 stars 29 forks source link

Create a .formatter.exs to assert functions #16

Closed sezaru closed 3 years ago

sezaru commented 4 years ago

Hello, by default build-in assert functions doesn't require parenthesis when using then, so basically you can write this:

assert :bla == :bla

instead of

assert(:bla == :bla)

Since your library adds new assert functions, I think it would be nice that they don't require parenthesis too (note that when I say don't require, I mean that the formatter doesn't add them automatically).

To do that, you just need to add a .formatter.exs file to the library specifying the functions that doesn't need parenthesis, for example:

locals_without_parens = [
  assert_lists_equal: 2
]

[
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
  locals_without_parens: locals_without_parens,
  export: [
    locals_without_parens: locals_without_parens
  ]
]

Basically you only need to add the other assert functions to locals_without_parens variable.

With that in place, a user of your library just need to add assertions to its import_deps property of their project .formatter.exs file:

[
  inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
  import_deps: [:assertions, :typed_struct]
]
devonestes commented 4 years ago

Yeah, that seems ok. Want to send a PR?