3 ms·
Some extra stuff I've been working on to supplement the the formatter in your workflow a bit: Pre commit hook: https://github.com/jasongoodwin/elixir-mix-forma
by ninjakeyboard 9y ago
Some extra stuff I've been working on to supplement the the formatter in your workflow a bit:
Pre commit hook:
https://github.com/jasongoodwin/elixir-mix-format-pre-commit-hook https://github.com/jasongoodwin/elixir-mix-format-pre-commit...
Emacs format current file:
https://github.com/jasongoodwin/emacs-elixir-formatter https://github.com/jasongoodwin/emacs-elixir-formatter
Generally the formatter is good, but we've noticed a couple cases where it would be nice to override
EG:
it would be nice to have the join and on statements on the same line so you can see as the reader what relates to what
u in Db.User,
distinct: u.id,
join: c in Db.Comment,
on: u.id == c.user_id,
join: p in Db.Profile,
on: u.profile_id == u.id,
join: x in Db.SomethingElse,
on: x.profile_id == u.id,
join: y in Db.AnotherThing,
on: y.profile_id == u.id,
...
I can see why it's like that, but it would be nice to be able to override it.
Also the formatter requires () so you end up with ecto code differing from the styles recommend in the docs
schema "thingy" do
field(:name, :string)
field(:abbreviation, :string)
end
instead of
schema "thingy" do
field :name, :string
field :abbreviation, :string
end
Anyway, still useful and good for the team.
- _asummers 9y agoEcto can export a .formatter.exs file that says you don't need parens for those calls.
- rehemiau 9y agoBut that would apply ecto's style across whole codebase and for some function names this wouldn't be handy (see https://groups.google.com/d/msg/elixir-lang-core/xTduV3KZvfY/5lDAu5zlDQAJ https://groups.google.com/d/msg/elixir-lang-core/xTduV3KZvfY... )
- jurre 9y ago> it would be nice to override One of the big advantages I have experienced from the Golang formatter is that you cannot configure it, period. This took me a little bit off getting over myself, but eventually the fact that every single Golang codebase adheres to these rules is so nice. Plus you don't have to think about it, ever. In this case I think it would be best if Ecto just recommends the new default style in their docs.
- ninjakeyboard 9y agoThat's fair - thanks for the comment. It makes sense - then there are no opinions or variation so "this is the way" and all code looks like that.
- rkangel 9y ago> Emacs format current file: https://github.com/jasongoodwin/emacs-elixir-formatter https://github.com/jasongoodwin/emacs-elixir-formatter Would it be possible to have that be trivially configurable to hook into save-buffer? That would seem to be the cleanest way to use it.
- ninjakeyboard 9y agoI was thinking that too and had actually created a ticket for it https://github.com/jasongoodwin/emacs-elixir-formatter/issues/1 https://github.com/jasongoodwin/emacs-elixir-formatter/issue... . I'm relatively new to elisp and this was a good way to jump in a little deeper - I'll try to tackle this soon. Publish it somewhere etc. I save on navigate away so that would be ideal for me too. I'll try to make that change shortly. Or feel free to make a pr.