WhatsApp / erlfmt

An automated code formatter for Erlang
Apache License 2.0
412 stars 52 forks source link

preserve spec alternative #275

Closed awalterschulze closed 3 years ago

awalterschulze commented 3 years ago

I decided to make clause_to_algebra a special case for spec_clause using maybe_force_breaks The reason to try this alternative is to avoid cases such as:

-spec use_credit(
    store:id(),
    decimal:decimal(),
    binary() | null,
    credit | {refund | dispute, binary()},
    binary() | null
) ->
    ok.
use_credit(...

which is really popular in the whatsapp code base.

This version preserves the newline after spec, but does not force it when the function parameters for the spec breaks.

The reason I made spec_clause a special case is that for other clause types there is a conflict with the break behaviour in clauses https://github.com/whatsapp/erlfmt#in-clauses where breaking the first one should result in breaking all clauses.