From 5a1b5c5a0218296c7dbdfcc6f7a27f119f923c27 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 9 Aug 2024 14:08:21 +0900 Subject: [PATCH 1/8] Add option to remove unless --- lib/elixir/lib/code/formatter.ex | 58 ++++++++++++++ .../elixir/code_formatter/migration_test.exs | 77 +++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 lib/elixir/test/elixir/code_formatter/migration_test.exs diff --git a/lib/elixir/lib/code/formatter.ex b/lib/elixir/lib/code/formatter.ex index a923f9bde48..544a23a7918 100644 --- a/lib/elixir/lib/code/formatter.ex +++ b/lib/elixir/lib/code/formatter.ex @@ -191,6 +191,7 @@ defmodule Code.Formatter do sigils = Keyword.get(opts, :sigils, []) normalize_bitstring_modifiers = Keyword.get(opts, :normalize_bitstring_modifiers, true) normalize_charlists_as_sigils = Keyword.get(opts, :normalize_charlists_as_sigils, true) + rewrite_unless = Keyword.get(opts, :rewrite_unless, false) syntax_colors = Keyword.get(opts, :syntax_colors, []) sigils = @@ -217,6 +218,7 @@ defmodule Code.Formatter do file: file, normalize_bitstring_modifiers: normalize_bitstring_modifiers, normalize_charlists_as_sigils: normalize_charlists_as_sigils, + rewrite_unless: rewrite_unless, inspect_opts: %Inspect.Opts{syntax_colors: syntax_colors} } end @@ -484,6 +486,27 @@ defmodule Code.Formatter do binary_op_to_algebra(:in, "not in", meta, left, right, context, state) end + # rewrite unless as if! + defp quoted_to_algebra( + {:unless, meta, [condition, block]}, + context, + %{rewrite_unless: true} = state + ) do + quoted_to_algebra({:if, meta, [negate_condition(condition), block]}, context, state) + end + + defp quoted_to_algebra( + {:|>, meta1, [condition, {:unless, meta2, [block]}]}, + context, + %{rewrite_unless: true} = state + ) do + quoted_to_algebra( + {:|>, meta1, [negate_condition(condition), {:if, meta2, [block]}]}, + context, + state + ) + end + # .. defp quoted_to_algebra({:.., _meta, []}, context, state) do if context in [:no_parens_arg, :no_parens_one_arg] do @@ -2449,4 +2472,39 @@ defmodule Code.Formatter do defp has_double_quote?(chunk) do is_binary(chunk) and chunk =~ @double_quote end + + # Migration rewrites + + @bool_operators [ + :>, + :>=, + :<, + :<=, + :in + ] + @guards [ + :is_atom, + :is_number, + :is_integer, + :is_float, + :is_binary, + :is_map, + :is_struct + # ... + # TODO add more guards + ] + + defp negate_condition(condition) do + case condition do + {neg, _, [condition]} when neg in [:!, :not] -> condition + {:|>, _, _} -> {:|>, [], [condition, {{:., [], [Kernel, :!]}, [closing: []], []}]} + {op, _, [_, _]} when op in @bool_operators -> {:not, [], [condition]} + {guard, _, [_ | _]} when guard in @guards -> {:not, [], [condition]} + {:==, meta, [left, right]} -> {:!=, meta, [left, right]} + {:===, meta, [left, right]} -> {:!==, meta, [left, right]} + {:!=, meta, [left, right]} -> {:==, meta, [left, right]} + {:!==, meta, [left, right]} -> {:===, meta, [left, right]} + _ -> {:!, [], [condition]} + end + end end diff --git a/lib/elixir/test/elixir/code_formatter/migration_test.exs b/lib/elixir/test/elixir/code_formatter/migration_test.exs new file mode 100644 index 00000000000..a15d9b6c2e6 --- /dev/null +++ b/lib/elixir/test/elixir/code_formatter/migration_test.exs @@ -0,0 +1,77 @@ +Code.require_file("../test_helper.exs", __DIR__) + +defmodule Code.Formatter.MigrationTest do + use ExUnit.Case, async: true + + import CodeFormatterHelpers + + @rewrite_unless [rewrite_unless: true] + + describe "rewrite_unless: true" do + test "rewrites unless as an if with negated condition" do + bad = "unless x, do: y" + + good = "if !x, do: y" + + assert_format bad, good, @rewrite_unless + + bad = """ + unless x do + y + else + z + end + """ + + good = """ + if !x do + y + else + z + end + """ + + assert_format bad, good, @rewrite_unless + end + + test "rewrites pipelines with negated condition" do + bad = "x |> unless(do: y)" + + good = "!x |> if(do: y)" + + assert_format bad, good, @rewrite_unless + + bad = "x |> foo() |> unless(do: y)" + + good = "x |> foo() |> Kernel.!() |> if(do: y)" + + assert_format bad, good, @rewrite_unless + end + + test "rewrites in as not in" do + assert_format "unless x in y, do: 1", "if x not in y, do: 1", @rewrite_unless + end + + test "rewrites equality operators" do + assert_format "unless x == y, do: 1", "if x != y, do: 1", @rewrite_unless + assert_format "unless x === y, do: 1", "if x !== y, do: 1", @rewrite_unless + assert_format "unless x != y, do: 1", "if x == y, do: 1", @rewrite_unless + assert_format "unless x !== y, do: 1", "if x === y, do: 1", @rewrite_unless + end + + test "rewrites boolean or is_* conditions with not" do + assert_format "unless x > 0, do: 1", "if not (x > 0), do: 1", @rewrite_unless + assert_format "unless is_atom(x), do: 1", "if not is_atom(x), do: 1", @rewrite_unless + end + + test "removes ! or not in condition" do + assert_format "unless not x, do: 1", "if x, do: 1", @rewrite_unless + assert_format "unless !x, do: 1", "if x, do: 1", @rewrite_unless + end + + test "does nothing without the rewrite_unless option" do + assert_same "unless x, do: y" + assert_same "unless x, do: y, else: z" + end + end +end From fe87314a2ee796001132307337603aa657a45dac Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 9 Aug 2024 14:28:05 +0900 Subject: [PATCH 2/8] Run formatter on the codebase --- lib/elixir/lib/agent.ex | 2 +- lib/elixir/lib/calendar/time.ex | 2 +- lib/elixir/lib/config.ex | 2 +- lib/elixir/lib/dynamic_supervisor.ex | 2 +- lib/elixir/lib/gen_server.ex | 4 +-- lib/elixir/lib/io/ansi/docs.ex | 2 +- lib/elixir/lib/kernel.ex | 2 +- lib/elixir/lib/kernel/typespec.ex | 14 +++++----- lib/elixir/lib/macro.ex | 4 +-- lib/elixir/lib/module.ex | 4 +-- lib/elixir/lib/partition_supervisor.ex | 14 +++++----- lib/elixir/lib/protocol.ex | 2 +- lib/elixir/lib/registry.ex | 12 ++++----- lib/elixir/lib/stream/reducers.ex | 2 +- lib/elixir/lib/supervisor.ex | 2 +- lib/elixir/lib/supervisor/spec.ex | 2 +- lib/elixir/lib/system.ex | 2 +- lib/elixir/lib/task.ex | 2 +- lib/elixir/lib/task/supervised.ex | 6 ++--- lib/elixir/lib/task/supervisor.ex | 2 +- lib/elixir/scripts/diff.exs | 2 +- lib/elixir/test/elixir/file_test.exs | 4 +-- lib/elixir/test/elixir/kernel/cli_test.exs | 2 +- .../test/elixir/kernel/dialyzer_test.exs | 2 +- lib/elixir/test/elixir/macro_test.exs | 2 +- lib/elixir/test/elixir/supervisor_test.exs | 2 +- lib/elixir/test/elixir/system_test.exs | 4 +-- lib/ex_unit/lib/ex_unit/assertions.ex | 4 +-- lib/ex_unit/lib/ex_unit/callbacks.ex | 4 +-- lib/ex_unit/lib/ex_unit/case.ex | 14 +++++----- lib/ex_unit/test/ex_unit/supervised_test.exs | 2 +- lib/iex/lib/iex.ex | 2 +- lib/iex/lib/iex/evaluator.ex | 2 +- lib/iex/lib/iex/helpers.ex | 6 ++--- lib/logger/lib/logger/backends/internal.ex | 2 +- lib/logger/test/test_helper.exs | 2 +- lib/mix/lib/mix.ex | 4 +-- lib/mix/lib/mix/dep.ex | 2 +- lib/mix/lib/mix/dep/loader.ex | 4 +-- lib/mix/lib/mix/dep/lock.ex | 2 +- lib/mix/lib/mix/generator.ex | 2 +- lib/mix/lib/mix/local.ex | 2 +- lib/mix/lib/mix/project.ex | 4 +-- lib/mix/lib/mix/release.ex | 2 +- lib/mix/lib/mix/scm/git.ex | 2 +- lib/mix/lib/mix/shell/io.ex | 2 +- lib/mix/lib/mix/task.ex | 2 +- lib/mix/lib/mix/tasks/app.config.ex | 2 +- lib/mix/lib/mix/tasks/archive.build.ex | 2 +- lib/mix/lib/mix/tasks/compile.all.ex | 4 +-- lib/mix/lib/mix/tasks/compile.app.ex | 26 +++++++++---------- lib/mix/lib/mix/tasks/compile.elixir.ex | 2 +- lib/mix/lib/mix/tasks/compile.erlang.ex | 2 +- lib/mix/lib/mix/tasks/compile.leex.ex | 4 +-- lib/mix/lib/mix/tasks/compile.yecc.ex | 4 +-- lib/mix/lib/mix/tasks/deps.compile.ex | 8 +++--- lib/mix/lib/mix/tasks/deps.get.ex | 2 +- lib/mix/lib/mix/tasks/deps.loadpaths.ex | 10 +++---- lib/mix/lib/mix/tasks/deps.unlock.ex | 6 ++--- lib/mix/lib/mix/tasks/deps.update.ex | 2 +- lib/mix/lib/mix/tasks/escript.build.ex | 4 +-- lib/mix/lib/mix/tasks/format.ex | 2 +- lib/mix/lib/mix/tasks/loadpaths.ex | 4 +-- lib/mix/lib/mix/tasks/new.ex | 6 ++--- lib/mix/lib/mix/tasks/release.ex | 2 +- lib/mix/lib/mix/tasks/run.ex | 2 +- lib/mix/lib/mix/tasks/test.ex | 2 +- lib/mix/lib/mix/utils.ex | 2 +- lib/mix/test/mix/release_test.exs | 2 +- lib/mix/test/test_helper.exs | 8 +++--- 70 files changed, 138 insertions(+), 138 deletions(-) diff --git a/lib/elixir/lib/agent.ex b/lib/elixir/lib/agent.ex index 20af983839b..74758e6798d 100644 --- a/lib/elixir/lib/agent.ex +++ b/lib/elixir/lib/agent.ex @@ -207,7 +207,7 @@ defmodule Agent do @doc false defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do - unless Module.has_attribute?(__MODULE__, :doc) do + if !Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/calendar/time.ex b/lib/elixir/lib/calendar/time.ex index 38198561c82..5661ab21c0f 100644 --- a/lib/elixir/lib/calendar/time.ex +++ b/lib/elixir/lib/calendar/time.ex @@ -521,7 +521,7 @@ defmodule Time do do: unit > 0, else: unit in ~w(second millisecond microsecond nanosecond)a - unless valid? do + if !valid? do raise ArgumentError, "unsupported time unit. Expected :hour, :minute, :second, :millisecond, :microsecond, :nanosecond, or a positive integer, got #{inspect(unit)}" end diff --git a/lib/elixir/lib/config.ex b/lib/elixir/lib/config.ex index 728a2b2cbd4..107dd30b15b 100644 --- a/lib/elixir/lib/config.ex +++ b/lib/elixir/lib/config.ex @@ -143,7 +143,7 @@ defmodule Config do """ @doc since: "1.9.0" def config(root_key, opts) when is_atom(root_key) and is_list(opts) do - unless Keyword.keyword?(opts) do + if !Keyword.keyword?(opts) do raise ArgumentError, "config/2 expected a keyword list, got: #{inspect(opts)}" end diff --git a/lib/elixir/lib/dynamic_supervisor.ex b/lib/elixir/lib/dynamic_supervisor.ex index 95147113b3c..76079dd3fd3 100644 --- a/lib/elixir/lib/dynamic_supervisor.ex +++ b/lib/elixir/lib/dynamic_supervisor.ex @@ -274,7 +274,7 @@ defmodule DynamicSupervisor do defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do @behaviour DynamicSupervisor - unless Module.has_attribute?(__MODULE__, :doc) do + if !Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/gen_server.ex b/lib/elixir/lib/gen_server.ex index 90d773fff40..fb571d73a93 100644 --- a/lib/elixir/lib/gen_server.ex +++ b/lib/elixir/lib/gen_server.ex @@ -845,7 +845,7 @@ defmodule GenServer do quote location: :keep, bind_quoted: [opts: opts] do @behaviour GenServer - unless Module.has_attribute?(__MODULE__, :doc) do + if !Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. @@ -945,7 +945,7 @@ defmodule GenServer do end defmacro __before_compile__(env) do - unless Module.defines?(env.module, {:init, 1}) do + if !Module.defines?(env.module, {:init, 1}) do message = """ function init/1 required by behaviour GenServer is not implemented \ (in module #{inspect(env.module)}). diff --git a/lib/elixir/lib/io/ansi/docs.ex b/lib/elixir/lib/io/ansi/docs.ex index 0f1af54cf65..de0878be6b4 100644 --- a/lib/elixir/lib/io/ansi/docs.ex +++ b/lib/elixir/lib/io/ansi/docs.ex @@ -350,7 +350,7 @@ defmodule IO.ANSI.Docs do |> String.split(@spaces) |> write_with_wrap(options[:width] - byte_size(indent), indent, no_wrap, prefix) - unless no_wrap, do: newline_after_block(options) + if !no_wrap, do: newline_after_block(options) end defp format_text(text, options) do diff --git a/lib/elixir/lib/kernel.ex b/lib/elixir/lib/kernel.ex index 68b779a5755..a586da9fa09 100644 --- a/lib/elixir/lib/kernel.ex +++ b/lib/elixir/lib/kernel.ex @@ -3956,7 +3956,7 @@ defmodule Kernel do "Math still works" """ - defmacro unless(condition, clauses) do + defmacro if(!condition, clauses) do build_unless(condition, clauses) end diff --git a/lib/elixir/lib/kernel/typespec.ex b/lib/elixir/lib/kernel/typespec.ex index da7c6df5a51..03af66a441e 100644 --- a/lib/elixir/lib/kernel/typespec.ex +++ b/lib/elixir/lib/kernel/typespec.ex @@ -118,7 +118,7 @@ defmodule Kernel.Typespec do case spec_to_signature(expr) do {name, arity} -> # store doc only once in case callback has multiple clauses - unless :ets.member(set, {kind, name, arity}) do + if !:ets.member(set, {kind, name, arity}) do {line, doc} = get_doc_info(set, :doc, line) store_doc(set, kind, name, arity, line, :doc, doc, %{}) end @@ -320,7 +320,7 @@ defmodule Kernel.Typespec do invalid_args = :lists.filter(&(not valid_variable_ast?(&1)), args) - unless invalid_args == [] do + if invalid_args != [] do invalid_args = :lists.join(", ", :lists.map(&Macro.to_string/1, invalid_args)) message = @@ -380,7 +380,7 @@ defmodule Kernel.Typespec do ensure_no_defaults!(args) state = clean_local_state(state) - unless Keyword.keyword?(guard) do + if !Keyword.keyword?(guard) do error = "expected keywords as guard in type specification, got: #{Macro.to_string(guard)}" compile_error(caller, error) end @@ -573,7 +573,7 @@ defmodule Kernel.Typespec do |> Map.delete(:__struct__) |> Map.to_list() - unless Keyword.keyword?(fields) do + if !Keyword.keyword?(fields) do compile_error(caller, "expected key-value pairs in struct #{Macro.to_string(name)}") end @@ -587,7 +587,7 @@ defmodule Kernel.Typespec do ) fun = fn {field, _} -> - unless Keyword.has_key?(struct, field) do + if !Keyword.has_key?(struct, field) do compile_error( caller, "undefined field #{inspect(field)} on struct #{inspect(module)}" @@ -630,7 +630,7 @@ defmodule Kernel.Typespec do ) fun = fn {field, _} -> - unless Keyword.has_key?(fields, field) do + if !Keyword.has_key?(fields, field) do compile_error(caller, "undefined field #{field} on record #{inspect(tag)}") end end @@ -754,7 +754,7 @@ defmodule Kernel.Typespec do ) do remote = Module.get_attribute(caller.module, attr) - unless is_atom(remote) and remote != nil do + if !(is_atom(remote) and remote != nil) do message = "invalid remote in typespec: #{Macro.to_string(orig)} (@#{attr} is #{inspect(remote)})" diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex index 6f9ff8dc7b5..9a2077d1a32 100644 --- a/lib/elixir/lib/macro.ex +++ b/lib/elixir/lib/macro.ex @@ -895,8 +895,8 @@ defmodule Macro do defp find_invalid(bin) when is_binary(bin), do: nil defp find_invalid(fun) when is_function(fun) do - unless Function.info(fun, :env) == {:env, []} and - Function.info(fun, :type) == {:type, :external} do + if !(Function.info(fun, :env) == {:env, []} and + Function.info(fun, :type) == {:type, :external}) do {:error, fun} end end diff --git a/lib/elixir/lib/module.ex b/lib/elixir/lib/module.ex index 2c5ff41e3de..e4f823a0399 100644 --- a/lib/elixir/lib/module.ex +++ b/lib/elixir/lib/module.ex @@ -902,7 +902,7 @@ defmodule Module do end def create(module, quoted, opts) when is_atom(module) and is_list(opts) do - unless Keyword.has_key?(opts, :file) do + if !Keyword.has_key?(opts, :file) do raise ArgumentError, "expected :file to be given as option" end @@ -2260,7 +2260,7 @@ defmodule Module do end defp preprocess_attribute(:nifs, value) do - unless function_arity_list?(value) do + if !function_arity_list?(value) do raise ArgumentError, "@nifs is a built-in module attribute for specifying a list " <> "of functions and their arities that are NIFs, got: #{inspect(value)}" diff --git a/lib/elixir/lib/partition_supervisor.ex b/lib/elixir/lib/partition_supervisor.ex index 11058c19c65..f3557718292 100644 --- a/lib/elixir/lib/partition_supervisor.ex +++ b/lib/elixir/lib/partition_supervisor.ex @@ -228,26 +228,26 @@ defmodule PartitionSupervisor do def start_link(opts) when is_list(opts) do name = opts[:name] - unless name do + if !name do raise ArgumentError, "the :name option must be given to PartitionSupervisor" end {child_spec, opts} = Keyword.pop(opts, :child_spec) - unless child_spec do + if !child_spec do raise ArgumentError, "the :child_spec option must be given to PartitionSupervisor" end {partitions, opts} = Keyword.pop(opts, :partitions, System.schedulers_online()) - unless is_integer(partitions) and partitions >= 1 do + if !(is_integer(partitions) and partitions >= 1) do raise ArgumentError, "the :partitions option must be a positive integer, got: #{inspect(partitions)}" end {with_arguments, opts} = Keyword.pop(opts, :with_arguments, fn args, _partition -> args end) - unless is_function(with_arguments, 2) do + if !is_function(with_arguments, 2) do raise ArgumentError, "the :with_arguments option must be a function that receives two arguments, " <> "the current call arguments and the partition, got: #{inspect(with_arguments)}" @@ -260,7 +260,7 @@ defmodule PartitionSupervisor do for partition <- 0..(partitions - 1) do args = with_arguments.(args, partition) - unless is_list(args) do + if !is_list(args) do raise "the call to the function in :with_arguments must return a list, got: #{inspect(args)}" end @@ -270,7 +270,7 @@ defmodule PartitionSupervisor do auto_shutdown = Keyword.get(opts, :auto_shutdown, :never) - unless auto_shutdown == :never do + if auto_shutdown != :never do raise ArgumentError, "the :auto_shutdown option must be :never, got: #{inspect(auto_shutdown)}" end @@ -319,7 +319,7 @@ defmodule PartitionSupervisor do defp init_partitions({:via, _, _}, partitions) do child_spec = {Registry, keys: :unique, name: @registry} - unless Process.whereis(@registry) do + if !Process.whereis(@registry) do Supervisor.start_child(:elixir_sup, child_spec) end diff --git a/lib/elixir/lib/protocol.ex b/lib/elixir/lib/protocol.ex index f1c802a9f2c..78c7f8aaf6d 100644 --- a/lib/elixir/lib/protocol.ex +++ b/lib/elixir/lib/protocol.ex @@ -896,7 +896,7 @@ defmodule Protocol do # Inline struct implementation for performance @compile {:inline, struct_impl_for: 1} - unless Module.defines_type?(__MODULE__, {:t, 0}) do + if !Module.defines_type?(__MODULE__, {:t, 0}) do @typedoc """ All the types that implement this protocol. """ diff --git a/lib/elixir/lib/registry.ex b/lib/elixir/lib/registry.ex index 01774f7d9da..e5dd199d864 100644 --- a/lib/elixir/lib/registry.ex +++ b/lib/elixir/lib/registry.ex @@ -331,7 +331,7 @@ defmodule Registry do def start_link(options) do keys = Keyword.get(options, :keys) - unless keys in @keys do + if keys not in @keys do raise ArgumentError, "expected :keys to be given and be one of :unique or :duplicate, got: #{inspect(keys)}" end @@ -350,27 +350,27 @@ defmodule Registry do meta = Keyword.get(options, :meta, []) - unless Keyword.keyword?(meta) do + if !Keyword.keyword?(meta) do raise ArgumentError, "expected :meta to be a keyword list, got: #{inspect(meta)}" end partitions = Keyword.get(options, :partitions, 1) - unless is_integer(partitions) and partitions >= 1 do + if !(is_integer(partitions) and partitions >= 1) do raise ArgumentError, "expected :partitions to be a positive integer, got: #{inspect(partitions)}" end listeners = Keyword.get(options, :listeners, []) - unless is_list(listeners) and Enum.all?(listeners, &is_atom/1) do + if !(is_list(listeners) and Enum.all?(listeners, &is_atom/1)) do raise ArgumentError, "expected :listeners to be a list of named processes, got: #{inspect(listeners)}" end compressed = Keyword.get(options, :compressed, false) - unless is_boolean(compressed) do + if !is_boolean(compressed) do raise ArgumentError, "expected :compressed to be a boolean, got: #{inspect(compressed)}" end @@ -1433,7 +1433,7 @@ defmodule Registry do end defp unlink_if_unregistered(pid_server, pid_ets, self) do - unless :ets.member(pid_ets, self) do + if !:ets.member(pid_ets, self) do Process.unlink(pid_server) end end diff --git a/lib/elixir/lib/stream/reducers.ex b/lib/elixir/lib/stream/reducers.ex index 9e5c0512179..8afb0a841cb 100644 --- a/lib/elixir/lib/stream/reducers.ex +++ b/lib/elixir/lib/stream/reducers.ex @@ -151,7 +151,7 @@ defmodule Stream.Reducers do defmacro reject(callback, fun \\ nil) do quote do fn entry, acc -> - unless unquote(callback).(entry) do + if !unquote(callback).(entry) do next(unquote(fun), entry, acc) else skip(acc) diff --git a/lib/elixir/lib/supervisor.ex b/lib/elixir/lib/supervisor.ex index 0307673567d..a746c3a1d2b 100644 --- a/lib/elixir/lib/supervisor.ex +++ b/lib/elixir/lib/supervisor.ex @@ -525,7 +525,7 @@ defmodule Supervisor do import Supervisor.Spec @behaviour Supervisor - unless Module.has_attribute?(__MODULE__, :doc) do + if !Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/supervisor/spec.ex b/lib/elixir/lib/supervisor/spec.ex index f2a55a15709..7d408be8781 100644 --- a/lib/elixir/lib/supervisor/spec.ex +++ b/lib/elixir/lib/supervisor/spec.ex @@ -168,7 +168,7 @@ defmodule Supervisor.Spec do ) :: {:ok, tuple} @deprecated "Use the new child specifications outlined in the Supervisor module instead" def supervise(children, options) do - unless strategy = options[:strategy] do + if !(strategy = options[:strategy]) do raise ArgumentError, "expected :strategy option to be given" end diff --git a/lib/elixir/lib/system.ex b/lib/elixir/lib/system.ex index 24e3c457b6b..cbd9c856bca 100644 --- a/lib/elixir/lib/system.ex +++ b/lib/elixir/lib/system.ex @@ -1101,7 +1101,7 @@ defmodule System do def cmd(command, args, opts \\ []) when is_binary(command) and is_list(args) do assert_no_null_byte!(command, "System.cmd/3") - unless Enum.all?(args, &is_binary/1) do + if !Enum.all?(args, &is_binary/1) do raise ArgumentError, "all arguments for System.cmd/3 must be binaries" end diff --git a/lib/elixir/lib/task.ex b/lib/elixir/lib/task.ex index 3722af3f09b..b0d91eb31b4 100644 --- a/lib/elixir/lib/task.ex +++ b/lib/elixir/lib/task.ex @@ -329,7 +329,7 @@ defmodule Task do @doc false defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do - unless Module.has_attribute?(__MODULE__, :doc) do + if !Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/task/supervised.ex b/lib/elixir/lib/task/supervised.ex index c0da3b76541..f58b5c01c39 100644 --- a/lib/elixir/lib/task/supervised.ex +++ b/lib/elixir/lib/task/supervised.ex @@ -209,15 +209,15 @@ defmodule Task.Supervised do ordered = Keyword.get(options, :ordered, true) zip_input_on_exit = Keyword.get(options, :zip_input_on_exit, false) - unless is_integer(max_concurrency) and max_concurrency > 0 do + if !(is_integer(max_concurrency) and max_concurrency > 0) do raise ArgumentError, ":max_concurrency must be an integer greater than zero" end - unless on_timeout in [:exit, :kill_task] do + if on_timeout not in [:exit, :kill_task] do raise ArgumentError, ":on_timeout must be either :exit or :kill_task" end - unless (is_integer(timeout) and timeout >= 0) or timeout == :infinity do + if !((is_integer(timeout) and timeout >= 0) or timeout == :infinity) do raise ArgumentError, ":timeout must be either a positive integer or :infinity" end diff --git a/lib/elixir/lib/task/supervisor.ex b/lib/elixir/lib/task/supervisor.ex index c3367ff03df..bd10acf2dfd 100644 --- a/lib/elixir/lib/task/supervisor.ex +++ b/lib/elixir/lib/task/supervisor.ex @@ -614,7 +614,7 @@ defmodule Task.Supervisor do defp build_stream(supervisor, link_type, enumerable, fun, options) do shutdown = Keyword.get(options, :shutdown, 5000) - unless (is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill do + if !((is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill) do raise ArgumentError, ":shutdown must be either a positive integer or :brutal_kill" end diff --git a/lib/elixir/scripts/diff.exs b/lib/elixir/scripts/diff.exs index 4b0b6253672..56d4925d5e0 100644 --- a/lib/elixir/scripts/diff.exs +++ b/lib/elixir/scripts/diff.exs @@ -131,7 +131,7 @@ defmodule Diff do end defp assert_dir!(dir) do - unless File.dir?(dir) do + if !File.dir?(dir) do raise ArgumentError, "#{inspect(dir)} is not a directory" end end diff --git a/lib/elixir/test/elixir/file_test.exs b/lib/elixir/test/elixir/file_test.exs index aa4a6b03f6c..b76d8dd5f62 100644 --- a/lib/elixir/test/elixir/file_test.exs +++ b/lib/elixir/test/elixir/file_test.exs @@ -1794,7 +1794,7 @@ defmodule FileTest do stat = File.stat!(fixture) assert stat.mode == 0o100666 - unless windows?() do + if !windows?() do assert File.chmod(fixture, 0o100777) == :ok stat = File.stat!(fixture) assert stat.mode == 0o100777 @@ -1814,7 +1814,7 @@ defmodule FileTest do stat = File.stat!(fixture) assert stat.mode == 0o100666 - unless windows?() do + if !windows?() do assert File.chmod!(fixture, 0o100777) == :ok stat = File.stat!(fixture) assert stat.mode == 0o100777 diff --git a/lib/elixir/test/elixir/kernel/cli_test.exs b/lib/elixir/test/elixir/kernel/cli_test.exs index 0d402249d02..44634487d4e 100644 --- a/lib/elixir/test/elixir/kernel/cli_test.exs +++ b/lib/elixir/test/elixir/kernel/cli_test.exs @@ -95,7 +95,7 @@ defmodule Kernel.CLI.ExecutableTest do System.cmd(elixir_executable(context.cli_extension), ["-e", "Time.new!(0, 0, 0)"]) # TODO: remove this once we bump CI to 26.3 - unless windows?() and System.otp_release() == "26" do + if !(windows?() and System.otp_release() == "26") do {output, 0} = System.cmd(iex_executable(context.cli_extension), [ "--eval", diff --git a/lib/elixir/test/elixir/kernel/dialyzer_test.exs b/lib/elixir/test/elixir/kernel/dialyzer_test.exs index 0f730123ba2..918b7fe0188 100644 --- a/lib/elixir/test/elixir/kernel/dialyzer_test.exs +++ b/lib/elixir/test/elixir/kernel/dialyzer_test.exs @@ -17,7 +17,7 @@ defmodule Kernel.DialyzerTest do |> String.to_charlist() # Some OSs (like Windows) do not provide the HOME environment variable. - unless System.get_env("HOME") do + if !System.get_env("HOME") do System.put_env("HOME", System.user_home()) end diff --git a/lib/elixir/test/elixir/macro_test.exs b/lib/elixir/test/elixir/macro_test.exs index 15004ed8db9..fddf72859b1 100644 --- a/lib/elixir/test/elixir/macro_test.exs +++ b/lib/elixir/test/elixir/macro_test.exs @@ -648,7 +648,7 @@ defmodule MacroTest do {result, formatted} = dbg_format( - unless true and x do + if !(true and x) do map[:a] * 2 else map[:b] diff --git a/lib/elixir/test/elixir/supervisor_test.exs b/lib/elixir/test/elixir/supervisor_test.exs index a67cf389ca9..d4b469fc9f7 100644 --- a/lib/elixir/test/elixir/supervisor_test.exs +++ b/lib/elixir/test/elixir/supervisor_test.exs @@ -277,7 +277,7 @@ defmodule SupervisorTest do end defp wait_until_registered(name) do - unless Process.whereis(name) do + if !Process.whereis(name) do wait_until_registered(name) end end diff --git a/lib/elixir/test/elixir/system_test.exs b/lib/elixir/test/elixir/system_test.exs index dd6b85db966..f2f782d7c27 100644 --- a/lib/elixir/test/elixir/system_test.exs +++ b/lib/elixir/test/elixir/system_test.exs @@ -128,7 +128,7 @@ defmodule SystemTest do # There is a bug in OTP where find_executable is finding # entries on the current directory. If this is the case, # we should avoid the assertion below. - unless System.find_executable(@echo) do + if !System.find_executable(@echo) do assert :enoent = catch_error(System.cmd(@echo, ~w[/c echo hello])) end @@ -212,7 +212,7 @@ defmodule SystemTest do # There is a bug in OTP where find_executable is finding # entries on the current directory. If this is the case, # we should avoid the assertion below. - unless System.find_executable(@echo) do + if !System.find_executable(@echo) do assert :enoent = catch_error(System.cmd(@echo, ["hello"])) end diff --git a/lib/ex_unit/lib/ex_unit/assertions.ex b/lib/ex_unit/lib/ex_unit/assertions.ex index 1abd2b0899d..62835ce9751 100644 --- a/lib/ex_unit/lib/ex_unit/assertions.ex +++ b/lib/ex_unit/lib/ex_unit/assertions.ex @@ -410,7 +410,7 @@ defmodule ExUnit.Assertions do end def assert(value, opts) when is_list(opts) do - unless value, do: raise(ExUnit.AssertionError, opts) + if !value, do: raise(ExUnit.AssertionError, opts) true end @@ -780,7 +780,7 @@ defmodule ExUnit.Assertions do "expected:\n #{inspect(message)}\n" <> "actual:\n" <> " #{inspect(Exception.message(error))}" - unless match?, do: flunk(message) + if !match?, do: flunk(message) error end diff --git a/lib/ex_unit/lib/ex_unit/callbacks.ex b/lib/ex_unit/lib/ex_unit/callbacks.ex index a4ce29d2ee5..9b188de1fd9 100644 --- a/lib/ex_unit/lib/ex_unit/callbacks.ex +++ b/lib/ex_unit/lib/ex_unit/callbacks.ex @@ -243,7 +243,7 @@ defmodule ExUnit.Callbacks do """ defmacro setup(context, block) do - unless Keyword.keyword?(block) and Keyword.has_key?(block, :do) do + if !(Keyword.keyword?(block) and Keyword.has_key?(block, :do)) do raise ArgumentError, "setup/2 requires a block as the second argument after the context, got: #{Macro.to_string(block)}" end @@ -378,7 +378,7 @@ defmodule ExUnit.Callbacks do """ defmacro setup_all(context, block) do - unless Keyword.keyword?(block) and Keyword.has_key?(block, :do) do + if !(Keyword.keyword?(block) and Keyword.has_key?(block, :do)) do raise ArgumentError, "setup_all/2 requires a block as the second argument after the context, got: #{Macro.to_string(block)}" end diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index f73c4c723c7..6f82ce061f6 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -299,7 +299,7 @@ defmodule ExUnit.Case do @doc false defmacro __using__(opts) do quote do - unless ExUnit.Case.__register__(__MODULE__, unquote(opts)) do + if !ExUnit.Case.__register__(__MODULE__, unquote(opts)) do use ExUnit.Callbacks end @@ -312,7 +312,7 @@ defmodule ExUnit.Case do @doc false def __register__(module, opts) do - unless Keyword.keyword?(opts) do + if !Keyword.keyword?(opts) do raise ArgumentError, ~s(the argument passed to "use ExUnit.Case" must be a list of options, ) <> ~s(got: #{inspect(opts)}) @@ -322,7 +322,7 @@ defmodule ExUnit.Case do {async?, opts} = Keyword.pop(opts, :async, false) {parameterize, opts} = Keyword.pop(opts, :parameterize, nil) - unless parameterize == nil or (is_list(parameterize) and Enum.all?(parameterize, &is_map/1)) do + if !(parameterize == nil or (is_list(parameterize) and Enum.all?(parameterize, &is_map/1))) do raise ArgumentError, ":parameterize must be a list of maps, got: #{inspect(parameterize)}" end @@ -332,7 +332,7 @@ defmodule ExUnit.Case do registered? = Module.has_attribute?(module, :ex_unit_tests) - unless registered? do + if !registered? do tag_check = Enum.any?([:moduletag, :describetag, :tag], &Module.has_attribute?(module, &1)) if tag_check do @@ -381,7 +381,7 @@ defmodule ExUnit.Case do """ defmacro test(message, var \\ quote(do: _), contents) do - unless is_tuple(var) do + if !is_tuple(var) do IO.warn( "test context is always a map. The pattern " <> "#{inspect(Macro.to_string(var))} will never match", @@ -602,7 +602,7 @@ defmodule ExUnit.Case do """ @doc since: "1.11.0" def register_test(mod, file, line, test_type, name, tags) do - unless Module.has_attribute?(mod, :ex_unit_tests) do + if !Module.has_attribute?(mod, :ex_unit_tests) do raise "cannot define #{test_type}. Please make sure you have invoked " <> "\"use ExUnit.Case\" in the current module" end @@ -846,7 +846,7 @@ defmodule ExUnit.Case do raise "cannot set tag #{inspect(tag)} because it is reserved by ExUnit" end - unless is_atom(tags[:test_type]) do + if not is_atom(tags[:test_type]) do raise("value for tag \":test_type\" must be an atom") end diff --git a/lib/ex_unit/test/ex_unit/supervised_test.exs b/lib/ex_unit/test/ex_unit/supervised_test.exs index d8bd311a3e0..295d4424a6c 100644 --- a/lib/ex_unit/test/ex_unit/supervised_test.exs +++ b/lib/ex_unit/test/ex_unit/supervised_test.exs @@ -149,7 +149,7 @@ defmodule ExUnit.SupervisedTest do end defp wait_until_registered(name) do - unless Process.whereis(name) do + if !Process.whereis(name) do wait_until_registered(name) end end diff --git a/lib/iex/lib/iex.ex b/lib/iex/lib/iex.ex index 2d31c1a00ab..7215b5ef3cc 100644 --- a/lib/iex/lib/iex.ex +++ b/lib/iex/lib/iex.ex @@ -716,7 +716,7 @@ defmodule IEx do defp __break__!(ast, module, fun, args, guards, stops, env) do module = Macro.expand(module, env) - unless is_atom(module) do + if not is_atom(module) do raise_unknown_break_ast!(ast) end diff --git a/lib/iex/lib/iex/evaluator.ex b/lib/iex/lib/iex/evaluator.ex index 5f1bae9820a..4de5dc74d25 100644 --- a/lib/iex/lib/iex/evaluator.ex +++ b/lib/iex/lib/iex/evaluator.ex @@ -335,7 +335,7 @@ defmodule IEx.Evaluator do forms = add_if_undefined_apply_to_vars(forms, env) {result, binding, env} = eval_expr_by_expr(forms, binding, env) - unless result == IEx.dont_display_result() do + if result != IEx.dont_display_result() do io_inspect(result) end diff --git a/lib/iex/lib/iex/helpers.ex b/lib/iex/lib/iex/helpers.ex index 1979fb83691..5b2da3ea8ba 100644 --- a/lib/iex/lib/iex/helpers.ex +++ b/lib/iex/lib/iex/helpers.ex @@ -205,13 +205,13 @@ defmodule IEx.Helpers do def c(files, path \\ :in_memory) when is_binary(path) or path == :in_memory do files = List.wrap(files) - unless Enum.all?(files, &is_binary/1) do + if !Enum.all?(files, &is_binary/1) do raise ArgumentError, "expected a binary or a list of binaries as argument" end {found, not_found} = Enum.split_with(files, &File.exists?/1) - unless Enum.empty?(not_found) do + if !Enum.empty?(not_found) do raise ArgumentError, "could not find files #{Enum.join(not_found, ", ")}" end @@ -462,7 +462,7 @@ defmodule IEx.Helpers do sources = Enum.map(modules, fn module -> - unless Code.ensure_loaded?(module) do + if !Code.ensure_loaded?(module) do raise ArgumentError, "could not load nor find module: #{inspect(module)}" end diff --git a/lib/logger/lib/logger/backends/internal.ex b/lib/logger/lib/logger/backends/internal.ex index f92a305fe07..e8ba149c05c 100644 --- a/lib/logger/lib/logger/backends/internal.ex +++ b/lib/logger/lib/logger/backends/internal.ex @@ -98,7 +98,7 @@ defmodule Logger.Backends.Internal do ## Supervisor callbacks defp ensure_started() do - unless Process.whereis(@name) do + if !Process.whereis(@name) do Supervisor.start_child(Logger.Supervisor, __MODULE__) end diff --git a/lib/logger/test/test_helper.exs b/lib/logger/test/test_helper.exs index 4cd2ad563fb..fa35525c258 100644 --- a/lib/logger/test/test_helper.exs +++ b/lib/logger/test/test_helper.exs @@ -22,7 +22,7 @@ defmodule Logger.Case do end def wait_for_handler(manager, handler) do - unless handler in :gen_event.which_handlers(manager) do + if handler not in :gen_event.which_handlers(manager) do Process.sleep(10) wait_for_handler(manager, handler) end diff --git a/lib/mix/lib/mix.ex b/lib/mix/lib/mix.ex index 207496ab7ce..e79fe2ec2ed 100644 --- a/lib/mix/lib/mix.ex +++ b/lib/mix/lib/mix.ex @@ -640,7 +640,7 @@ defmodule Mix do ) %{} -> - unless app in optional do + if app not in optional do Mix.raise( "The application \"#{app}\" could not be found. This may happen if your " <> "Operating System broke Erlang into multiple packages and may be fixed " <> @@ -998,7 +998,7 @@ defmodule Mix do _ -> Mix.raise("unknown dependency #{inspect(app_name)} given to #{inspect(key)}") end - unless app_dir do + if !app_dir do Mix.raise("#{inspect(app_name)} given to #{inspect(key)} must be a path dependency") end diff --git a/lib/mix/lib/mix/dep.ex b/lib/mix/lib/mix/dep.ex index 2208910fd5f..73c027b120f 100644 --- a/lib/mix/lib/mix/dep.ex +++ b/lib/mix/lib/mix/dep.ex @@ -206,7 +206,7 @@ defmodule Mix.Dep do end Enum.each(apps, fn app -> - unless Enum.any?(all_deps, &(&1.app == app)) do + if !Enum.any?(all_deps, &(&1.app == app)) do Mix.raise("Unknown dependency #{app} for environment #{Mix.env()}") end end) diff --git a/lib/mix/lib/mix/dep/loader.ex b/lib/mix/lib/mix/dep/loader.ex index 79d1d6935b5..9be3db7ba66 100644 --- a/lib/mix/lib/mix/dep/loader.ex +++ b/lib/mix/lib/mix/dep/loader.ex @@ -167,7 +167,7 @@ defmodule Mix.Dep.Loader do end defp with_scm_and_app(app, req, opts, original, locked?) do - unless Keyword.keyword?(opts) do + if !Keyword.keyword?(opts) do invalid_dep_format(original) end @@ -192,7 +192,7 @@ defmodule Mix.Dep.Loader do {scm, opts} end - unless scm do + if !scm do Mix.raise( "Could not find an SCM for dependency #{inspect(app)} from #{inspect(Mix.Project.get())}" ) diff --git a/lib/mix/lib/mix/dep/lock.ex b/lib/mix/lib/mix/dep/lock.ex index 248831caf0a..055be84925a 100644 --- a/lib/mix/lib/mix/dep/lock.ex +++ b/lib/mix/lib/mix/dep/lock.ex @@ -30,7 +30,7 @@ defmodule Mix.Dep.Lock do def write(map, opts \\ []) do lockfile = opts[:file] || lockfile() - unless map == read() do + if map != read() do if Keyword.get(opts, :check_locked, false) do Mix.raise( "Your #{lockfile} is out of date and must be updated without the --check-locked flag" diff --git a/lib/mix/lib/mix/generator.ex b/lib/mix/lib/mix/generator.ex index 2551b8ecb38..2eeba1c7453 100644 --- a/lib/mix/lib/mix/generator.ex +++ b/lib/mix/lib/mix/generator.ex @@ -160,7 +160,7 @@ defmodule Mix.Generator do end defp log(color, command, message, opts) do - unless opts[:quiet] do + if !opts[:quiet] do Mix.shell().info([color, "* #{command} ", :reset, message]) end end diff --git a/lib/mix/lib/mix/local.ex b/lib/mix/lib/mix/local.ex index edca321bed3..2192e689f06 100644 --- a/lib/mix/lib/mix/local.ex +++ b/lib/mix/lib/mix/local.ex @@ -141,7 +141,7 @@ defmodule Mix.Local do case File.read(elixir) do {:ok, req} -> - unless Version.match?(System.version(), req) do + if !Version.match?(System.version(), req) do archive = ebin |> Path.dirname() |> Path.basename() Mix.shell().error( diff --git a/lib/mix/lib/mix/project.ex b/lib/mix/lib/mix/project.ex index d8c6e811aaa..6d9988d8ee9 100644 --- a/lib/mix/lib/mix/project.ex +++ b/lib/mix/lib/mix/project.ex @@ -188,13 +188,13 @@ defmodule Mix.Project do task = String.to_atom(task || config[:default_task] || "run") - unless System.get_env("MIX_ENV") do + if !System.get_env("MIX_ENV") do if env = config[:preferred_envs][task] || @preferred_envs[task] || config[:default_env] do Mix.env(env) end end - unless System.get_env("MIX_TARGET") do + if !System.get_env("MIX_TARGET") do if target = config[:preferred_targets][task] || config[:default_target] do Mix.target(target) end diff --git a/lib/mix/lib/mix/release.ex b/lib/mix/lib/mix/release.ex index 5e4fa474149..ea62c3f5612 100644 --- a/lib/mix/lib/mix/release.ex +++ b/lib/mix/lib/mix/release.ex @@ -75,7 +75,7 @@ defmodule Mix.Release do def from_config!(name, config, overrides) do {name, apps, opts} = find_release(name, config) - unless Atom.to_string(name) =~ ~r/^[a-z][a-z0-9_]*$/ do + if !(Atom.to_string(name) =~ ~r/^[a-z][a-z0-9_]*$/) do Mix.raise( "Invalid release name. A release name must start with a lowercase ASCII letter, " <> "followed by lowercase ASCII letters, numbers, or underscores, got: #{inspect(name)}" diff --git a/lib/mix/lib/mix/scm/git.ex b/lib/mix/lib/mix/scm/git.ex index 154df891263..4ff914dc7ee 100644 --- a/lib/mix/lib/mix/scm/git.ex +++ b/lib/mix/lib/mix/scm/git.ex @@ -197,7 +197,7 @@ defmodule Mix.SCM.Git do end defp ensure_feature_compatibility(version, required_version, feature) do - unless required_version <= version do + if not (required_version <= version) do Mix.raise( "Git >= #{format_version(required_version)} is required to use #{feature}. " <> "You are running version #{format_version(version)}" diff --git a/lib/mix/lib/mix/shell/io.ex b/lib/mix/lib/mix/shell/io.ex index d9c1809caef..6724e327e62 100644 --- a/lib/mix/lib/mix/shell/io.ex +++ b/lib/mix/lib/mix/shell/io.ex @@ -71,7 +71,7 @@ defmodule Mix.Shell.IO do def yes?(message, options \\ []) do default = Keyword.get(options, :default, :yes) - unless default in [:yes, :no] do + if default not in [:yes, :no] do raise ArgumentError, "expected :default to be either :yes or :no, got: #{inspect(default)}" end diff --git a/lib/mix/lib/mix/task.ex b/lib/mix/lib/mix/task.ex index 19440f297c8..8a2467d172b 100644 --- a/lib/mix/lib/mix/task.ex +++ b/lib/mix/lib/mix/task.ex @@ -397,7 +397,7 @@ defmodule Mix.Task do @doc since: "1.14.0" @spec run_in_apps(task_name, [atom], [any]) :: any def run_in_apps(task, apps, args \\ []) do - unless Mix.Project.umbrella?() do + if !Mix.Project.umbrella?() do Mix.raise( "Could not run #{inspect(task)} with the --app option because this is not an umbrella project" ) diff --git a/lib/mix/lib/mix/tasks/app.config.ex b/lib/mix/lib/mix/tasks/app.config.ex index 5afdc4dc913..39f147d2552 100644 --- a/lib/mix/lib/mix/tasks/app.config.ex +++ b/lib/mix/lib/mix/tasks/app.config.ex @@ -50,7 +50,7 @@ defmodule Mix.Tasks.App.Config do # # Therefore we let the application that owns the build path # to ultimately perform the check. - unless config[:build_path] do + if !config[:build_path] do check_configured() end end diff --git a/lib/mix/lib/mix/tasks/archive.build.ex b/lib/mix/lib/mix/tasks/archive.build.ex index 3c1f56a6bac..cc0e2c8ebc2 100644 --- a/lib/mix/lib/mix/tasks/archive.build.ex +++ b/lib/mix/lib/mix/tasks/archive.build.ex @@ -100,7 +100,7 @@ defmodule Mix.Tasks.Archive.Build do Mix.raise("Cannot create archive without output file, please pass -o as an option") end - unless File.dir?(source) do + if !File.dir?(source) do Mix.raise("Expected archive source #{inspect(source)} to be a directory") end diff --git a/lib/mix/lib/mix/tasks/compile.all.ex b/lib/mix/lib/mix/tasks/compile.all.ex index 89be926498e..9fe30f054f7 100644 --- a/lib/mix/lib/mix/tasks/compile.all.ex +++ b/lib/mix/lib/mix/tasks/compile.all.ex @@ -17,7 +17,7 @@ defmodule Mix.Tasks.Compile.All do # Compute the app cache if it is stale and we are # not compiling from a dependency. app_cache = - unless "--from-mix-deps-compile" in args do + if "--from-mix-deps-compile" not in args do Mix.AppLoader.stale_cache(config) end @@ -66,7 +66,7 @@ defmodule Mix.Tasks.Compile.All do Mix.AppLoader.write_cache(app_cache, Map.new(loaded_modules)) end - unless "--no-app-loading" in args do + if "--no-app-loading" not in args do app = config[:app] with {:ok, properties} <- Mix.AppLoader.load_app(app, "#{compile_path}/#{app}.app"), diff --git a/lib/mix/lib/mix/tasks/compile.app.ex b/lib/mix/lib/mix/tasks/compile.app.ex index 0dc525de427..fe8a209927d 100644 --- a/lib/mix/lib/mix/tasks/compile.app.ex +++ b/lib/mix/lib/mix/tasks/compile.app.ex @@ -211,7 +211,7 @@ defmodule Mix.Tasks.Compile.App do defp validate_version(version) do ensure_present(:version, version) - unless is_binary(version) and match?({:ok, _}, Version.parse(version)) do + if !(is_binary(version) and match?({:ok, _}, Version.parse(version))) do Mix.raise( "Expected :version to be a valid Version, got: #{inspect(version)} (see the Version module for more information)" ) @@ -240,7 +240,7 @@ defmodule Mix.Tasks.Compile.App do if function_exported?(project, :application, 0) do project_application = project.application() - unless Keyword.keyword?(project_application) do + if !Keyword.keyword?(project_application) do Mix.raise( "Application configuration returned from application/0 should be a keyword list" ) @@ -255,7 +255,7 @@ defmodule Mix.Tasks.Compile.App do defp validate_properties!(properties) do Enum.each(properties, fn {:description, value} -> - unless is_list(value) do + if !is_list(value) do Mix.raise( "Application description (:description) is not a character list, got: " <> inspect(value) @@ -263,17 +263,17 @@ defmodule Mix.Tasks.Compile.App do end {:id, value} -> - unless is_list(value) do + if !is_list(value) do Mix.raise("Application ID (:id) is not a character list, got: " <> inspect(value)) end {:vsn, value} -> - unless is_list(value) do + if !is_list(value) do Mix.raise("Application vsn (:vsn) is not a character list, got: " <> inspect(value)) end {:maxT, value} -> - unless value == :infinity or is_integer(value) do + if !(value == :infinity or is_integer(value)) do Mix.raise( "Application maximum time (:maxT) is not an integer or :infinity, got: " <> inspect(value) @@ -281,14 +281,14 @@ defmodule Mix.Tasks.Compile.App do end {:modules, value} -> - unless is_list(value) and Enum.all?(value, &is_atom(&1)) do + if !(is_list(value) and Enum.all?(value, &is_atom(&1))) do Mix.raise( "Application modules (:modules) should be a list of atoms, got: " <> inspect(value) ) end {:registered, value} -> - unless is_list(value) and Enum.all?(value, &is_atom(&1)) do + if !(is_list(value) and Enum.all?(value, &is_atom(&1))) do Mix.raise( "Application registered processes (:registered) should be a list of atoms, got: " <> inspect(value) @@ -296,7 +296,7 @@ defmodule Mix.Tasks.Compile.App do end {:included_applications, value} -> - unless is_list(value) and Enum.all?(value, &is_atom(&1)) do + if !(is_list(value) and Enum.all?(value, &is_atom(&1))) do Mix.raise( "Application included applications (:included_applications) should be a list of atoms, got: " <> inspect(value) @@ -304,7 +304,7 @@ defmodule Mix.Tasks.Compile.App do end {:extra_applications, value} -> - unless is_list(value) and Enum.all?(value, &typed_app?(&1)) do + if !(is_list(value) and Enum.all?(value, &typed_app?(&1))) do Mix.raise( "Application extra applications (:extra_applications) should be a list of atoms or " <> "{app, :required | :optional} pairs, got: " <> inspect(value) @@ -312,7 +312,7 @@ defmodule Mix.Tasks.Compile.App do end {:applications, value} -> - unless is_list(value) and Enum.all?(value, &typed_app?(&1)) do + if !(is_list(value) and Enum.all?(value, &typed_app?(&1))) do Mix.raise( "Application applications (:applications) should be a list of atoms or " <> "{app, :required | :optional} pairs, got: " <> inspect(value) @@ -320,14 +320,14 @@ defmodule Mix.Tasks.Compile.App do end {:env, value} -> - unless Keyword.keyword?(value) do + if !Keyword.keyword?(value) do Mix.raise( "Application environment (:env) should be a keyword list, got: " <> inspect(value) ) end {:start_phases, value} -> - unless Keyword.keyword?(value) do + if !Keyword.keyword?(value) do Mix.raise( "Application start phases (:start_phases) should be a keyword list, got: " <> inspect(value) diff --git a/lib/mix/lib/mix/tasks/compile.elixir.ex b/lib/mix/lib/mix/tasks/compile.elixir.ex index 59ecd89f8c9..cb15db4a73e 100644 --- a/lib/mix/lib/mix/tasks/compile.elixir.ex +++ b/lib/mix/lib/mix/tasks/compile.elixir.ex @@ -108,7 +108,7 @@ defmodule Mix.Tasks.Compile.Elixir do dest = Mix.Project.compile_path(project) srcs = project[:elixirc_paths] - unless is_list(srcs) do + if !is_list(srcs) do Mix.raise(":elixirc_paths should be a list of paths, got: #{inspect(srcs)}") end diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index be17dbbb7b2..9dfa7e3f4aa 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -60,7 +60,7 @@ defmodule Mix.Tasks.Compile.Erlang do compile_path = Erlang.to_erl_file(Mix.Project.compile_path(project)) erlc_options = project[:erlc_options] || [] - unless is_list(erlc_options) do + if !is_list(erlc_options) do Mix.raise(":erlc_options should be a list of options, got: #{inspect(erlc_options)}") end diff --git a/lib/mix/lib/mix/tasks/compile.leex.ex b/lib/mix/lib/mix/tasks/compile.leex.ex index c4f7e47e090..d3f6ebc0173 100644 --- a/lib/mix/lib/mix/tasks/compile.leex.ex +++ b/lib/mix/lib/mix/tasks/compile.leex.ex @@ -51,7 +51,7 @@ defmodule Mix.Tasks.Compile.Leex do leex_options = project[:leex_options] || [] - unless is_list(leex_options) do + if !is_list(leex_options) do Mix.raise(":leex_options should be a list of options, got: #{inspect(leex_options)}") end @@ -65,7 +65,7 @@ defmodule Mix.Tasks.Compile.Leex do defp preload(project) do # TODO: Remove me in Elixir v2.0 - unless :leex in List.wrap(project[:compilers]) do + if :leex not in List.wrap(project[:compilers]) do Mix.shell().error( "warning: in order to compile .xrl files, you must add \"compilers: [:leex] ++ Mix.compilers()\" to the \"def project\" section of #{project[:app]}'s mix.exs" ) diff --git a/lib/mix/lib/mix/tasks/compile.yecc.ex b/lib/mix/lib/mix/tasks/compile.yecc.ex index 044f244e32d..5d9924224da 100644 --- a/lib/mix/lib/mix/tasks/compile.yecc.ex +++ b/lib/mix/lib/mix/tasks/compile.yecc.ex @@ -52,7 +52,7 @@ defmodule Mix.Tasks.Compile.Yecc do yecc_options = project[:yecc_options] || [] - unless is_list(yecc_options) do + if !is_list(yecc_options) do Mix.raise(":yecc_options should be a list of options, got: #{inspect(yecc_options)}") end @@ -66,7 +66,7 @@ defmodule Mix.Tasks.Compile.Yecc do defp preload(project) do # TODO: Remove me in Elixir v2.0 - unless :yecc in List.wrap(project[:compilers]) do + if :yecc not in List.wrap(project[:compilers]) do Mix.shell().error( "warning: in order to compile .yrl files, you must add \"compilers: [:yecc] ++ Mix.compilers()\" to the \"def project\" section of #{project[:app]}'s mix.exs" ) diff --git a/lib/mix/lib/mix/tasks/deps.compile.ex b/lib/mix/lib/mix/tasks/deps.compile.ex index c34d1dc82ad..60a5447324f 100644 --- a/lib/mix/lib/mix/tasks/deps.compile.ex +++ b/lib/mix/lib/mix/tasks/deps.compile.ex @@ -48,7 +48,7 @@ defmodule Mix.Tasks.Deps.Compile do @impl true def run(args) do - unless "--no-archives-check" in args do + if "--no-archives-check" not in args do Mix.Task.run("archive.check", args) end @@ -180,7 +180,7 @@ defmodule Mix.Tasks.Deps.Compile do end defp do_rebar3(%Mix.Dep{opts: opts} = dep, config) do - unless Mix.Rebar.available?(:rebar3) do + if !Mix.Rebar.available?(:rebar3) do handle_rebar_not_found(dep) end @@ -247,7 +247,7 @@ defmodule Mix.Tasks.Deps.Compile do "Shall I install #{manager}? (if running non-interactively, " <> "use \"mix local.rebar --force\")" - unless shell.yes?(install_question) do + if !shell.yes?(install_question) do error_message = "Could not find \"#{manager}\" to compile " <> "dependency #{inspect(app)}, please ensure \"#{manager}\" is available" @@ -257,7 +257,7 @@ defmodule Mix.Tasks.Deps.Compile do Mix.Tasks.Local.Rebar.run(["--force"]) - unless Mix.Rebar.available?(manager) do + if !Mix.Rebar.available?(manager) do Mix.raise("\"#{manager}\" installation failed") end end diff --git a/lib/mix/lib/mix/tasks/deps.get.ex b/lib/mix/lib/mix/tasks/deps.get.ex index 451260ff463..4e63c218bea 100644 --- a/lib/mix/lib/mix/tasks/deps.get.ex +++ b/lib/mix/lib/mix/tasks/deps.get.ex @@ -17,7 +17,7 @@ defmodule Mix.Tasks.Deps.Get do @impl true def run(args) do - unless "--no-archives-check" in args do + if "--no-archives-check" not in args do Mix.Task.run("archive.check", args) end diff --git a/lib/mix/lib/mix/tasks/deps.loadpaths.ex b/lib/mix/lib/mix/tasks/deps.loadpaths.ex index cbb4bef6ecf..a244dd207d8 100644 --- a/lib/mix/lib/mix/tasks/deps.loadpaths.ex +++ b/lib/mix/lib/mix/tasks/deps.loadpaths.ex @@ -25,7 +25,7 @@ defmodule Mix.Tasks.Deps.Loadpaths do @impl true def run(args) do - unless "--no-archives-check" in args do + if "--no-archives-check" not in args do Mix.Task.run("archive.check", args) end @@ -40,15 +40,15 @@ defmodule Mix.Tasks.Deps.Loadpaths do config = Mix.Project.config() - unless "--no-elixir-version-check" in args do + if "--no-elixir-version-check" not in args do check_elixir_version(config) end - unless "--no-deps-check" in args do + if "--no-deps-check" not in args do deps_check(all, "--no-compile" in args) end - unless "--no-path-loading" in args do + if "--no-path-loading" not in args do Code.prepend_paths(Enum.flat_map(all, &Mix.Dep.load_paths/1), cache: true) end @@ -59,7 +59,7 @@ defmodule Mix.Tasks.Deps.Loadpaths do if req = config[:elixir] do case Version.parse_requirement(req) do {:ok, req} -> - unless Version.match?(System.version(), req) do + if !Version.match?(System.version(), req) do raise Mix.ElixirVersionError, target: config[:app] || Mix.Project.get(), expected: req, diff --git a/lib/mix/lib/mix/tasks/deps.unlock.ex b/lib/mix/lib/mix/tasks/deps.unlock.ex index c0a601269b8..eb72786254c 100644 --- a/lib/mix/lib/mix/tasks/deps.unlock.ex +++ b/lib/mix/lib/mix/tasks/deps.unlock.ex @@ -35,7 +35,7 @@ defmodule Mix.Tasks.Deps.Unlock do lock = Mix.Dep.Lock.read() unused_apps = unused_apps(lock) - unless unused_apps == [] do + if unused_apps != [] do Mix.raise(""" Unused dependencies in mix.lock file: @@ -47,7 +47,7 @@ defmodule Mix.Tasks.Deps.Unlock do lock = Mix.Dep.Lock.read() unused_apps = unused_apps(lock) - unless unused_apps == [] do + if unused_apps != [] do unlock(lock, unused_apps) end @@ -92,7 +92,7 @@ defmodule Mix.Tasks.Deps.Unlock do end defp unlock(lock, apps) do - unless apps == [] do + if apps != [] do lock |> Map.drop(apps) |> Mix.Dep.Lock.write() Mix.shell().info(""" diff --git a/lib/mix/lib/mix/tasks/deps.update.ex b/lib/mix/lib/mix/tasks/deps.update.ex index d6666e2a0db..d74a0b105c3 100644 --- a/lib/mix/lib/mix/tasks/deps.update.ex +++ b/lib/mix/lib/mix/tasks/deps.update.ex @@ -36,7 +36,7 @@ defmodule Mix.Tasks.Deps.Update do @impl true def run(args) do - unless "--no-archives-check" in args do + if "--no-archives-check" not in args do Mix.Task.run("archive.check", args) end diff --git a/lib/mix/lib/mix/tasks/escript.build.ex b/lib/mix/lib/mix/tasks/escript.build.ex index 43cb7d60614..96f80254ed5 100644 --- a/lib/mix/lib/mix/tasks/escript.build.ex +++ b/lib/mix/lib/mix/tasks/escript.build.ex @@ -147,7 +147,7 @@ defmodule Mix.Tasks.Escript.Build do filename = escript_opts[:path] || script_name main = escript_opts[:main_module] - unless main do + if !main do error_message = "Could not generate escript, please set :main_module " <> "in your project configuration (under :escript option) to a module that implements main/1" @@ -155,7 +155,7 @@ defmodule Mix.Tasks.Escript.Build do Mix.raise(error_message) end - unless Code.ensure_loaded?(main) do + if !Code.ensure_loaded?(main) do error_message = "Could not generate escript, module #{main} defined as " <> ":main_module could not be loaded" diff --git a/lib/mix/lib/mix/tasks/format.ex b/lib/mix/lib/mix/tasks/format.ex index e07d740703d..e4bdbed1c1d 100644 --- a/lib/mix/lib/mix/tasks/format.ex +++ b/lib/mix/lib/mix/tasks/format.ex @@ -505,7 +505,7 @@ defmodule Mix.Tasks.Format do defp eval_file_with_keyword_list(path) do {opts, _} = Code.eval_file(path) - unless Keyword.keyword?(opts) do + if !Keyword.keyword?(opts) do Mix.raise("Expected #{inspect(path)} to return a keyword list, got: #{inspect(opts)}") end diff --git a/lib/mix/lib/mix/tasks/loadpaths.ex b/lib/mix/lib/mix/tasks/loadpaths.ex index 71a6f445903..2a9e12d515d 100644 --- a/lib/mix/lib/mix/tasks/loadpaths.ex +++ b/lib/mix/lib/mix/tasks/loadpaths.ex @@ -33,7 +33,7 @@ defmodule Mix.Tasks.Loadpaths do # recursively checking and loading dependencies that have # already been loaded. It has no purpose from Mix.CLI # because running a task may load deps. - unless "--from-mix-deps-compile" in args do + if "--from-mix-deps-compile" not in args do Mix.Task.run("deps.loadpaths", args) end @@ -61,7 +61,7 @@ defmodule Mix.Tasks.Loadpaths do :ok end - unless "--no-path-loading" in args do + if "--no-path-loading" not in args do # We don't cache the current application as we may still write to it Code.prepend_path(Mix.Project.compile_path(config)) end diff --git a/lib/mix/lib/mix/tasks/new.ex b/lib/mix/lib/mix/tasks/new.ex index f8607210e37..0f3cea5a910 100644 --- a/lib/mix/lib/mix/tasks/new.ex +++ b/lib/mix/lib/mix/tasks/new.ex @@ -69,7 +69,7 @@ defmodule Mix.Tasks.New do check_mod_name_validity!(mod) check_mod_name_availability!(mod) - unless path == "." do + if path != "." do check_directory_existence!(path) File.mkdir_p!(path) end @@ -195,7 +195,7 @@ defmodule Mix.Tasks.New do end defp invalid_app(name) do - unless name =~ ~r/^[a-z][a-z0-9_]*$/ do + if !(name =~ ~r/^[a-z][a-z0-9_]*$/) do "Application name must start with a lowercase ASCII letter, followed by " <> "lowercase ASCII letters, numbers, or underscores, got: #{inspect(name)}" end @@ -210,7 +210,7 @@ defmodule Mix.Tasks.New do end defp check_mod_name_validity!(name) do - unless name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/ do + if !(name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/) do Mix.raise( "Module name must be a valid Elixir alias (for example: Foo.Bar), got: #{inspect(name)}" ) diff --git a/lib/mix/lib/mix/tasks/release.ex b/lib/mix/lib/mix/tasks/release.ex index d5c00209020..5829dea821e 100644 --- a/lib/mix/lib/mix/tasks/release.ex +++ b/lib/mix/lib/mix/tasks/release.ex @@ -1357,7 +1357,7 @@ defmodule Mix.Tasks.Release do end defp info(release, message) do - unless release.options[:quiet] do + if !release.options[:quiet] do Mix.shell().info(message) end end diff --git a/lib/mix/lib/mix/tasks/run.ex b/lib/mix/lib/mix/tasks/run.ex index 9b7a50523b0..52e2fad50aa 100644 --- a/lib/mix/lib/mix/tasks/run.ex +++ b/lib/mix/lib/mix/tasks/run.ex @@ -83,7 +83,7 @@ defmodule Mix.Tasks.Run do ) run(args, opts, head, &Code.eval_string/1, &Code.require_file/1) - unless Keyword.get(opts, :halt, true), do: System.no_halt(true) + if !Keyword.get(opts, :halt, true), do: System.no_halt(true) Mix.Task.reenable("run") :ok end diff --git a/lib/mix/lib/mix/tasks/test.ex b/lib/mix/lib/mix/tasks/test.ex index 9f19a9e828c..7b73af1e905 100644 --- a/lib/mix/lib/mix/tasks/test.ex +++ b/lib/mix/lib/mix/tasks/test.ex @@ -512,7 +512,7 @@ defmodule Mix.Tasks.Test do defp do_run(opts, args, files) do _ = Mix.Project.get!() - unless System.get_env("MIX_ENV") || Mix.env() == :test do + if !(System.get_env("MIX_ENV") || Mix.env() == :test) do Mix.raise(""" "mix test" is running in the \"#{Mix.env()}\" environment. If you are \ running tests from within another command, you can either: diff --git a/lib/mix/lib/mix/utils.ex b/lib/mix/lib/mix/utils.ex index 63933c6a943..81954e49f3e 100644 --- a/lib/mix/lib/mix/utils.ex +++ b/lib/mix/lib/mix/utils.ex @@ -512,7 +512,7 @@ defmodule Mix.Utils do do_symlink_or_copy(source, target, link) {:error, _} -> - unless File.dir?(target) do + if !File.dir?(target) do File.rm_rf!(target) end diff --git a/lib/mix/test/mix/release_test.exs b/lib/mix/test/mix/release_test.exs index e42386450a9..a7c352b1651 100644 --- a/lib/mix/test/mix/release_test.exs +++ b/lib/mix/test/mix/release_test.exs @@ -659,7 +659,7 @@ defmodule Mix.ReleaseTest do assert File.read!(Path.join(destination, "bin/erl")) =~ ~s|ROOTDIR="${ERL_ROOTDIR:-"$(dirname "$(dirname "$BINDIR")")"}| - unless match?({:win32, _}, :os.type()) do + if !match?({:win32, _}, :os.type()) do assert File.lstat!(Path.join(destination, "bin/erl")).mode |> rem(0o1000) == 0o755 end diff --git a/lib/mix/test/test_helper.exs b/lib/mix/test/test_helper.exs index 874d27910e9..8c0f9fb174d 100644 --- a/lib/mix/test/test_helper.exs +++ b/lib/mix/test/test_helper.exs @@ -263,7 +263,7 @@ System.cmd("git", ~w[config --global init.defaultBranch not-main]) ### Git repo target = Path.expand("fixtures/git_repo", __DIR__) -unless File.dir?(target) do +if !File.dir?(target) do File.mkdir_p!(Path.join(target, "lib")) File.write!(Path.join(target, "mix.exs"), """ @@ -345,7 +345,7 @@ end ### Deps on Git repo target = Path.expand("fixtures/deps_on_git_repo", __DIR__) -unless File.dir?(target) do +if !File.dir?(target) do File.mkdir_p!(Path.join(target, "lib")) File.write!(Path.join(target, "mix.exs"), """ @@ -401,7 +401,7 @@ end # Git Rebar target = Path.expand("fixtures/git_rebar", __DIR__) -unless File.dir?(target) do +if !File.dir?(target) do File.mkdir_p!(Path.join(target, "ebin")) File.mkdir_p!(Path.join(target, "src")) @@ -439,7 +439,7 @@ end) ### Archive ebin target = Path.expand("fixtures/archive", __DIR__) -unless File.dir?(Path.join(target, "ebin")) do +if !File.dir?(Path.join(target, "ebin")) do File.mkdir_p!(Path.join(target, "ebin")) File.write!(Path.join([target, "ebin", "local_sample.app"]), """ From 4a3cc20e910052354172f3161b5efefc41089afb Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 9 Aug 2024 14:29:27 +0900 Subject: [PATCH 3/8] Fix breaking change in Kernel --- lib/elixir/lib/kernel.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/elixir/lib/kernel.ex b/lib/elixir/lib/kernel.ex index a586da9fa09..68b779a5755 100644 --- a/lib/elixir/lib/kernel.ex +++ b/lib/elixir/lib/kernel.ex @@ -3956,7 +3956,7 @@ defmodule Kernel do "Math still works" """ - defmacro if(!condition, clauses) do + defmacro unless(condition, clauses) do build_unless(condition, clauses) end From a8aba2a821584fb7e7fd13513d7c4e46b2789c3b Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 9 Aug 2024 14:34:12 +0900 Subject: [PATCH 4/8] Manual fixes where boolean is known --- lib/elixir/lib/agent.ex | 2 +- lib/elixir/lib/config.ex | 2 +- lib/elixir/lib/dynamic_supervisor.ex | 2 +- lib/elixir/lib/gen_server.ex | 2 +- lib/elixir/lib/kernel/typespec.ex | 10 +++++----- lib/elixir/lib/module.ex | 4 ++-- lib/elixir/lib/partition_supervisor.ex | 4 ++-- lib/elixir/lib/registry.ex | 6 +++--- lib/elixir/lib/supervisor.ex | 2 +- lib/elixir/lib/task.ex | 2 +- lib/ex_unit/lib/ex_unit/case.ex | 6 +++--- lib/mix/lib/mix/dep/loader.ex | 2 +- lib/mix/lib/mix/tasks/compile.app.ex | 12 ++++++------ lib/mix/lib/mix/tasks/compile.elixir.ex | 2 +- lib/mix/lib/mix/tasks/compile.erlang.ex | 2 +- lib/mix/lib/mix/tasks/compile.leex.ex | 2 +- lib/mix/lib/mix/tasks/compile.yecc.ex | 2 +- lib/mix/lib/mix/tasks/format.ex | 2 +- 18 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/elixir/lib/agent.ex b/lib/elixir/lib/agent.ex index 74758e6798d..b1a3bc654c7 100644 --- a/lib/elixir/lib/agent.ex +++ b/lib/elixir/lib/agent.ex @@ -207,7 +207,7 @@ defmodule Agent do @doc false defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do - if !Module.has_attribute?(__MODULE__, :doc) do + if not Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/config.ex b/lib/elixir/lib/config.ex index 107dd30b15b..4789219a717 100644 --- a/lib/elixir/lib/config.ex +++ b/lib/elixir/lib/config.ex @@ -143,7 +143,7 @@ defmodule Config do """ @doc since: "1.9.0" def config(root_key, opts) when is_atom(root_key) and is_list(opts) do - if !Keyword.keyword?(opts) do + if not Keyword.keyword?(opts) do raise ArgumentError, "config/2 expected a keyword list, got: #{inspect(opts)}" end diff --git a/lib/elixir/lib/dynamic_supervisor.ex b/lib/elixir/lib/dynamic_supervisor.ex index 76079dd3fd3..38ecd6c6a62 100644 --- a/lib/elixir/lib/dynamic_supervisor.ex +++ b/lib/elixir/lib/dynamic_supervisor.ex @@ -274,7 +274,7 @@ defmodule DynamicSupervisor do defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do @behaviour DynamicSupervisor - if !Module.has_attribute?(__MODULE__, :doc) do + if not Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/gen_server.ex b/lib/elixir/lib/gen_server.ex index fb571d73a93..c6acc5c523f 100644 --- a/lib/elixir/lib/gen_server.ex +++ b/lib/elixir/lib/gen_server.ex @@ -845,7 +845,7 @@ defmodule GenServer do quote location: :keep, bind_quoted: [opts: opts] do @behaviour GenServer - if !Module.has_attribute?(__MODULE__, :doc) do + if not Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/kernel/typespec.ex b/lib/elixir/lib/kernel/typespec.ex index 03af66a441e..7d7e7cbd864 100644 --- a/lib/elixir/lib/kernel/typespec.ex +++ b/lib/elixir/lib/kernel/typespec.ex @@ -118,7 +118,7 @@ defmodule Kernel.Typespec do case spec_to_signature(expr) do {name, arity} -> # store doc only once in case callback has multiple clauses - if !:ets.member(set, {kind, name, arity}) do + if not :ets.member(set, {kind, name, arity}) do {line, doc} = get_doc_info(set, :doc, line) store_doc(set, kind, name, arity, line, :doc, doc, %{}) end @@ -380,7 +380,7 @@ defmodule Kernel.Typespec do ensure_no_defaults!(args) state = clean_local_state(state) - if !Keyword.keyword?(guard) do + if not Keyword.keyword?(guard) do error = "expected keywords as guard in type specification, got: #{Macro.to_string(guard)}" compile_error(caller, error) end @@ -573,7 +573,7 @@ defmodule Kernel.Typespec do |> Map.delete(:__struct__) |> Map.to_list() - if !Keyword.keyword?(fields) do + if not Keyword.keyword?(fields) do compile_error(caller, "expected key-value pairs in struct #{Macro.to_string(name)}") end @@ -587,7 +587,7 @@ defmodule Kernel.Typespec do ) fun = fn {field, _} -> - if !Keyword.has_key?(struct, field) do + if not Keyword.has_key?(struct, field) do compile_error( caller, "undefined field #{inspect(field)} on struct #{inspect(module)}" @@ -630,7 +630,7 @@ defmodule Kernel.Typespec do ) fun = fn {field, _} -> - if !Keyword.has_key?(fields, field) do + if not Keyword.has_key?(fields, field) do compile_error(caller, "undefined field #{field} on record #{inspect(tag)}") end end diff --git a/lib/elixir/lib/module.ex b/lib/elixir/lib/module.ex index e4f823a0399..73367bccfc8 100644 --- a/lib/elixir/lib/module.ex +++ b/lib/elixir/lib/module.ex @@ -902,7 +902,7 @@ defmodule Module do end def create(module, quoted, opts) when is_atom(module) and is_list(opts) do - if !Keyword.has_key?(opts, :file) do + if not Keyword.has_key?(opts, :file) do raise ArgumentError, "expected :file to be given as option" end @@ -2260,7 +2260,7 @@ defmodule Module do end defp preprocess_attribute(:nifs, value) do - if !function_arity_list?(value) do + if not function_arity_list?(value) do raise ArgumentError, "@nifs is a built-in module attribute for specifying a list " <> "of functions and their arities that are NIFs, got: #{inspect(value)}" diff --git a/lib/elixir/lib/partition_supervisor.ex b/lib/elixir/lib/partition_supervisor.ex index f3557718292..14ef2905506 100644 --- a/lib/elixir/lib/partition_supervisor.ex +++ b/lib/elixir/lib/partition_supervisor.ex @@ -247,7 +247,7 @@ defmodule PartitionSupervisor do {with_arguments, opts} = Keyword.pop(opts, :with_arguments, fn args, _partition -> args end) - if !is_function(with_arguments, 2) do + if not is_function(with_arguments, 2) do raise ArgumentError, "the :with_arguments option must be a function that receives two arguments, " <> "the current call arguments and the partition, got: #{inspect(with_arguments)}" @@ -260,7 +260,7 @@ defmodule PartitionSupervisor do for partition <- 0..(partitions - 1) do args = with_arguments.(args, partition) - if !is_list(args) do + if not is_list(args) do raise "the call to the function in :with_arguments must return a list, got: #{inspect(args)}" end diff --git a/lib/elixir/lib/registry.ex b/lib/elixir/lib/registry.ex index e5dd199d864..e2b4b1c875e 100644 --- a/lib/elixir/lib/registry.ex +++ b/lib/elixir/lib/registry.ex @@ -350,7 +350,7 @@ defmodule Registry do meta = Keyword.get(options, :meta, []) - if !Keyword.keyword?(meta) do + if not Keyword.keyword?(meta) do raise ArgumentError, "expected :meta to be a keyword list, got: #{inspect(meta)}" end @@ -370,7 +370,7 @@ defmodule Registry do compressed = Keyword.get(options, :compressed, false) - if !is_boolean(compressed) do + if not is_boolean(compressed) do raise ArgumentError, "expected :compressed to be a boolean, got: #{inspect(compressed)}" end @@ -1433,7 +1433,7 @@ defmodule Registry do end defp unlink_if_unregistered(pid_server, pid_ets, self) do - if !:ets.member(pid_ets, self) do + if not :ets.member(pid_ets, self) do Process.unlink(pid_server) end end diff --git a/lib/elixir/lib/supervisor.ex b/lib/elixir/lib/supervisor.ex index a746c3a1d2b..0849aa7501a 100644 --- a/lib/elixir/lib/supervisor.ex +++ b/lib/elixir/lib/supervisor.ex @@ -525,7 +525,7 @@ defmodule Supervisor do import Supervisor.Spec @behaviour Supervisor - if !Module.has_attribute?(__MODULE__, :doc) do + if not Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/elixir/lib/task.ex b/lib/elixir/lib/task.ex index b0d91eb31b4..9eba4f452d2 100644 --- a/lib/elixir/lib/task.ex +++ b/lib/elixir/lib/task.ex @@ -329,7 +329,7 @@ defmodule Task do @doc false defmacro __using__(opts) do quote location: :keep, bind_quoted: [opts: opts] do - if !Module.has_attribute?(__MODULE__, :doc) do + if not Module.has_attribute?(__MODULE__, :doc) do @doc """ Returns a specification to start this module under a supervisor. diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index 6f82ce061f6..4fe86694e9f 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -312,7 +312,7 @@ defmodule ExUnit.Case do @doc false def __register__(module, opts) do - if !Keyword.keyword?(opts) do + if not Keyword.keyword?(opts) do raise ArgumentError, ~s(the argument passed to "use ExUnit.Case" must be a list of options, ) <> ~s(got: #{inspect(opts)}) @@ -381,7 +381,7 @@ defmodule ExUnit.Case do """ defmacro test(message, var \\ quote(do: _), contents) do - if !is_tuple(var) do + if not is_tuple(var) do IO.warn( "test context is always a map. The pattern " <> "#{inspect(Macro.to_string(var))} will never match", @@ -602,7 +602,7 @@ defmodule ExUnit.Case do """ @doc since: "1.11.0" def register_test(mod, file, line, test_type, name, tags) do - if !Module.has_attribute?(mod, :ex_unit_tests) do + if not Module.has_attribute?(mod, :ex_unit_tests) do raise "cannot define #{test_type}. Please make sure you have invoked " <> "\"use ExUnit.Case\" in the current module" end diff --git a/lib/mix/lib/mix/dep/loader.ex b/lib/mix/lib/mix/dep/loader.ex index 9be3db7ba66..e47bfc5568d 100644 --- a/lib/mix/lib/mix/dep/loader.ex +++ b/lib/mix/lib/mix/dep/loader.ex @@ -167,7 +167,7 @@ defmodule Mix.Dep.Loader do end defp with_scm_and_app(app, req, opts, original, locked?) do - if !Keyword.keyword?(opts) do + if not Keyword.keyword?(opts) do invalid_dep_format(original) end diff --git a/lib/mix/lib/mix/tasks/compile.app.ex b/lib/mix/lib/mix/tasks/compile.app.ex index fe8a209927d..73fadf7e147 100644 --- a/lib/mix/lib/mix/tasks/compile.app.ex +++ b/lib/mix/lib/mix/tasks/compile.app.ex @@ -240,7 +240,7 @@ defmodule Mix.Tasks.Compile.App do if function_exported?(project, :application, 0) do project_application = project.application() - if !Keyword.keyword?(project_application) do + if not Keyword.keyword?(project_application) do Mix.raise( "Application configuration returned from application/0 should be a keyword list" ) @@ -255,7 +255,7 @@ defmodule Mix.Tasks.Compile.App do defp validate_properties!(properties) do Enum.each(properties, fn {:description, value} -> - if !is_list(value) do + if not is_list(value) do Mix.raise( "Application description (:description) is not a character list, got: " <> inspect(value) @@ -263,12 +263,12 @@ defmodule Mix.Tasks.Compile.App do end {:id, value} -> - if !is_list(value) do + if not is_list(value) do Mix.raise("Application ID (:id) is not a character list, got: " <> inspect(value)) end {:vsn, value} -> - if !is_list(value) do + if not is_list(value) do Mix.raise("Application vsn (:vsn) is not a character list, got: " <> inspect(value)) end @@ -320,14 +320,14 @@ defmodule Mix.Tasks.Compile.App do end {:env, value} -> - if !Keyword.keyword?(value) do + if not Keyword.keyword?(value) do Mix.raise( "Application environment (:env) should be a keyword list, got: " <> inspect(value) ) end {:start_phases, value} -> - if !Keyword.keyword?(value) do + if not Keyword.keyword?(value) do Mix.raise( "Application start phases (:start_phases) should be a keyword list, got: " <> inspect(value) diff --git a/lib/mix/lib/mix/tasks/compile.elixir.ex b/lib/mix/lib/mix/tasks/compile.elixir.ex index cb15db4a73e..2b2d67d7739 100644 --- a/lib/mix/lib/mix/tasks/compile.elixir.ex +++ b/lib/mix/lib/mix/tasks/compile.elixir.ex @@ -108,7 +108,7 @@ defmodule Mix.Tasks.Compile.Elixir do dest = Mix.Project.compile_path(project) srcs = project[:elixirc_paths] - if !is_list(srcs) do + if not is_list(srcs) do Mix.raise(":elixirc_paths should be a list of paths, got: #{inspect(srcs)}") end diff --git a/lib/mix/lib/mix/tasks/compile.erlang.ex b/lib/mix/lib/mix/tasks/compile.erlang.ex index 9dfa7e3f4aa..301331b99ac 100644 --- a/lib/mix/lib/mix/tasks/compile.erlang.ex +++ b/lib/mix/lib/mix/tasks/compile.erlang.ex @@ -60,7 +60,7 @@ defmodule Mix.Tasks.Compile.Erlang do compile_path = Erlang.to_erl_file(Mix.Project.compile_path(project)) erlc_options = project[:erlc_options] || [] - if !is_list(erlc_options) do + if not is_list(erlc_options) do Mix.raise(":erlc_options should be a list of options, got: #{inspect(erlc_options)}") end diff --git a/lib/mix/lib/mix/tasks/compile.leex.ex b/lib/mix/lib/mix/tasks/compile.leex.ex index d3f6ebc0173..6ff6ec10678 100644 --- a/lib/mix/lib/mix/tasks/compile.leex.ex +++ b/lib/mix/lib/mix/tasks/compile.leex.ex @@ -51,7 +51,7 @@ defmodule Mix.Tasks.Compile.Leex do leex_options = project[:leex_options] || [] - if !is_list(leex_options) do + if not is_list(leex_options) do Mix.raise(":leex_options should be a list of options, got: #{inspect(leex_options)}") end diff --git a/lib/mix/lib/mix/tasks/compile.yecc.ex b/lib/mix/lib/mix/tasks/compile.yecc.ex index 5d9924224da..09127770124 100644 --- a/lib/mix/lib/mix/tasks/compile.yecc.ex +++ b/lib/mix/lib/mix/tasks/compile.yecc.ex @@ -52,7 +52,7 @@ defmodule Mix.Tasks.Compile.Yecc do yecc_options = project[:yecc_options] || [] - if !is_list(yecc_options) do + if not is_list(yecc_options) do Mix.raise(":yecc_options should be a list of options, got: #{inspect(yecc_options)}") end diff --git a/lib/mix/lib/mix/tasks/format.ex b/lib/mix/lib/mix/tasks/format.ex index e4bdbed1c1d..ebf44b6eb50 100644 --- a/lib/mix/lib/mix/tasks/format.ex +++ b/lib/mix/lib/mix/tasks/format.ex @@ -505,7 +505,7 @@ defmodule Mix.Tasks.Format do defp eval_file_with_keyword_list(path) do {opts, _} = Code.eval_file(path) - if !Keyword.keyword?(opts) do + if not Keyword.keyword?(opts) do Mix.raise("Expected #{inspect(path)} to return a keyword list, got: #{inspect(opts)}") end From 7855b060714348abd531ef82f146c05ead0ee8d1 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 9 Aug 2024 14:46:24 +0900 Subject: [PATCH 5/8] Manual fixes of multiple conditions --- lib/elixir/lib/kernel/typespec.ex | 2 +- lib/elixir/lib/macro.ex | 4 ++-- lib/elixir/lib/partition_supervisor.ex | 2 +- lib/elixir/lib/registry.ex | 4 ++-- lib/elixir/lib/task/supervised.ex | 4 ++-- lib/elixir/lib/task/supervisor.ex | 2 +- lib/elixir/test/elixir/kernel/cli_test.exs | 2 +- lib/elixir/test/elixir/macro_test.exs | 2 +- lib/ex_unit/lib/ex_unit/callbacks.ex | 4 ++-- lib/ex_unit/lib/ex_unit/case.ex | 2 +- lib/mix/lib/mix/release.ex | 2 +- lib/mix/lib/mix/tasks/compile.app.ex | 14 +++++++------- lib/mix/lib/mix/tasks/new.ex | 4 ++-- 13 files changed, 24 insertions(+), 24 deletions(-) diff --git a/lib/elixir/lib/kernel/typespec.ex b/lib/elixir/lib/kernel/typespec.ex index 7d7e7cbd864..e21ea04d501 100644 --- a/lib/elixir/lib/kernel/typespec.ex +++ b/lib/elixir/lib/kernel/typespec.ex @@ -754,7 +754,7 @@ defmodule Kernel.Typespec do ) do remote = Module.get_attribute(caller.module, attr) - if !(is_atom(remote) and remote != nil) do + if not (is_atom(remote) and remote != nil) do message = "invalid remote in typespec: #{Macro.to_string(orig)} (@#{attr} is #{inspect(remote)})" diff --git a/lib/elixir/lib/macro.ex b/lib/elixir/lib/macro.ex index 9a2077d1a32..8237529866f 100644 --- a/lib/elixir/lib/macro.ex +++ b/lib/elixir/lib/macro.ex @@ -895,8 +895,8 @@ defmodule Macro do defp find_invalid(bin) when is_binary(bin), do: nil defp find_invalid(fun) when is_function(fun) do - if !(Function.info(fun, :env) == {:env, []} and - Function.info(fun, :type) == {:type, :external}) do + if Function.info(fun, :env) != {:env, []} or + Function.info(fun, :type) != {:type, :external} do {:error, fun} end end diff --git a/lib/elixir/lib/partition_supervisor.ex b/lib/elixir/lib/partition_supervisor.ex index 14ef2905506..d08f43017c8 100644 --- a/lib/elixir/lib/partition_supervisor.ex +++ b/lib/elixir/lib/partition_supervisor.ex @@ -240,7 +240,7 @@ defmodule PartitionSupervisor do {partitions, opts} = Keyword.pop(opts, :partitions, System.schedulers_online()) - if !(is_integer(partitions) and partitions >= 1) do + if not (is_integer(partitions) and partitions >= 1) do raise ArgumentError, "the :partitions option must be a positive integer, got: #{inspect(partitions)}" end diff --git a/lib/elixir/lib/registry.ex b/lib/elixir/lib/registry.ex index e2b4b1c875e..101cb49e34f 100644 --- a/lib/elixir/lib/registry.ex +++ b/lib/elixir/lib/registry.ex @@ -356,14 +356,14 @@ defmodule Registry do partitions = Keyword.get(options, :partitions, 1) - if !(is_integer(partitions) and partitions >= 1) do + if not (is_integer(partitions) and partitions >= 1) do raise ArgumentError, "expected :partitions to be a positive integer, got: #{inspect(partitions)}" end listeners = Keyword.get(options, :listeners, []) - if !(is_list(listeners) and Enum.all?(listeners, &is_atom/1)) do + if not (is_list(listeners) and Enum.all?(listeners, &is_atom/1)) do raise ArgumentError, "expected :listeners to be a list of named processes, got: #{inspect(listeners)}" end diff --git a/lib/elixir/lib/task/supervised.ex b/lib/elixir/lib/task/supervised.ex index f58b5c01c39..906231bbbff 100644 --- a/lib/elixir/lib/task/supervised.ex +++ b/lib/elixir/lib/task/supervised.ex @@ -209,7 +209,7 @@ defmodule Task.Supervised do ordered = Keyword.get(options, :ordered, true) zip_input_on_exit = Keyword.get(options, :zip_input_on_exit, false) - if !(is_integer(max_concurrency) and max_concurrency > 0) do + if not (is_integer(max_concurrency) and max_concurrency > 0) do raise ArgumentError, ":max_concurrency must be an integer greater than zero" end @@ -217,7 +217,7 @@ defmodule Task.Supervised do raise ArgumentError, ":on_timeout must be either :exit or :kill_task" end - if !((is_integer(timeout) and timeout >= 0) or timeout == :infinity) do + if not ((is_integer(timeout) and timeout >= 0) or timeout == :infinity) do raise ArgumentError, ":timeout must be either a positive integer or :infinity" end diff --git a/lib/elixir/lib/task/supervisor.ex b/lib/elixir/lib/task/supervisor.ex index bd10acf2dfd..6086b2a18fe 100644 --- a/lib/elixir/lib/task/supervisor.ex +++ b/lib/elixir/lib/task/supervisor.ex @@ -614,7 +614,7 @@ defmodule Task.Supervisor do defp build_stream(supervisor, link_type, enumerable, fun, options) do shutdown = Keyword.get(options, :shutdown, 5000) - if !((is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill) do + if not ((is_integer(shutdown) and shutdown >= 0) or shutdown == :brutal_kill) do raise ArgumentError, ":shutdown must be either a positive integer or :brutal_kill" end diff --git a/lib/elixir/test/elixir/kernel/cli_test.exs b/lib/elixir/test/elixir/kernel/cli_test.exs index 44634487d4e..79602df7b72 100644 --- a/lib/elixir/test/elixir/kernel/cli_test.exs +++ b/lib/elixir/test/elixir/kernel/cli_test.exs @@ -95,7 +95,7 @@ defmodule Kernel.CLI.ExecutableTest do System.cmd(elixir_executable(context.cli_extension), ["-e", "Time.new!(0, 0, 0)"]) # TODO: remove this once we bump CI to 26.3 - if !(windows?() and System.otp_release() == "26") do + if not (windows?() and System.otp_release() == "26") do {output, 0} = System.cmd(iex_executable(context.cli_extension), [ "--eval", diff --git a/lib/elixir/test/elixir/macro_test.exs b/lib/elixir/test/elixir/macro_test.exs index fddf72859b1..15004ed8db9 100644 --- a/lib/elixir/test/elixir/macro_test.exs +++ b/lib/elixir/test/elixir/macro_test.exs @@ -648,7 +648,7 @@ defmodule MacroTest do {result, formatted} = dbg_format( - if !(true and x) do + unless true and x do map[:a] * 2 else map[:b] diff --git a/lib/ex_unit/lib/ex_unit/callbacks.ex b/lib/ex_unit/lib/ex_unit/callbacks.ex index 9b188de1fd9..3c7a9c82a85 100644 --- a/lib/ex_unit/lib/ex_unit/callbacks.ex +++ b/lib/ex_unit/lib/ex_unit/callbacks.ex @@ -243,7 +243,7 @@ defmodule ExUnit.Callbacks do """ defmacro setup(context, block) do - if !(Keyword.keyword?(block) and Keyword.has_key?(block, :do)) do + if not (Keyword.keyword?(block) and Keyword.has_key?(block, :do)) do raise ArgumentError, "setup/2 requires a block as the second argument after the context, got: #{Macro.to_string(block)}" end @@ -378,7 +378,7 @@ defmodule ExUnit.Callbacks do """ defmacro setup_all(context, block) do - if !(Keyword.keyword?(block) and Keyword.has_key?(block, :do)) do + if not (Keyword.keyword?(block) and Keyword.has_key?(block, :do)) do raise ArgumentError, "setup_all/2 requires a block as the second argument after the context, got: #{Macro.to_string(block)}" end diff --git a/lib/ex_unit/lib/ex_unit/case.ex b/lib/ex_unit/lib/ex_unit/case.ex index 4fe86694e9f..6ed27b5e306 100644 --- a/lib/ex_unit/lib/ex_unit/case.ex +++ b/lib/ex_unit/lib/ex_unit/case.ex @@ -322,7 +322,7 @@ defmodule ExUnit.Case do {async?, opts} = Keyword.pop(opts, :async, false) {parameterize, opts} = Keyword.pop(opts, :parameterize, nil) - if !(parameterize == nil or (is_list(parameterize) and Enum.all?(parameterize, &is_map/1))) do + if not (parameterize == nil or (is_list(parameterize) and Enum.all?(parameterize, &is_map/1))) do raise ArgumentError, ":parameterize must be a list of maps, got: #{inspect(parameterize)}" end diff --git a/lib/mix/lib/mix/release.ex b/lib/mix/lib/mix/release.ex index ea62c3f5612..51201a1ad31 100644 --- a/lib/mix/lib/mix/release.ex +++ b/lib/mix/lib/mix/release.ex @@ -75,7 +75,7 @@ defmodule Mix.Release do def from_config!(name, config, overrides) do {name, apps, opts} = find_release(name, config) - if !(Atom.to_string(name) =~ ~r/^[a-z][a-z0-9_]*$/) do + if not (Atom.to_string(name) =~ ~r/^[a-z][a-z0-9_]*$/) do Mix.raise( "Invalid release name. A release name must start with a lowercase ASCII letter, " <> "followed by lowercase ASCII letters, numbers, or underscores, got: #{inspect(name)}" diff --git a/lib/mix/lib/mix/tasks/compile.app.ex b/lib/mix/lib/mix/tasks/compile.app.ex index 73fadf7e147..2f6040e3747 100644 --- a/lib/mix/lib/mix/tasks/compile.app.ex +++ b/lib/mix/lib/mix/tasks/compile.app.ex @@ -211,7 +211,7 @@ defmodule Mix.Tasks.Compile.App do defp validate_version(version) do ensure_present(:version, version) - if !(is_binary(version) and match?({:ok, _}, Version.parse(version))) do + if not (is_binary(version) and match?({:ok, _}, Version.parse(version))) do Mix.raise( "Expected :version to be a valid Version, got: #{inspect(version)} (see the Version module for more information)" ) @@ -273,7 +273,7 @@ defmodule Mix.Tasks.Compile.App do end {:maxT, value} -> - if !(value == :infinity or is_integer(value)) do + if not (value == :infinity or is_integer(value)) do Mix.raise( "Application maximum time (:maxT) is not an integer or :infinity, got: " <> inspect(value) @@ -281,14 +281,14 @@ defmodule Mix.Tasks.Compile.App do end {:modules, value} -> - if !(is_list(value) and Enum.all?(value, &is_atom(&1))) do + if not (is_list(value) and Enum.all?(value, &is_atom(&1))) do Mix.raise( "Application modules (:modules) should be a list of atoms, got: " <> inspect(value) ) end {:registered, value} -> - if !(is_list(value) and Enum.all?(value, &is_atom(&1))) do + if not (is_list(value) and Enum.all?(value, &is_atom(&1))) do Mix.raise( "Application registered processes (:registered) should be a list of atoms, got: " <> inspect(value) @@ -296,7 +296,7 @@ defmodule Mix.Tasks.Compile.App do end {:included_applications, value} -> - if !(is_list(value) and Enum.all?(value, &is_atom(&1))) do + if not (is_list(value) and Enum.all?(value, &is_atom(&1))) do Mix.raise( "Application included applications (:included_applications) should be a list of atoms, got: " <> inspect(value) @@ -304,7 +304,7 @@ defmodule Mix.Tasks.Compile.App do end {:extra_applications, value} -> - if !(is_list(value) and Enum.all?(value, &typed_app?(&1))) do + if not (is_list(value) and Enum.all?(value, &typed_app?(&1))) do Mix.raise( "Application extra applications (:extra_applications) should be a list of atoms or " <> "{app, :required | :optional} pairs, got: " <> inspect(value) @@ -312,7 +312,7 @@ defmodule Mix.Tasks.Compile.App do end {:applications, value} -> - if !(is_list(value) and Enum.all?(value, &typed_app?(&1))) do + if not (is_list(value) and Enum.all?(value, &typed_app?(&1))) do Mix.raise( "Application applications (:applications) should be a list of atoms or " <> "{app, :required | :optional} pairs, got: " <> inspect(value) diff --git a/lib/mix/lib/mix/tasks/new.ex b/lib/mix/lib/mix/tasks/new.ex index 0f3cea5a910..4a038dbddcf 100644 --- a/lib/mix/lib/mix/tasks/new.ex +++ b/lib/mix/lib/mix/tasks/new.ex @@ -195,7 +195,7 @@ defmodule Mix.Tasks.New do end defp invalid_app(name) do - if !(name =~ ~r/^[a-z][a-z0-9_]*$/) do + if not (name =~ ~r/^[a-z][a-z0-9_]*$/) do "Application name must start with a lowercase ASCII letter, followed by " <> "lowercase ASCII letters, numbers, or underscores, got: #{inspect(name)}" end @@ -210,7 +210,7 @@ defmodule Mix.Tasks.New do end defp check_mod_name_validity!(name) do - if !(name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/) do + if not (name =~ ~r/^[A-Z]\w*(\.[A-Z]\w*)*$/) do Mix.raise( "Module name must be a valid Elixir alias (for example: Foo.Bar), got: #{inspect(name)}" ) From 9213315ab821a65f5a6e5608e116c699b734d886 Mon Sep 17 00:00:00 2001 From: sabiwara Date: Fri, 9 Aug 2024 14:51:14 +0900 Subject: [PATCH 6/8] Add more guards --- lib/elixir/lib/code/formatter.ex | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/elixir/lib/code/formatter.ex b/lib/elixir/lib/code/formatter.ex index 544a23a7918..ebf789b817a 100644 --- a/lib/elixir/lib/code/formatter.ex +++ b/lib/elixir/lib/code/formatter.ex @@ -2484,14 +2484,18 @@ defmodule Code.Formatter do ] @guards [ :is_atom, + :is_boolean, + :is_nil, :is_number, :is_integer, :is_float, :is_binary, + :is_list, :is_map, - :is_struct - # ... - # TODO add more guards + :is_struct, + :is_function, + :is_reference, + :is_pid ] defp negate_condition(condition) do From 3d2dbffe6f8b350d50e0d222317df2a74b9f1103 Mon Sep 17 00:00:00 2001 From: Jean Klingler Date: Fri, 9 Aug 2024 17:17:11 +0900 Subject: [PATCH 7/8] Apply suggestions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/elixir/test/elixir/file_test.exs | 4 ++-- lib/mix/lib/mix/tasks/deps.compile.ex | 6 +++--- lib/mix/lib/mix/tasks/deps.loadpaths.ex | 2 +- lib/mix/lib/mix/tasks/escript.build.ex | 2 +- lib/mix/lib/mix/tasks/run.ex | 2 +- lib/mix/lib/mix/tasks/test.ex | 2 +- lib/mix/lib/mix/utils.ex | 2 +- lib/mix/test/mix/release_test.exs | 2 +- lib/mix/test/test_helper.exs | 8 ++++---- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/elixir/test/elixir/file_test.exs b/lib/elixir/test/elixir/file_test.exs index b76d8dd5f62..792dea5a94e 100644 --- a/lib/elixir/test/elixir/file_test.exs +++ b/lib/elixir/test/elixir/file_test.exs @@ -1794,7 +1794,7 @@ defmodule FileTest do stat = File.stat!(fixture) assert stat.mode == 0o100666 - if !windows?() do + if not windows?() do assert File.chmod(fixture, 0o100777) == :ok stat = File.stat!(fixture) assert stat.mode == 0o100777 @@ -1814,7 +1814,7 @@ defmodule FileTest do stat = File.stat!(fixture) assert stat.mode == 0o100666 - if !windows?() do + if not windows?() do assert File.chmod!(fixture, 0o100777) == :ok stat = File.stat!(fixture) assert stat.mode == 0o100777 diff --git a/lib/mix/lib/mix/tasks/deps.compile.ex b/lib/mix/lib/mix/tasks/deps.compile.ex index 60a5447324f..0865990c6e9 100644 --- a/lib/mix/lib/mix/tasks/deps.compile.ex +++ b/lib/mix/lib/mix/tasks/deps.compile.ex @@ -180,7 +180,7 @@ defmodule Mix.Tasks.Deps.Compile do end defp do_rebar3(%Mix.Dep{opts: opts} = dep, config) do - if !Mix.Rebar.available?(:rebar3) do + if not Mix.Rebar.available?(:rebar3) do handle_rebar_not_found(dep) end @@ -247,7 +247,7 @@ defmodule Mix.Tasks.Deps.Compile do "Shall I install #{manager}? (if running non-interactively, " <> "use \"mix local.rebar --force\")" - if !shell.yes?(install_question) do + if not shell.yes?(install_question) do error_message = "Could not find \"#{manager}\" to compile " <> "dependency #{inspect(app)}, please ensure \"#{manager}\" is available" @@ -257,7 +257,7 @@ defmodule Mix.Tasks.Deps.Compile do Mix.Tasks.Local.Rebar.run(["--force"]) - if !Mix.Rebar.available?(manager) do + if not Mix.Rebar.available?(manager) do Mix.raise("\"#{manager}\" installation failed") end end diff --git a/lib/mix/lib/mix/tasks/deps.loadpaths.ex b/lib/mix/lib/mix/tasks/deps.loadpaths.ex index a244dd207d8..efca17f2bb2 100644 --- a/lib/mix/lib/mix/tasks/deps.loadpaths.ex +++ b/lib/mix/lib/mix/tasks/deps.loadpaths.ex @@ -59,7 +59,7 @@ defmodule Mix.Tasks.Deps.Loadpaths do if req = config[:elixir] do case Version.parse_requirement(req) do {:ok, req} -> - if !Version.match?(System.version(), req) do + if not Version.match?(System.version(), req) do raise Mix.ElixirVersionError, target: config[:app] || Mix.Project.get(), expected: req, diff --git a/lib/mix/lib/mix/tasks/escript.build.ex b/lib/mix/lib/mix/tasks/escript.build.ex index 96f80254ed5..1a27fe57c02 100644 --- a/lib/mix/lib/mix/tasks/escript.build.ex +++ b/lib/mix/lib/mix/tasks/escript.build.ex @@ -155,7 +155,7 @@ defmodule Mix.Tasks.Escript.Build do Mix.raise(error_message) end - if !Code.ensure_loaded?(main) do + if not Code.ensure_loaded?(main) do error_message = "Could not generate escript, module #{main} defined as " <> ":main_module could not be loaded" diff --git a/lib/mix/lib/mix/tasks/run.ex b/lib/mix/lib/mix/tasks/run.ex index 52e2fad50aa..d32131f6a9e 100644 --- a/lib/mix/lib/mix/tasks/run.ex +++ b/lib/mix/lib/mix/tasks/run.ex @@ -83,7 +83,7 @@ defmodule Mix.Tasks.Run do ) run(args, opts, head, &Code.eval_string/1, &Code.require_file/1) - if !Keyword.get(opts, :halt, true), do: System.no_halt(true) + if not Keyword.get(opts, :halt, true), do: System.no_halt(true) Mix.Task.reenable("run") :ok end diff --git a/lib/mix/lib/mix/tasks/test.ex b/lib/mix/lib/mix/tasks/test.ex index 7b73af1e905..2cf561e2cf6 100644 --- a/lib/mix/lib/mix/tasks/test.ex +++ b/lib/mix/lib/mix/tasks/test.ex @@ -512,7 +512,7 @@ defmodule Mix.Tasks.Test do defp do_run(opts, args, files) do _ = Mix.Project.get!() - if !(System.get_env("MIX_ENV") || Mix.env() == :test) do + if System.get_env("MIX_ENV") == nil && Mix.env() != :test do Mix.raise(""" "mix test" is running in the \"#{Mix.env()}\" environment. If you are \ running tests from within another command, you can either: diff --git a/lib/mix/lib/mix/utils.ex b/lib/mix/lib/mix/utils.ex index 81954e49f3e..733591d4548 100644 --- a/lib/mix/lib/mix/utils.ex +++ b/lib/mix/lib/mix/utils.ex @@ -512,7 +512,7 @@ defmodule Mix.Utils do do_symlink_or_copy(source, target, link) {:error, _} -> - if !File.dir?(target) do + if not File.dir?(target) do File.rm_rf!(target) end diff --git a/lib/mix/test/mix/release_test.exs b/lib/mix/test/mix/release_test.exs index a7c352b1651..fe24f1f1f65 100644 --- a/lib/mix/test/mix/release_test.exs +++ b/lib/mix/test/mix/release_test.exs @@ -659,7 +659,7 @@ defmodule Mix.ReleaseTest do assert File.read!(Path.join(destination, "bin/erl")) =~ ~s|ROOTDIR="${ERL_ROOTDIR:-"$(dirname "$(dirname "$BINDIR")")"}| - if !match?({:win32, _}, :os.type()) do + if not match?({:win32, _}, :os.type()) do assert File.lstat!(Path.join(destination, "bin/erl")).mode |> rem(0o1000) == 0o755 end diff --git a/lib/mix/test/test_helper.exs b/lib/mix/test/test_helper.exs index 8c0f9fb174d..5f4f0467425 100644 --- a/lib/mix/test/test_helper.exs +++ b/lib/mix/test/test_helper.exs @@ -263,7 +263,7 @@ System.cmd("git", ~w[config --global init.defaultBranch not-main]) ### Git repo target = Path.expand("fixtures/git_repo", __DIR__) -if !File.dir?(target) do +if not File.dir?(target) do File.mkdir_p!(Path.join(target, "lib")) File.write!(Path.join(target, "mix.exs"), """ @@ -345,7 +345,7 @@ end ### Deps on Git repo target = Path.expand("fixtures/deps_on_git_repo", __DIR__) -if !File.dir?(target) do +if not File.dir?(target) do File.mkdir_p!(Path.join(target, "lib")) File.write!(Path.join(target, "mix.exs"), """ @@ -401,7 +401,7 @@ end # Git Rebar target = Path.expand("fixtures/git_rebar", __DIR__) -if !File.dir?(target) do +if not File.dir?(target) do File.mkdir_p!(Path.join(target, "ebin")) File.mkdir_p!(Path.join(target, "src")) @@ -439,7 +439,7 @@ end) ### Archive ebin target = Path.expand("fixtures/archive", __DIR__) -if !File.dir?(Path.join(target, "ebin")) do +if not File.dir?(Path.join(target, "ebin")) do File.mkdir_p!(Path.join(target, "ebin")) File.write!(Path.join([target, "ebin", "local_sample.app"]), """ From 2162ad72c0474d5fb02284f63ceb25205287d8ac Mon Sep 17 00:00:00 2001 From: sabiwara Date: Tue, 27 Aug 2024 13:35:42 +0900 Subject: [PATCH 8/8] Swap conditions --- lib/elixir/lib/stream/reducers.ex | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/elixir/lib/stream/reducers.ex b/lib/elixir/lib/stream/reducers.ex index 8afb0a841cb..4a9ae8d84ac 100644 --- a/lib/elixir/lib/stream/reducers.ex +++ b/lib/elixir/lib/stream/reducers.ex @@ -151,10 +151,10 @@ defmodule Stream.Reducers do defmacro reject(callback, fun \\ nil) do quote do fn entry, acc -> - if !unquote(callback).(entry) do - next(unquote(fun), entry, acc) - else + if unquote(callback).(entry) do skip(acc) + else + next(unquote(fun), entry, acc) end end end