Skip to content

Commit

Permalink
mix needs to use --stdin-filename to support non-elixir files like `.…
Browse files Browse the repository at this point in the history
…heex`

I was seeing errors formatting `.heex` files from `elixir-mode`: 
```
$ apheleia-from-project-root .formatter.exs mix format -

mix format failed for stdin
** (SyntaxError) invalid syntax found on stdin.exs:1:1:
    error: syntax error before: '<'
    │
  1 │ <html lang="en" class="[scrollbar-gutter:stable]">
    │ ^
    │
    └─ stdin.exs:1:1
    (elixir 1.17.2) lib/code.ex:999: Code.format_string!/2
    (mix 1.17.2) lib/mix/tasks/format.ex:649: Mix.Tasks.Format.elixir_format/2
    (mix 1.17.2) lib/mix/tasks/format.ex:668: Mix.Tasks.Format.format_file/2
    (elixir 1.17.2) lib/task/supervised.ex:101: Task.Supervised.invoke_mfa/2
    (elixir 1.17.2) lib/task/supervised.ex:36: Task.Supervised.reply/4
```
Looking through the help page for `mix format`, I saw:
> `--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".

This makes that change.
  • Loading branch information
LucianoLaratelli committed Sep 18, 2024
1 parent 407095d commit 7441fe1
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions apheleia-formatters.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@
(lisp-indent . apheleia-indent-lisp-buffer)
(ktlint . ("ktlint" "--log-level=none" "--stdin" "-F" "-"))
(latexindent . ("latexindent" "--logfile=/dev/null"))
(mix-format . ("apheleia-from-project-root"
".formatter.exs" "mix" "format" "-"))
(mix-format . ("apheleia-from-project-root" ".formatter.exs"
"mix" "format" "--stdin-filename" filepath "-"))
(nixfmt . ("nixfmt"))
(ocamlformat . ("ocamlformat" "-" "--name" filepath
"--enable-outside-detected-project"))
Expand Down

0 comments on commit 7441fe1

Please sign in to comment.