We have been working on a Formatter to format Heex templates. The idea is to have a similar experience as we do when formatting Elixir code :).
Please, we’d love if you try it out and let us know any feedback you have. In the repo, you can find the instructions on how to install and use it and, here you can see how it is supposed to format.
Friends, this library made my vscode setup leaner ( I was using beautify and more extensions earlier.) and @feliperenan has been very responsive to attend to my queries. A big applause.
What is your Elixir and Phoenix.LiveView versions? Do you also have a full stacktrace? I am wondering if it is trying to run the Elixir formatter on that .heex file.
I’m not sure if that works on Elixir 1.12 since format plugins are a thing only after Elixir 1.13. Please, try to update your Elixir and let us know If you have any other issues, it would be nice if you could share the template you are trying to format in case you are still facing issues .
λ mix deps.get
* Getting heex_formatter (https://github.com/feliperenan/heex_formatter.git)
remote: Enumerating objects: 492, done.
remote: Counting objects: 100% (492/492), done.
remote: Compressing objects: 100% (254/254), done.
remote: Total 492 (delta 207), reused 485 (delta 200), pack-reused 0
origin/HEAD set to main
Dependencies have diverged:
* phoenix_live_view (Hex package)
the dependency phoenix_live_view in mix.exs is overriding a child dependency:
> In mix.exs:
{:phoenix_live_view, "~> 0.17", [env: :prod, repo: "hexpm", hex: "phoenix_live_view"]}
> In deps/heex_formatter/mix.exs:
{:phoenix_live_view, [only: [:dev], env: :prod, git: "https://github.com/phoenixframework/phoenix_live_view.git"]}
Ensure they match or specify one of the above in your deps and set "override: true"
** (Mix) Can't continue due to errors on dependencies
Rather not mark LV with override, but I get that this is pre-release.
@axelson - I have observed that with Elixir 1.13.3, suddenly, the ~H sigils inside the *.ex files are getting formatted on save in VS Code. However, the same is not happening for *.heex files. I could not understand why so. Can you please explain?
Regards,
I also struggled to have the formatter automatically running in a consistent way and noticed mix format does the trick, so just went ahead and created a manual task and keybinding to move on for now until I can get time to revisit the issue.
Please, give it a try and let me know about any issue you may face. Also, notice that you might get some difference from how it has been formatting before.
PS: In case you don’t want to update it, I’ve created a git tag for previous version. But I really recommend you to try out the latest version