Mix format fails on emojis

Is it supposed to?

Stacktrace:

mix format failed for file: /.../backend/apps/web/lib/web/templates/session/new.html.eex
** (SyntaxError) /.../backend/apps/web/lib/web/templates/session/new.html.eex:2: unexpected token: "👋" (column 6, codepoint U+****)
    (elixir) lib/code.ex:442: Code.format_string!/2
    (mix) lib/mix/tasks/format.ex:293: Mix.Tasks.Format.format_file/3
    (elixir) lib/task/supervised.ex:88: Task.Supervised.do_apply/2
    (elixir) lib/task/supervised.ex:38: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
2 Likes

mix format is capable of formatting eex files? Didn’t know that and consider this a dangerous feature, we could affect the hosts languages semantic…

Anyway, can you please show a full example file which causes that issue? Especially it’s important if this happens when the emoji is embedded or in the host part, or if it doesn’t matter.

mix format is capable of formatting eex files?

Sublime Test elixir plugin seems to be trying to format them on save.

can you please show a full example file which causes that issue?

<div class="mt5">
  <p>👋</p>
  <p>localhost welcomes you</p>
  <div class="bg-white w-third center pa3">
    <%= form_for @conn, session_path(@conn, :create), [as: :session], fn f -> %>

<!-- etc. -->

Opening < html tags also seem to give it troubles.

<div>
  join localhost

  create your personal account

  <%= form_for @changeset, user_path(@conn, :create), fn u -> %>
    <label>
      Name: <%= text_input(u, :handle) %>
    </label>

    <%= submit("Submit") %>
  <% end %>
</div>

causes

mix format failed for file: /.../backend/apps/web/lib/web/templates/user/new.html.eex
** (SyntaxError) /.../backend/apps/web/lib/web/templates/user/new.html.eex:1: syntax error before: '<'
    (elixir) lib/code.ex:442: Code.format_string!/2
    (mix) lib/mix/tasks/format.ex:293: Mix.Tasks.Format.format_file/3
    (elixir) lib/task/supervised.ex:88: Task.Supervised.do_apply/2
    (elixir) lib/task/supervised.ex:38: Task.Supervised.reply/5
    (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3

It seems to want them to format them as plain elixir files, please deactivate the feature in sublime for eex files.

3 Likes

Added a .formatter.exs file into the root of this phoenix project with the following

# Used by "mix format"
[
  inputs: ["mix.exs", "{config,lib,test}/**/*.{ex,exs}"]
]

and the attempts to format .eex files appear to have stopped.

Thanks!

UPDATE: actually, not. Still tries to format on save sometimes, but not every time.

2 Likes

Sounds like a bug in your IDE’s plugin, should report it. :slight_smile: