Elixir: Formatter is indenting more than necessary

Created on 4 Nov 2017  路  10Comments  路  Source: elixir-lang/elixir

  @callback init(args :: term) ::
              {
                  :ok,
                  {
                    sup_flags(),
                    [:supervisor.child_spec()]
                  }
                }
              | :ignore
Elixir Intermediate Formatter

All 10 comments

I was looking into helping with this issue, but I'm not sure what the expected indent should be. Could you provide how you would expect this snippet to be formatted?

    @callback init(args :: term) ::
                {
                  :ok,
                  {
                    sup_flags(),
                    [:supervisor.child_spec()]
                  }
                }
                | :ignore

Does the formatter turn the following into the above?

@callback init(args :: term) :: {:ok, {sup_flags(), [:supervisor.child_spec()]}} | :ignore

I'm trying to get started on this but am not sure what section of the Code.Formatter or even Inspect.Algebra I should look in. I'll come back to it and try to work through it but thought someone might be kind enough to point me in the right direction.

@rcdilorenzo I think this will be one of the bugs where it takes you 12 hours to find the fix and 2 minutes to fix it. It is definitely a bug in the Code.Formatter though. Either in the tuple or in the operator rendering.

Honestly, I would strongly prefer:

@callback init(args :: term) ::
  {:ok, {sup_flags(), [:supervisor.child_spec()] } }
  | :ignore

So that each type is on its own line. The formatted version supplied isn't that readable. I would say drop this and move to a more readable version, then one doesn't have to spend 12 hours find the fix. Just a few hours building a nicer implementation.

Folks, the fact the snippet above is broken does not mean your code will be formatted like that. In fact, the whole thing fits on a single line, so the formatter wouldn't even introduce a line break. The snippet above is just an example that triggered the bug post formatting. If it didn't happen in this case, it would have happened elsewhere when a break was actually necessary. If in doubt, try the formatter out.

Maybe I missed something but why was this issue closed? Is there another one that covers it?

@rcdilorenzo apparently fixed in commit ca75fc6 :)

Ah, sorry. I couldn't see that on mobile. :-)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sashaafm picture sashaafm  路  3Comments

lukaszsamson picture lukaszsamson  路  3Comments

DEvil0000 picture DEvil0000  路  3Comments

Irio picture Irio  路  3Comments

whitepaperclip picture whitepaperclip  路  3Comments