elixir-editors / elixir-editors/emacs-elixir

elixir-format does not respect locals_without_parens in .formatter.exs

Open
#428 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Emacs Lisp
Stars
454
Forks
93
PR merge metrics
No merged PRs in 30d

Description

With the following .formatter.exs and files, `mix format $file` respects `locals_without_parens`, whereas elixir-format does not

`.formatter.exs`
```elixir
# Used by "mix format"
[
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"],
locals_without_parens: [
defroute: 2
]
]
```

`lib/pea_bb/bbs/router.ex`
```elixir
defmodule PeaBB.BBS.Router do
import PeaBB.Macro.Route

defroute "/", PeaBB.BBS.Menu
defroute "/board", PeaBB.BBS.Board
defroute "/blog", PeaBB.BBS.Blog

# 404 route not found
def route(_), do: {:error, "Route does not exist."}
end
```

`lib/pea_bb/macro/route.ex`
```elixir
defmodule PeaBB.Macro.Route do
defmacro defroute(path, module) do
with path <- String.split(path, "/", [:trim]) do
quote do
def route(unquote(gen_match_statement(path))),
do:
{unquote(module),
unquote(
case path do
[] -> quote do: []
_ -> quote do: t
end
)}
end
end
end

defp gen_match_statement([head | tail]) do
quote do
[unquote(head) | unquote(gen_match_statement(tail))]
end
end

defp gen_match_statement([]),
do: quote(do: t)
end
```

(I doubt the last file is important, but I included it for completeness sake given that these files have no external dependencies other than the existence of the modules being routed to)

when elixir-format is run, `lib/pea_bb/bbs/router.ex` is changed to
```elixir
defmodule PeaBB.BBS.Router do
import PeaBB.Macro.Route

defroute("/", PeaBB.BBS.Menu)
defroute("/board", PeaBB.BBS.Board)
defroute("/blog", PeaBB.BBS.Blog)

# 404 route not found
def route(_), do: {:error, "Route does not exist."}
end
```

this is not the case for when `mix format` is run

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.