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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+7-7
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

+2-2
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

+2-2
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

+7-7
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

lib/elixir/lib/protocol.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ defmodule Protocol do
896896
# Inline struct implementation for performance
897897
@compile {:inline, struct_impl_for: 1}
898898

899-
unless Module.defines_type?(__MODULE__, {:t, 0}) do
899+
if not Module.defines_type?(__MODULE__, {:t, 0}) do
900900
@typedoc """
901901
All the types that implement this protocol.
902902
"""

lib/elixir/lib/registry.ex

+6-6
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ defmodule Registry do
331331
def start_link(options) do
332332
keys = Keyword.get(options, :keys)
333333

334-
unless keys in @keys do
334+
if keys not in @keys do
335335
raise ArgumentError,
336336
"expected :keys to be given and be one of :unique or :duplicate, got: #{inspect(keys)}"
337337
end
@@ -350,27 +350,27 @@ defmodule Registry do
350350

351351
meta = Keyword.get(options, :meta, [])
352352

353-
unless Keyword.keyword?(meta) do
353+
if not Keyword.keyword?(meta) do
354354
raise ArgumentError, "expected :meta to be a keyword list, got: #{inspect(meta)}"
355355
end
356356

357357
partitions = Keyword.get(options, :partitions, 1)
358358

359-
unless is_integer(partitions) and partitions >= 1 do
359+
if not (is_integer(partitions) and partitions >= 1) do
360360
raise ArgumentError,
361361
"expected :partitions to be a positive integer, got: #{inspect(partitions)}"
362362
end
363363

364364
listeners = Keyword.get(options, :listeners, [])
365365

366-
unless is_list(listeners) and Enum.all?(listeners, &is_atom/1) do
366+
if not (is_list(listeners) and Enum.all?(listeners, &is_atom/1)) do
367367
raise ArgumentError,
368368
"expected :listeners to be a list of named processes, got: #{inspect(listeners)}"
369369
end
370370

371371
compressed = Keyword.get(options, :compressed, false)
372372

373-
unless is_boolean(compressed) do
373+
if not is_boolean(compressed) do
374374
raise ArgumentError,
375375
"expected :compressed to be a boolean, got: #{inspect(compressed)}"
376376
end
@@ -1433,7 +1433,7 @@ defmodule Registry do
14331433
end
14341434

14351435
defp unlink_if_unregistered(pid_server, pid_ets, self) do
1436-
unless :ets.member(pid_ets, self) do
1436+
if not :ets.member(pid_ets, self) do
14371437
Process.unlink(pid_server)
14381438
end
14391439
end

lib/elixir/lib/stream/reducers.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ defmodule Stream.Reducers do
151151
defmacro reject(callback, fun \\ nil) do
152152
quote do
153153
fn entry, acc ->
154-
unless unquote(callback).(entry) do
155-
next(unquote(fun), entry, acc)
156-
else
154+
if unquote(callback).(entry) do
157155
skip(acc)
156+
else
157+
next(unquote(fun), entry, acc)
158158
end
159159
end
160160
end

lib/elixir/lib/supervisor.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ defmodule Supervisor do
525525
import Supervisor.Spec
526526
@behaviour Supervisor
527527

528-
unless Module.has_attribute?(__MODULE__, :doc) do
528+
if not Module.has_attribute?(__MODULE__, :doc) do
529529
@doc """
530530
Returns a specification to start this module under a supervisor.
531531

lib/elixir/lib/supervisor/spec.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ defmodule Supervisor.Spec do
168168
) :: {:ok, tuple}
169169
@deprecated "Use the new child specifications outlined in the Supervisor module instead"
170170
def supervise(children, options) do
171-
unless strategy = options[:strategy] do
171+
if !(strategy = options[:strategy]) do
172172
raise ArgumentError, "expected :strategy option to be given"
173173
end
174174

lib/elixir/lib/system.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -1101,7 +1101,7 @@ defmodule System do
11011101
def cmd(command, args, opts \\ []) when is_binary(command) and is_list(args) do
11021102
assert_no_null_byte!(command, "System.cmd/3")
11031103

1104-
unless Enum.all?(args, &is_binary/1) do
1104+
if not Enum.all?(args, &is_binary/1) do
11051105
raise ArgumentError, "all arguments for System.cmd/3 must be binaries"
11061106
end
11071107

lib/elixir/lib/task.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ defmodule Task do
329329
@doc false
330330
defmacro __using__(opts) do
331331
quote location: :keep, bind_quoted: [opts: opts] do
332-
unless Module.has_attribute?(__MODULE__, :doc) do
332+
if not Module.has_attribute?(__MODULE__, :doc) do
333333
@doc """
334334
Returns a specification to start this module under a supervisor.
335335

