Skip to content

Conversation

superhawk610
Copy link
Contributor

@superhawk610 superhawk610 commented Dec 13, 2020

This PR adds a new compilation error when EEx encounters a do expression without the <%= modifier, since this is nearly always unintentional. For example, take this block:

<% if @password %>
Temporary Password: <%= @password %>
<% else %>
Sign in with your existing password.
<% end %

At first glance, all seems well, and in the context of a full application it may take quite some time to work out that nothing is being output because you're missing the <%= opening tag. The only case I can think of where a do block is valid without the <%= opening tag is something like this:

<% if @condition do %>
  <% some_side_effect() %>
<% end %>

...but this could trivially be refactored to the (IMO) cleaner:

<% if @condition do
  some_side_effect()
end %>

Credit to @halostatue for suggesting this https://groups.google.com/g/elixir-lang-core/c/FKA9PancUm0/m/KzkT1vWuAAAJ

Closes #10536.

@fertapric
Copy link
Member

I would also include another test that checks that it does not warn for single expressions :)

@josevalim
Copy link
Member

@fertapric we don't need said test because otherwise the suite would be warning all the time. Generally speaking, we don't test that warnings are not emitted, because the tests would emit warnings otherwise and because it means we can't run tests concurrently.

@josevalim josevalim merged commit bfa34ec into elixir-lang:master Dec 14, 2020
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

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.

EEx compiler should provide a warning if a block is used without <%=
3 participants