Skip to content

Commit

Permalink
Do not warn for assignment with blocks in EEx
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Jun 15, 2024
1 parent b56b49f commit a39f469
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
14 changes: 7 additions & 7 deletions lib/eex/lib/eex/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -353,13 +353,6 @@ defmodule EEx.Compiler do
scope,
state
) do
if mark == ~c"" do
message =
"the contents of this expression won't be output unless the EEx block starts with \"<%=\""

:elixir_errors.erl_warn({meta.line, meta.column}, state.file, message)
end

{rest, line, contents} = look_ahead_middle(rest, meta.line, chars) || {rest, meta.line, chars}
start_line = meta.line
start_column = column(meta.column, mark)
Expand All @@ -372,6 +365,13 @@ defmodule EEx.Compiler do
%{state | quoted: [], line: line}
)

if mark == ~c"" and not match?({:=, _, [_, _]}, contents) do
message =
"the contents of this expression won't be output unless the EEx block starts with \"<%=\""

:elixir_errors.erl_warn({meta.line, meta.column}, state.file, message)
end

buffer = state.engine.handle_expr(buffer, IO.chardata_to_string(mark), contents)
generate_buffer(rest, buffer, scope, state)
end
Expand Down
9 changes: 0 additions & 9 deletions lib/eex/test/eex/smart_engine_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,6 @@ defmodule EEx.SmartEngineTest do
assert_received :found
end

test "error with unused \"do\" block without \"<%=\" modifier" do
stderr =
ExUnit.CaptureIO.capture_io(:stderr, fn ->
assert_eval("", "<% if true do %>I'm invisible!<% end %>", assigns: %{})
end)

assert stderr =~ "the contents of this expression won't be output"
end

defp assert_eval(expected, actual, binding \\ []) do
result = EEx.eval_string(actual, binding, file: __ENV__.file, engine: EEx.SmartEngine)
assert result == expected
Expand Down
10 changes: 10 additions & 0 deletions lib/eex/test/eex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,16 @@ defmodule EExTest do
~s[unexpected beginning of EEx tag \"<%=\" on \"<%= end %>\"]
end

test "unused \"do\" block without \"<%=\" modifier" do
assert ExUnit.CaptureIO.capture_io(:stderr, fn ->
EEx.compile_string("<% if true do %>I'm invisible!<% end %>")
end) =~ "the contents of this expression won't be output"

# These are fine though
EEx.compile_string("<% foo = fn -> %>Hello<% end %>")
EEx.compile_string("<% foo = if true do %>Hello<% end %>")
end

test "from tokenizer" do
warning =
ExUnit.CaptureIO.capture_io(:stderr, fn ->
Expand Down

0 comments on commit a39f469

Please sign in to comment.