radian-software / apheleia

🌷 Run code formatter on buffer contents without moving point, using RCS patches and dynamic programming.
MIT License
517 stars 73 forks source link

Fix mix-format for `.heex` files #304

Open tomconroy opened 1 month ago

tomconroy commented 1 month ago

Per the documentation for mix format:

  • --stdin-filename - path to the file being formatted on stdin. This is
    useful if you are using plugins to support custom filetypes such as .heex.
    Without passing this flag, it is assumed that the code being passed via
    stdin is valid Elixir code. Defaults to "stdin.exs".
tomconroy commented 1 month ago

It seems the test is failing because the test suite is using elixir 1.12 (because of ubuntu 22) and this option was added in 1.14 (available on ubuntu 23+)

raxod502 commented 1 month ago

Oh I see, as you said this blocks CI. Hmmm, can we implement the wrapper script now then, so that it works for CI but also for everyone who is not running the latest package version?

tomconroy commented 1 month ago

I can give it a shot, is there an example in this repo of a similar behavior?

raxod502 commented 1 month ago

There aren't any other formatters that have conditioning on the version in use currently, but there are other wrapper scripts in the scripts/formatters directory. I would do something like running the tool to get its version, cache that in a file with some ttl or based on some other property of the system like the executable location, then delegate the correct arguments based on that. Should be fast and robust.

If you just want to keep things simply for now, I am okay with that too, like I mentioned we can change it later if we receive complaints. Looks like the formatting sample data needs to be updated though to reflect the new tool version:

image

tomconroy commented 1 month ago

So I tried adding a new test for .heex formatting but I realized we would need a config file (.formatter.exs) and probably some elixir dependencies to get it work (https://hexdocs.pm/phoenix_live_view/Phoenix.LiveView.HTMLFormatter.html) Maybe I should just remove this new test?