Skip to content

Commit 1286a62

Browse files
authored
Replace unless/2 usages in the codebase (#13808)
1 parent 99beb29 commit 1286a62

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+138
-138
lines changed

lib/elixir/lib/agent.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ defmodule Agent do
207207
@doc false
208208
defmacro __using__(opts) do
209209
quote location: :keep, bind_quoted: [opts: opts] do
210-
unless Module.has_attribute?(__MODULE__, :doc) do
210+
if not Module.has_attribute?(__MODULE__, :doc) do
211211
@doc """
212212
Returns a specification to start this module under a supervisor.
213213

lib/elixir/lib/calendar/time.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ defmodule Time do
521521
do: unit > 0,
522522
else: unit in ~w(second millisecond microsecond nanosecond)a
523523

524-
unless valid? do
524+
if not valid? do
525525
raise ArgumentError,
526526
"unsupported time unit. Expected :hour, :minute, :second, :millisecond, :microsecond, :nanosecond, or a positive integer, got #{inspect(unit)}"
527527
end

lib/elixir/lib/config.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ defmodule Config do
143143
"""
144144
@doc since: "1.9.0"
145145
def config(root_key, opts) when is_atom(root_key) and is_list(opts) do
146-
unless Keyword.keyword?(opts) do
146+
if not Keyword.keyword?(opts) do
147147
raise ArgumentError, "config/2 expected a keyword list, got: #{inspect(opts)}"
148148
end
149149

lib/elixir/lib/dynamic_supervisor.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ defmodule DynamicSupervisor do
274274
defmacro __using__(opts) do
275275
quote location: :keep, bind_quoted: [opts: opts] do
276276
@behaviour DynamicSupervisor
277-
unless Module.has_attribute?(__MODULE__, :doc) do
277+
if not Module.has_attribute?(__MODULE__, :doc) do
278278
@doc """
279279
Returns a specification to start this module under a supervisor.
280280

lib/elixir/lib/gen_server.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ defmodule GenServer do
845845
quote location: :keep, bind_quoted: [opts: opts] do
846846
@behaviour GenServer
847847

848-
unless Module.has_attribute?(__MODULE__, :doc) do
848+
if not Module.has_attribute?(__MODULE__, :doc) do
849849
@doc """
850850
Returns a specification to start this module under a supervisor.
851851
@@ -945,7 +945,7 @@ defmodule GenServer do
945945
end
946946

947947
defmacro __before_compile__(env) do
948-
unless Module.defines?(env.module, {:init, 1}) do
948+
if not Module.defines?(env.module, {:init, 1}) do
949949
message = """
950950
function init/1 required by behaviour GenServer is not implemented \
951951
(in module #{inspect(env.module)}).

lib/elixir/lib/io/ansi/docs.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ defmodule IO.ANSI.Docs do
350350
|> String.split(@spaces)
351351
|> write_with_wrap(options[:width] - byte_size(indent), indent, no_wrap, prefix)
352352

353-
unless no_wrap, do: newline_after_block(options)
353+
if !no_wrap, do: newline_after_block(options)
354354
end
355355

356356
defp format_text(text, options) do

lib/elixir/lib/kernel/typespec.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ defmodule Kernel.Typespec do
118118
case spec_to_signature(expr) do
119119
{name, arity} ->
120120
# store doc only once in case callback has multiple clauses
121-
unless :ets.member(set, {kind, name, arity}) do
121+
if not :ets.member(set, {kind, name, arity}) do
122122
{line, doc} = get_doc_info(set, :doc, line)
123123
store_doc(set, kind, name, arity, line, :doc, doc, %{})
124124
end
@@ -320,7 +320,7 @@ defmodule Kernel.Typespec do
320320

321321
invalid_args = :lists.filter(&(not valid_variable_ast?(&1)), args)
322322

323-
unless invalid_args == [] do
323+
if invalid_args != [] do
324324
invalid_args = :lists.join(", ", :lists.map(&Macro.to_string/1, invalid_args))
325325

326326
message =
@@ -380,7 +380,7 @@ defmodule Kernel.Typespec do
380380
ensure_no_defaults!(args)
381381
state = clean_local_state(state)
382382

383-
unless Keyword.keyword?(guard) do
383+
if not Keyword.keyword?(guard) do
384384
error = "expected keywords as guard in type specification, got: #{Macro.to_string(guard)}"
385385
compile_error(caller, error)
386386
end
@@ -573,7 +573,7 @@ defmodule Kernel.Typespec do
573573
|> Map.delete(:__struct__)
574574
|> Map.to_list()
575575

576-
unless Keyword.keyword?(fields) do
576+
if not Keyword.keyword?(fields) do
577577
compile_error(caller, "expected key-value pairs in struct #{Macro.to_string(name)}")
578578
end
579579

@@ -587,7 +587,7 @@ defmodule Kernel.Typespec do
587587
)
588588

589589
fun = fn {field, _} ->
590-
unless Keyword.has_key?(struct, field) do
590+
if not Keyword.has_key?(struct, field) do
591591
compile_error(
592592
caller,
593593
"undefined field #{inspect(field)} on struct #{inspect(module)}"
@@ -630,7 +630,7 @@ defmodule Kernel.Typespec do
630630
)
631631

632632
fun = fn {field, _} ->
633-
unless Keyword.has_key?(fields, field) do
633+
if not Keyword.has_key?(fields, field) do
634634
compile_error(caller, "undefined field #{field} on record #{inspect(tag)}")
635635
end
636636
end
@@ -754,7 +754,7 @@ defmodule Kernel.Typespec do
754754
) do
755755
remote = Module.get_attribute(caller.module, attr)
756756

757-
unless is_atom(remote) and remote != nil do
757+
if not (is_atom(remote) and remote != nil) do
758758
message =
759759
"invalid remote in typespec: #{Macro.to_string(orig)} (@#{attr} is #{inspect(remote)})"
760760

lib/elixir/lib/macro.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -895,8 +895,8 @@ defmodule Macro do
895895
defp find_invalid(bin) when is_binary(bin), do: nil
896896

897897
defp find_invalid(fun) when is_function(fun) do
898-
unless Function.info(fun, :env) == {:env, []} and
899-
Function.info(fun, :type) == {:type, :external} do
898+
if Function.info(fun, :env) != {:env, []} or
899+
Function.info(fun, :type) != {:type, :external} do
900900
{:error, fun}
901901
end
902902
end

lib/elixir/lib/module.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ defmodule Module do
902902
end
903903

904904
def create(module, quoted, opts) when is_atom(module) and is_list(opts) do
905-
unless Keyword.has_key?(opts, :file) do
905+
if not Keyword.has_key?(opts, :file) do
906906
raise ArgumentError, "expected :file to be given as option"
907907
end
908908

@@ -2260,7 +2260,7 @@ defmodule Module do
22602260
end
22612261

22622262
defp preprocess_attribute(:nifs, value) do
2263-
unless function_arity_list?(value) do
2263+
if not function_arity_list?(value) do
22642264
raise ArgumentError,
22652265
"@nifs is a built-in module attribute for specifying a list " <>
22662266
"of functions and their arities that are NIFs, got: #{inspect(value)}"

lib/elixir/lib/partition_supervisor.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,26 +228,26 @@ defmodule PartitionSupervisor do
228228
def start_link(opts) when is_list(opts) do
229229
name = opts[:name]
230230

231-
unless name do
231+
if !name do
232232
raise ArgumentError, "the :name option must be given to PartitionSupervisor"
233233
end
234234

235235
{child_spec, opts} = Keyword.pop(opts, :child_spec)
236236

237-
unless child_spec do
237+
if !child_spec do
238238
raise ArgumentError, "the :child_spec option must be given to PartitionSupervisor"
239239
end
240240

241241
{partitions, opts} = Keyword.pop(opts, :partitions, System.schedulers_online())
242242

243-
unless is_integer(partitions) and partitions >= 1 do
243+
if not (is_integer(partitions) and partitions >= 1) do
244244
raise ArgumentError,
245245
"the :partitions option must be a positive integer, got: #{inspect(partitions)}"
246246
end
247247

248248
{with_arguments, opts} = Keyword.pop(opts, :with_arguments, fn args, _partition -> args end)
249249

250-
unless is_function(with_arguments, 2) do
250+
if not is_function(with_arguments, 2) do
251251
raise ArgumentError,
252252
"the :with_arguments option must be a function that receives two arguments, " <>
253253
"the current call arguments and the partition, got: #{inspect(with_arguments)}"
@@ -260,7 +260,7 @@ defmodule PartitionSupervisor do
260260
for partition <- 0..(partitions - 1) do
261261
args = with_arguments.(args, partition)
262262

263-
unless is_list(args) do
263+
if not is_list(args) do
264264
raise "the call to the function in :with_arguments must return a list, got: #{inspect(args)}"
265265
end
266266

@@ -270,7 +270,7 @@ defmodule PartitionSupervisor do
270270

271271
auto_shutdown = Keyword.get(opts, :auto_shutdown, :never)
272272

273-
unless auto_shutdown == :never do
273+
if auto_shutdown != :never do
274274
raise ArgumentError,
275275
"the :auto_shutdown option must be :never, got: #{inspect(auto_shutdown)}"
276276
end
@@ -319,7 +319,7 @@ defmodule PartitionSupervisor do
319319
defp init_partitions({:via, _, _}, partitions) do
320320
child_spec = {Registry, keys: :unique, name: @registry}
321321

322-
unless Process.whereis(@registry) do
322+
if !Process.whereis(@registry) do
323323
Supervisor.start_child(:elixir_sup, child_spec)
324324
end
325325

0 commit comments

Comments
 (0)