Skip to content

Commit 7ebf5c3

Browse files
committed
Add :emit_warnings to Code.string_to_quoted
1 parent 7d4d420 commit 7ebf5c3

File tree

6 files changed

+9
-15
lines changed

6 files changed

+9
-15
lines changed

lib/elixir/lib/code.ex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -962,10 +962,9 @@ defmodule Code do
962962
to_quoted_opts =
963963
[
964964
unescape: false,
965-
warn_on_unnecessary_quotes: false,
966965
literal_encoder: &{:ok, {:__block__, &2, [&1]}},
967966
token_metadata: true,
968-
warnings: false
967+
emit_warnings: false
969968
] ++ opts
970969

971970
{forms, comments} = string_to_quoted_with_comments!(string, to_quoted_opts)
@@ -1126,9 +1125,8 @@ defmodule Code do
11261125
atoms but `:existing_atoms_only` is still used for dynamic atoms,
11271126
such as atoms with interpolations.
11281127
1129-
* `:warn_on_unnecessary_quotes` - when `false`, does not warn
1130-
when atoms, keywords or calls have unnecessary quotes on
1131-
them. Defaults to `true`.
1128+
* `:emit_warnings` (since v1.16.0) - when `false`, does not emit
1129+
tokenizing/parsing related warnings. Defaults to `true`.
11321130
11331131
## `Macro.to_string/2`
11341132

lib/elixir/lib/code/fragment.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,6 @@ defmodule Code.Fragment do
11071107
opts =
11081108
Keyword.take(opts, [:file, :line, :column, :columns, :token_metadata, :literal_encoder])
11091109

1110-
Code.string_to_quoted(fragment, [cursor_completion: true, warnings: false] ++ opts)
1110+
Code.string_to_quoted(fragment, [cursor_completion: true, emit_warnings: false] ++ opts)
11111111
end
11121112
end

lib/elixir/src/elixir.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ string_to_tokens(String, StartLine, StartColumn, File, Opts) when is_integer(Sta
486486
{ok, _Line, _Column, [], Tokens} ->
487487
{ok, Tokens};
488488
{ok, _Line, _Column, Warnings, Tokens} ->
489-
(lists:keyfind(warnings, 1, Opts) /= {warnings, false}) andalso
489+
(lists:keyfind(emit_warnings, 1, Opts) /= {emit_warnings, false}) andalso
490490
[elixir_errors:erl_warn(L, File, M) || {L, M} <- lists:reverse(Warnings)],
491491
{ok, Tokens};
492492
{error, {Location, {ErrorPrefix, ErrorSuffix}, Token}, _Rest, _Warnings, _SoFar} ->
@@ -544,8 +544,8 @@ to_binary(Atom) when is_atom(Atom) -> atom_to_binary(Atom).
544544

545545
handle_parsing_opts(File, Opts) ->
546546
WarningFile =
547-
case lists:keyfind(warnings, 1, Opts) of
548-
{warnings, false} -> nil;
547+
case lists:keyfind(emit_warnings, 1, Opts) of
548+
{emit_warnings, false} -> nil;
549549
_ -> File
550550
end,
551551
LiteralEncoder =

lib/elixir/src/elixir.hrl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,5 @@
3636
ascii_identifiers_only=true,
3737
indentation=0,
3838
mismatch_hints=[],
39-
warn_on_unnecessary_quotes=true,
4039
warnings=[]
4140
}).

lib/elixir/src/elixir_tokenizer.erl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ tokenize(String, Line, Column, Opts) ->
123123
Acc#elixir_tokenizer{preserve_comments=PreserveComments};
124124
({unescape, Unescape}, Acc) when is_boolean(Unescape) ->
125125
Acc#elixir_tokenizer{unescape=Unescape};
126-
({warn_on_unnecessary_quotes, Unnecessary}, Acc) when is_boolean(Unnecessary) ->
127-
Acc#elixir_tokenizer{warn_on_unnecessary_quotes=Unnecessary};
128126
(_, Acc) ->
129127
Acc
130128
end, #elixir_tokenizer{identifier_tokenizer=IdentifierTokenizer}, Opts),
@@ -964,12 +962,11 @@ eol(_Line, _Column, [{eol, {Line, Column, Count}} | Tokens]) ->
964962
eol(Line, Column, Tokens) ->
965963
[{eol, {Line, Column, 1}} | Tokens].
966964

967-
is_unnecessary_quote([Part], #elixir_tokenizer{warn_on_unnecessary_quotes=true} = Scope) when is_list(Part) ->
965+
is_unnecessary_quote([Part], Scope) when is_list(Part) ->
968966
case (Scope#elixir_tokenizer.identifier_tokenizer):tokenize(Part) of
969967
{identifier, _, [], _, true, Special} -> not lists:member(at, Special);
970968
_ -> false
971969
end;
972-
973970
is_unnecessary_quote(_Parts, _Scope) ->
974971
false.
975972

lib/mix/lib/mix/dep/lock.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Mix.Dep.Lock do
1111
"""
1212
@spec read(Path.t()) :: map()
1313
def read(lockfile \\ lockfile()) do
14-
opts = [file: lockfile, warn_on_unnecessary_quotes: false]
14+
opts = [file: lockfile, emit_warnings: false]
1515

1616
with {:ok, contents} <- File.read(lockfile),
1717
assert_no_merge_conflicts_in_lockfile(lockfile, contents),

0 commit comments

Comments
 (0)