From b55888befd96080043854f78839435b6e88bd1f7 Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Wed, 25 Mar 2026 10:30:59 -0500 Subject: [PATCH 1/3] Improve function argument naming, specs and guards in Mix --- lib/mix/lib/mix.ex | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/mix/lib/mix.ex b/lib/mix/lib/mix.ex index 9f0e0c65155..5498157bfe4 100644 --- a/lib/mix/lib/mix.ex +++ b/lib/mix/lib/mix.ex @@ -452,6 +452,7 @@ defmodule Mix do import Kernel, except: [raise: 2] @doc false + @spec start() :: :ok def start do {:ok, _} = Application.ensure_all_started(:mix) :ok @@ -485,7 +486,7 @@ defmodule Mix do Proper configuration can be set in config files, often per-environment (see the `Config` module for more information). """ - @spec env() :: atom() + @spec env() :: env :: atom() def env do # env is not available on bootstrapping, so set a :dev default Mix.State.get(:env, :dev) @@ -508,7 +509,7 @@ defmodule Mix do @doc """ Returns the Mix target. """ - @spec target() :: atom() + @spec target() :: target :: atom() def target do # target is not available on bootstrapping, so set a :host default Mix.State.get(:target, :host) @@ -536,7 +537,7 @@ defmodule Mix do end """ - @spec compilers() :: [atom()] + @spec compilers() :: [compiler :: atom()] def compilers do [:erlang, :elixir, :app] end @@ -612,8 +613,8 @@ defmodule Mix do Sets Mix debug mode. """ @spec debug(boolean()) :: :ok - def debug(debug) when is_boolean(debug) do - Mix.State.put(:debug, debug) + def debug(enabled?) when is_boolean(enabled?) do + Mix.State.put(:debug, enabled?) end @doc """ @@ -651,7 +652,9 @@ defmodule Mix do The path for local archives or escripts. """ @doc since: "1.10.0" - @spec path_for(:archives | :escripts) :: String.t() + @spec path_for(kind :: :archives | :escripts) :: String.t() + def path_for(kind) + def path_for(:archives) do System.get_env("MIX_ARCHIVES") || Path.join(Mix.Utils.mix_home(), "archives") end @@ -671,6 +674,7 @@ defmodule Mix do This function does not start the given applications. """ @doc since: "1.15.0" + @spec ensure_application!(Application.app()) :: :ok def ensure_application!(app) when is_atom(app) do ensure_application!(app, Mix.State.builtin_apps(), [], %{}) :ok @@ -1131,7 +1135,7 @@ defmodule Mix do end @doc false - def in_install_project(fun) do + def in_install_project(fun) when is_function(fun, 0) do case safe_get_installed() do {id, dynamic_config} -> config = install_project_config(dynamic_config) @@ -1221,5 +1225,6 @@ defmodule Mix do end @doc false + @spec install?() :: boolean() def install?, do: Mix.Project.get() == @mix_install_project end From a060c9939d474e7309e2555c4845f10640801142 Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Wed, 25 Mar 2026 16:25:17 -0500 Subject: [PATCH 2/3] Apply suggestions by @josevalim --- lib/mix/lib/mix.ex | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/mix/lib/mix.ex b/lib/mix/lib/mix.ex index 5498157bfe4..0fbf441b67e 100644 --- a/lib/mix/lib/mix.ex +++ b/lib/mix/lib/mix.ex @@ -452,7 +452,6 @@ defmodule Mix do import Kernel, except: [raise: 2] @doc false - @spec start() :: :ok def start do {:ok, _} = Application.ensure_all_started(:mix) :ok @@ -486,7 +485,7 @@ defmodule Mix do Proper configuration can be set in config files, often per-environment (see the `Config` module for more information). """ - @spec env() :: env :: atom() + @spec env() :: atom() def env do # env is not available on bootstrapping, so set a :dev default Mix.State.get(:env, :dev) @@ -509,7 +508,7 @@ defmodule Mix do @doc """ Returns the Mix target. """ - @spec target() :: target :: atom() + @spec target() :: atom() def target do # target is not available on bootstrapping, so set a :host default Mix.State.get(:target, :host) @@ -652,7 +651,7 @@ defmodule Mix do The path for local archives or escripts. """ @doc since: "1.10.0" - @spec path_for(kind :: :archives | :escripts) :: String.t() + @spec path_for(:archives | :escripts) :: String.t() def path_for(kind) def path_for(:archives) do @@ -1225,6 +1224,5 @@ defmodule Mix do end @doc false - @spec install?() :: boolean() def install?, do: Mix.Project.get() == @mix_install_project end From 84b35913e7e77fc9457c0e981d85dfbd451a6080 Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Thu, 26 Mar 2026 06:08:56 -0500 Subject: [PATCH 3/3] Update lib/mix/lib/mix.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/mix/lib/mix.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mix/lib/mix.ex b/lib/mix/lib/mix.ex index 0fbf441b67e..c7083f9b55b 100644 --- a/lib/mix/lib/mix.ex +++ b/lib/mix/lib/mix.ex @@ -536,7 +536,7 @@ defmodule Mix do end """ - @spec compilers() :: [compiler :: atom()] + @spec compilers() :: [atom()] def compilers do [:erlang, :elixir, :app] end