lib/elixir/lib/task/supervised.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,15 @@ defmodule Task.Supervised do
209209
ordered = Keyword.get(options, :ordered, true)
210210
zip_input_on_exit = Keyword.get(options, :zip_input_on_exit, false)
211211

212-
unless is_integer(max_concurrency) and max_concurrency > 0 do
212+
if not (is_integer(max_concurrency) and max_concurrency > 0) do
213213
raise ArgumentError, ":max_concurrency must be an integer greater than zero"
214214
end
215215

216-
unless on_timeout in [:exit, :kill_task] do
216+
if on_timeout not in [:exit, :kill_task] do
217217
raise ArgumentError, ":on_timeout must be either :exit or :kill_task"
218218
end
219219

220-
unless (is_integer(timeout) and timeout >= 0) or timeout == :infinity do
220+
if not ((is_integer(timeout) and timeout >= 0) or timeout == :infinity) do
221221
raise ArgumentError, ":timeout must be either a positive integer or :infinity"
222222
end
223223

lib/elixir/lib/task/supervisor.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ defmodule Task.Supervisor do
614614
defp build_stream(supervisor, link_type, enumerable, fun, options) do
615615
shutdown = Keyword.get(options, :shutdown, 5000)
616616

617-
unless (is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill do
617+
if not ((is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill) do
618618
raise ArgumentError, ":shutdown must be either a positive integer or :brutal_kill"
619619
end
620620

lib/elixir/scripts/diff.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ defmodule Diff do
131131
end
132132

133133
defp assert_dir!(dir) do
134-
unless File.dir?(dir) do
134+
if not File.dir?(dir) do
135135
raise ArgumentError, "#{inspect(dir)} is not a directory"
136136
end
137137
end

lib/elixir/test/elixir/file_test.exs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ defmodule FileTest do
17941794
stat = File.stat!(fixture)
17951795
assert stat.mode == 0o100666
17961796

1797-
unless windows?() do
1797+
if not windows?() do
17981798
assert File.chmod(fixture, 0o100777) == :ok
17991799
stat = File.stat!(fixture)
18001800
assert stat.mode == 0o100777
@@ -1814,7 +1814,7 @@ defmodule FileTest do
18141814
stat = File.stat!(fixture)
18151815
assert stat.mode == 0o100666
18161816

1817-
unless windows?() do
1817+
if not windows?() do
18181818
assert File.chmod!(fixture, 0o100777) == :ok
18191819
stat = File.stat!(fixture)
18201820
assert stat.mode == 0o100777

lib/elixir/test/elixir/kernel/cli_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ defmodule Kernel.CLI.ExecutableTest do
9595
System.cmd(elixir_executable(context.cli_extension), ["-e", "Time.new!(0, 0, 0)"])
9696

9797
# TODO: remove this once we bump CI to 26.3
98-
unless windows?() and System.otp_release() == "26" do
98+
if not (windows?() and System.otp_release() == "26") do
9999
{output, 0} =
100100
System.cmd(iex_executable(context.cli_extension), [
101101
"--eval",

lib/elixir/test/elixir/kernel/dialyzer_test.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Kernel.DialyzerTest do
1717
|> String.to_charlist()
1818

1919
# Some OSs (like Windows) do not provide the HOME environment variable.
20-
unless System.get_env("HOME") do
20+
if !System.get_env("HOME") do
2121
System.put_env("HOME", System.user_home())
2222
end
2323

0 commit comments

Comments
 (0)