feliperenan

feliperenan

Hi people :wave:

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.

Here is the Repo link: GitHub - feliperenan/heex_formatter: Formatter for Phoenix Live View templates. · GitHub

Thank you

Showing Posts 34 to 25

ryanjafari

ryanjafari

Yep I can confirm that is my setup as well. Thanks Víctor.

zenw0lf

zenw0lf

Seems like today the only thing you need is GitHub - elixir-lsp/elixir-ls: A frontend-independent IDE "smartness" server for Elixir. Implements the "Language Server Protocol" standard and provides debugger support via the "Debug Adapter Protocol" · GitHub and edit your .formatter.exs to:

[
  import_deps: [:ecto, :phoenix],
  plugins: [Phoenix.LiveView.HTMLFormatter],
  inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
  subdirectories: ["priv/*/migrations"]
]

As for VSCode settings.json:

  "[phoenix-heex]": {
    "editor.defaultFormatter": "JakeBecker.elixir-ls",
    "editor.formatOnSave": true
  },

If you want to be able to use Emmet in you .heex files, add this to settings.json:

  "emmet.includeLanguages": {
    "html-eex": "html",
    "phoenix-heex": "html"
  },
ryanjafari

ryanjafari

Thanks! Your recommendation is what I went with after trying all the options in this thread. Elixir Mix Formatter for VSCode uses mix format for my .heex and .ex, .exs. The key pieces of config seem to be:

"[elixir]": {
    "editor.defaultFormatter": "animus-coop.vscode-elixir-mix-formatter",
},
"[phoenix-heex]": {
    "editor.defaultFormatter": "animus-coop.vscode-elixir-mix-formatter"
},

…in VSCode settings.json and…

[
  plugins: [Phoenix.LiveView.HTMLFormatter],
  inputs: ["*.{heex,ex,exs}", "priv/*/seeds.exs", "{config,lib,test}/**/*.{heex,ex,exs}"],
  import_deps: [:ecto, :phoenix],
  subdirectories: ["priv/*/migrations"]
]

in .formatter.exs.

I also setup the pre-commit git hook for mix format recommended by @jaimeiniesta. You can manage that hook and share it with your teammates in version control by creating a .githooks folder at the project root and git config core.hooksPath .githooks. To ensure everyone formats! :grinning:

cchauche

cchauche

Wanted to update folks on a solution that worked for me to get VSCode to automatically format my HEEX code. I was able to use an extension called Elixir Mix Formatter and then set that as the default formatter for my elixir and heex files. I am now getting automatic formatting on save as well as the option to save without formatting.

jaimeiniesta

jaimeiniesta

Thanks, will try that extension.

Buy now I’ve added a pre-commit git hook so I don’t forget to run mix format, like this elixir-mix-format-pre-commit-hook/pre-commit at master · paulanthonywilson/elixir-mix-format-pre-commit-hook · GitHub

jaimeiniesta

jaimeiniesta

Thanks, I also saw that there’s an open issue in the ElixirLS extension: Formatting on save does not work with heex files. · Issue #242 · elixir-lsp/vscode-elixir-ls · GitHub

webuhu

webuhu

Ok. One more thing.
The formatter should not remove comments <%# TODO: xxx %>.

webuhu

webuhu

I just tried the formatter. Do we really need to format <br><br />.

PS: Other than that it’s great. And the thing thing the <br> is also nitpicking.

Nicd

Nicd

I use the runonsave extension like described here: Heex formatter - a Formatter for Heex templates - #18 by cvkmohan

The downside is that then “save without formatting” isn’t possible.

josevalim

josevalim

Creator of Elixir

Changes to visual studio code may be required, because they don’t call the mix format command directly but rather one of its functions. All the relevant information should be returned by our APIs.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews