Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix needs to use --stdin-filename to support non-elixir files like .heex #319

Closed

Conversation

LucianoLaratelli
Copy link

Hey, hope all is well.

I was seeing errors formatting .heex files from elixir-mode in *apheleia-apheleia-from-project-root-log*:

$ 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.

…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.
@LucianoLaratelli LucianoLaratelli changed the title mix needs to use --stdin-filename to support non-elixir files like …heex mix needs to use --stdin-filename to support non-elixir files like .heex Sep 18, 2024
@raxod502
Copy link
Member

Looks like CI is failing thusly, is this option not widely available yet?

image

@LucianoLaratelli
Copy link
Author

Ah, sorry about that.

It looks like the earliest version that had the option available was 1.14.0. The first release candidate for that version was cut in August 2022, so just a little more than two years ago. The current version is 1.17.3.

@raxod502
Copy link
Member

The dilemma I have is that Apheleia doesn't really know which version of a tool it's executing.

When I get some time, I will think on this. I think a framework can be introduced to allow defining how Apheleia will determine the installed version of a tool and cache the result, then use that to condition on what arguments it will pass.

Maybe we can get away with something as simple as implementing it in a wrapper script like apheleia-npx.

@raxod502
Copy link
Member

Check the implementation in #322

@LucianoLaratelli
Copy link
Author

Ah, very nice. Thanks for doing that :)

@LucianoLaratelli LucianoLaratelli deleted the patch-1 branch September 26, 2024 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants