Skip to content

Commit

Permalink
Add pending deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed May 24, 2024
1 parent 54b3736 commit 25e6ce4
Show file tree
Hide file tree
Showing 14 changed files with 87 additions and 124 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ This release no longer supports WERL (a graphical user interface for the Erlang

### 4. Hard deprecations

#### EEx

* [EEx] `<%#` is deprecated in favor of `<%!--` or `<% #`
* [EEx] `c:EEx.handle_text/2` is deprecated in favor of `c:EEx.handle_text/3`

#### Mix

* [mix cmd] Deprecate `mix cmd --app APP` in favor of `mix do --app APP`

## v1.17

The CHANGELOG for v1.17 releases can be found [in the v1.17 branch](https://github.com/elixir-lang/elixir/blob/v1.17/CHANGELOG.md).
18 changes: 15 additions & 3 deletions lib/eex/lib/eex/compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,14 @@ defmodule EEx.Compiler do
end
end

# TODO: Deprecate this on Elixir v1.18
# TODO: Remove me on Elixir v2.0
defp tokenize(~c"<%#" ++ t, line, column, state, buffer, acc) do
IO.warn("<%# is deprecated, use <%!-- or add a space between <% and # instead",
line: line,
column: column,
file: state.file
)

case expr(t, line, column + 3, state, []) do
{:error, message} ->
{:error, message, %{line: line, column: column}}
Expand Down Expand Up @@ -299,6 +305,13 @@ defmodule EEx.Compiler do
}

init = state.engine.init(opts)

if function_exported?(state.engine, :handle_text, 2) do
IO.warn(
"#{inspect(state.engine)}.handle_text/2 is deprecated, implement handle_text/3 instead"
)
end

generate_buffer(tokens, init, [], state)
end

Expand All @@ -316,8 +329,7 @@ defmodule EEx.Compiler do
meta = [line: meta.line, column: meta.column]
state.engine.handle_text(buffer, meta, IO.chardata_to_string(chars))
else
# TODO: Deprecate this branch on Elixir v1.18.
# We should most likely move this check to init to emit the deprecation once.
# TODO: Remove this on Elixir v2.0. The deprecation is on init.
state.engine.handle_text(buffer, IO.chardata_to_string(chars))
end

Expand Down
66 changes: 12 additions & 54 deletions lib/eex/test/eex/tokenizer_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -126,51 +126,21 @@ defmodule EEx.TokenizerTest do
end

test "EEx comments" do
exprs = [
{:text, ~c"foo ", %{column: 1, line: 1}},
{:eof, %{column: 16, line: 1}}
]
ExUnit.CaptureIO.capture_io(:stderr, fn ->
exprs = [
{:text, ~c"foo ", %{column: 1, line: 1}},
{:eof, %{column: 16, line: 1}}
]

assert EEx.tokenize(~c"foo <%# true %>", @opts) == {:ok, exprs}
assert EEx.tokenize(~c"foo <%# true %>", @opts) == {:ok, exprs}

exprs = [
{:text, ~c"foo ", %{column: 1, line: 1}},
{:eof, %{column: 8, line: 2}}
]
exprs = [
{:text, ~c"foo ", %{column: 1, line: 1}},
{:eof, %{column: 8, line: 2}}
]

assert EEx.tokenize(~c"foo <%#\ntrue %>", @opts) == {:ok, exprs}
end

test "EEx comments with do-end" do
exprs = [
{:text, ~c"foo ", %{column: 1, line: 1}},
{:text, ~c"bar", %{column: 19, line: 1}},
{:eof, %{column: 32, line: 1}}
]

assert EEx.tokenize(~c"foo <%# true do %>bar<%# end %>", @opts) == {:ok, exprs}
end

test "EEx comments inside do-end" do
exprs = [
{:start_expr, ~c"", ~c" if true do ", %{column: 1, line: 1}},
{:text, ~c"bar", %{column: 31, line: 1}},
{:end_expr, [], ~c" end ", %{column: 34, line: 1}},
{:eof, %{column: 43, line: 1}}
]

assert EEx.tokenize(~c"<% if true do %><%# comment %>bar<% end %>", @opts) == {:ok, exprs}

exprs = [
{:start_expr, [], ~c" case true do ", %{column: 1, line: 1}},
{:middle_expr, ~c"", ~c" true -> ", %{column: 33, line: 1}},
{:text, ~c"bar", %{column: 46, line: 1}},
{:end_expr, [], ~c" end ", %{column: 49, line: 1}},
{:eof, %{column: 58, line: 1}}
]

assert EEx.tokenize(~c"<% case true do %><%# comment %><% true -> %>bar<% end %>", @opts) ==
{:ok, exprs}
assert EEx.tokenize(~c"foo <%#\ntrue %>", @opts) == {:ok, exprs}
end)
end

test "EEx multi-line comments" do
Expand Down Expand Up @@ -321,15 +291,6 @@ defmodule EEx.TokenizerTest do
assert EEx.tokenize(template, [trim: true] ++ @opts) == {:ok, exprs}
end

test "trim mode with comment" do
exprs = [
{:text, ~c"\n123", %{column: 19, line: 1}},
{:eof, %{column: 4, line: 2}}
]

assert EEx.tokenize(~c" <%# comment %> \n123", [trim: true] ++ @opts) == {:ok, exprs}
end

test "trim mode with multi-line comment" do
exprs = [
{:comment, ~c" comment ", %{column: 3, line: 1}},
Expand Down Expand Up @@ -384,9 +345,6 @@ defmodule EEx.TokenizerTest do
assert EEx.tokenize(~c"foo <% :bar", @opts) ==
{:error, message, %{column: 5, line: 1}}

assert EEx.tokenize(~c"<%# true ", @opts) ==
{:error, "expected closing '%>' for EEx expression", %{column: 1, line: 1}}

message = """
expected closing '--%>' for EEx expression
|
Expand Down
9 changes: 0 additions & 9 deletions lib/eex/test/eex_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,6 @@ defmodule EExTest do
assert_eval("foo baz", "foo <%= if false do %>bar<% else %>baz<% end %>")
end

test "embedded code with comments in do end" do
assert_eval("foo bar", "foo <%= case true do %><%# comment %><% true -> %>bar<% end %>")

assert_eval(
"foo\n\nbar\n",
"foo\n<%= case true do %>\n<%# comment %>\n<% true -> %>\nbar\n<% end %>"
)
end

test "embedded code with multi-line comments in do end" do
assert_eval("foo bar", "foo <%= case true do %><%!-- comment --%><% true -> %>bar<% end %>")

Expand Down
13 changes: 2 additions & 11 deletions lib/elixir/lib/code/formatter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ defmodule Code.Formatter do
@ampersand_prec Code.Identifier.unary_op(:&) |> elem(1)

# Operators that are composed of multiple binary operators
@multi_binary_operators [:"..//"]
@multi_binary_operators [:..//]

# Operators that do not have space between operands
@no_space_binary_operators [:.., :"//"]
Expand Down Expand Up @@ -492,7 +492,7 @@ defmodule Code.Formatter do
end

# 1..2//3
defp quoted_to_algebra({:"..//", meta, [left, middle, right]}, context, state) do
defp quoted_to_algebra({:..//, meta, [left, middle, right]}, context, state) do
quoted_to_algebra({:"//", meta, [{:.., meta, [left, middle]}, right]}, context, state)
end

Expand Down Expand Up @@ -524,10 +524,6 @@ defmodule Code.Formatter do
if keyword_key?(left_arg) do
{left, state} =
case left_arg do
# TODO: Remove this clause in v1.18 when we no longer quote operator :..//
{:__block__, _, [:"..//"]} ->
{string(~S{"..//":}), state}

{:__block__, _, [atom]} when is_atom(atom) ->
iodata =
if Macro.classify_atom(atom) in [:identifier, :unquoted] do
Expand Down Expand Up @@ -1571,11 +1567,6 @@ defmodule Code.Formatter do
Atom.to_string(nil) |> color(nil, inspect_opts)
end

# TODO: Remove this clause in v1.18 when we no longer quote operator :..//
defp atom_to_algebra(:"..//", _, inspect_opts) do
string(":\"..//\"") |> color(:atom, inspect_opts)
end

defp atom_to_algebra(:\\, meta, inspect_opts) do
# Since we parse strings without unescaping, the atoms
# :\\ and :"\\" have the same representation, so we need
Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/code/normalizer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ defmodule Code.Normalizer do
{:.., meta, [left, right]}
else
step = do_normalize(step, state)
{:"..//", meta, [left, right, step]}
{:..//, meta, [left, right, step]}
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/elixir/lib/exception.ex
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ defmodule Exception do
defp rewrite_arg(arg) do
Macro.prewalk(arg, fn
{:%{}, meta, [__struct__: Range, first: first, last: last, step: step]} ->
{:"..//", meta, [first, last, step]}
{:..//, meta, [first, last, step]}

other ->
other
Expand Down
6 changes: 3 additions & 3 deletions lib/elixir/lib/macro.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ defmodule Macro do
:error
end

defp op_call({:"..//", _, [left, middle, right]} = ast, fun) do
defp op_call({:..//, _, [left, middle, right]} = ast, fun) do
left = op_to_string(left, fun, :.., :left)
middle = op_to_string(middle, fun, :.., :right)
right = op_to_string(right, fun, :"//", :right)
Expand Down Expand Up @@ -1935,7 +1935,7 @@ defmodule Macro do
@spec operator?(name :: atom(), arity()) :: boolean()
def operator?(name, arity)

def operator?(:"..//", 3),
def operator?(:..//, 3),
do: true

# Code.Identifier treats :// as a binary operator for precedence
Expand Down Expand Up @@ -2454,7 +2454,7 @@ defmodule Macro do
#
defp inner_classify(atom) when is_atom(atom) do
cond do
atom in [:%, :%{}, :{}, :<<>>, :..., :.., :., :"..//", :->] ->
atom in [:%, :%{}, :{}, :<<>>, :..., :.., :., :..//, :->] ->
:not_callable

# <|>, ^^^, and ~~~ are deprecated
Expand Down
4 changes: 0 additions & 4 deletions lib/elixir/test/elixir/code_formatter/literals_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ defmodule Code.Formatter.LiteralsTest do

test "quoted operators" do
assert_same ~S[:"::"]
assert_same ~S[:"..//"]
assert_format ~S[:..//], ~S[:"..//"]
assert_format ~S{[..//: 1]}, ~S{["..//": 1]}
assert_same ~S{["..//": 1]}
end

test "uses double quotes even when single quotes are used" do
Expand Down
8 changes: 4 additions & 4 deletions lib/elixir/test/elixir/kernel/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ defmodule Kernel.ParserTest do

describe "ternary ops" do
test "root" do
assert parse!("1..2//3") == {:"..//", [line: 1], [1, 2, 3]}
assert parse!("(1..2)//3") == {:"..//", [line: 1], [1, 2, 3]}
assert parse!("1..2//3") == {:..//, [line: 1], [1, 2, 3]}
assert parse!("(1..2)//3") == {:..//, [line: 1], [1, 2, 3]}
end

test "with do-blocks" do
assert parse!("foo do end..bar do end//baz do end") == {
:"..//",
:..//,
[line: 1],
[
{:foo, [line: 1], [[do: {:__block__, [], []}]]},
Expand All @@ -84,7 +84,7 @@ defmodule Kernel.ParserTest do

test "with no parens" do
assert parse!("1..foo do end//bar bat") == {
:"..//",
:..//,
[line: 1],
[
1,
Expand Down
12 changes: 6 additions & 6 deletions lib/logger/lib/logger.ex
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ defmodule Logger do
delete_process_level(pid)
"""
# TODO: Deprecate me on v1.18
# TODO: Deprecate me on v1.19
@doc deprecated: "Use Logger.delete_process_level(pid) instead"
@spec enable(pid) :: :ok
def enable(pid) when pid == self() do
Expand All @@ -580,7 +580,7 @@ defmodule Logger do
put_process_level(pid, :none)
"""
# TODO: Deprecate me on v1.18
# TODO: Deprecate me on v1.20
@doc deprecated: "Use Logger.put_process_level(pid, :none) instead"
@spec disable(pid) :: :ok
def disable(pid) when pid == self() do
Expand All @@ -592,7 +592,7 @@ defmodule Logger do
Currently the only accepted PID is `self()`.
"""
# TODO: Deprecate me on v1.18
# TODO: Deprecate me on v1.20
@doc deprecated: "Use Logger.get_process_level(pid) instead"
@spec enabled?(pid) :: boolean
def enabled?(pid) when pid == self() do
Expand Down Expand Up @@ -828,7 +828,7 @@ defmodule Logger do
@doc """
Adds a new backend.
"""
# TODO: Deprecate this on Elixir v1.19
# TODO: Deprecate this on Elixir v1.20
@doc deprecated: "Use LoggerBackends.add/2 from :logger_backends dependency"
def add_backend(backend, opts \\ []) do
Logger.Backends.Internal.add(backend, opts)
Expand All @@ -837,7 +837,7 @@ defmodule Logger do
@doc """
Removes a backend.
"""
# TODO: Deprecate this on Elixir v1.19
# TODO: Deprecate this on Elixir v1.20
@doc deprecated: "Use LoggerBackends.remove/2 from :logger_backends dependency"
def remove_backend(backend, opts \\ []) do
Logger.Backends.Internal.remove(backend, opts)
Expand All @@ -846,7 +846,7 @@ defmodule Logger do
@doc """
Configures the given backend.
"""
# TODO: Deprecate this on Elixir v1.19
# TODO: Deprecate this on Elixir v1.20
@doc deprecated: "Use LoggerBackends.configure/2 from :logger_backends dependency"
def configure_backend(:console, options) when is_list(options) do
options = Keyword.merge(Application.get_env(:logger, :console, []), options)
Expand Down
8 changes: 4 additions & 4 deletions lib/mix/lib/mix/tasks/cmd.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ defmodule Mix.Tasks.Cmd do
## Command line options
* `--app` - limit running the command to the given app.
This option is currently deprecated in favor of `mix do --app`
* `--cd` *(since v1.10.4)* - the directory to run the command in
## Zombie operating system processes
Expand All @@ -60,12 +57,15 @@ defmodule Mix.Tasks.Cmd do
def run(args) do
{opts, args} = OptionParser.parse_head!(args, strict: @switches)

# TODO: Deprecate `--app` flag in Elixir v1.18
apps =
opts
|> Keyword.get_values(:app)
|> Enum.map(&String.to_atom/1)

if apps != [] do
IO.warn("the --app in mix cmd is deprecated")
end

if apps == [] or Mix.Project.config()[:app] in apps do
cmd_opts = Keyword.take(opts, [:cd])

Expand Down
2 changes: 1 addition & 1 deletion lib/mix/lib/mix/tasks/do.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ defmodule Mix.Tasks.Do do
"""

# TODO: Deprecate using comma on Elixir v1.18
# TODO: Deprecate using comma on Elixir v1.19

@impl true
def run(args) do
Expand Down

0 comments on commit 25e6ce4

Please sign in to comment.