Repository: jeremyjh/dialyxir
Pull request #495 (2023-05-02 20:20:23)

Add warning for deprecated option: plt_add_deps: true
Based on the conversation in https://github.com/jeremyjh/dialyxir/pull/477


Patch:
diff --git a/lib/dialyxir/output.ex b/lib/dialyxir/output.ex
index 12de41c..4276df2 100644
--- a/lib/dialyxir/output.ex
+++ b/lib/dialyxir/output.ex
@@ -8,6 +8,9 @@ defmodule Dialyxir.Output do
   def info(""), do: :ok
   def info(text), do: Mix.shell().info(text)
 
+  def warning(""), do: :ok
+  def warning(text), do: Mix.shell().info(color(text, :yellow))
+
   def error(""), do: :ok
   def error(text), do: Mix.shell().error(text)
 end
diff --git a/lib/dialyxir/project.ex b/lib/dialyxir/project.ex
index 4be9b43..8e150e3 100644
--- a/lib/dialyxir/project.ex
+++ b/lib/dialyxir/project.ex
@@ -1,6 +1,6 @@
 defmodule Dialyxir.Project do
   @moduledoc false
-  import Dialyxir.Output, only: [info: 1, error: 1]
+  import Dialyxir.Output
 
   alias Dialyxir.FilterMap
   alias Dialyxir.Formatter.Short
@@ -34,7 +34,7 @@ defmodule Dialyxir.Project do
 
   def check_config do
     if is_binary(dialyzer_config()[:plt_file]) do
-      info("""
+      warning("""
       Notice: :plt_file is deprecated as Dialyxir now uses project-private PLT files by default.
       If you want to use this setting without seeing this warning, provide it in a pair
       with the :no_warn key e.g. `dialyzer: plt_file: {:no_warn, "~/mypltfile"}`
@@ -316,10 +316,14 @@ defmodule Dialyxir.Project do
 
           # compatibility
           true ->
+            warning(
+              "Dialyxir has deprecated plt_add_deps: true in favor of apps_direct, which includes only runtime dependencies."
+            )
+
             deps_project() ++ deps_app(false)
 
           :project ->
-            info(
+            warning(
               "Dialyxir has deprecated plt_add_deps: :project in favor of apps_direct, which includes only runtime dependencies."
             )
 
@@ -329,7 +333,7 @@ defmodule Dialyxir.Project do
             deps_app(false)
 
           :transitive ->
-            info(
+            warning(
               "Dialyxir has deprecated plt_add_deps: :transitive in favor of app_tree, which includes only runtime dependencies."
             )
 


Test patch:
diff --git a/test/dialyxir/project_test.exs b/test/dialyxir/project_test.exs
index 259dcfd..7816d8e 100644
--- a/test/dialyxir/project_test.exs
+++ b/test/dialyxir/project_test.exs
@@ -175,6 +175,13 @@ defmodule Dialyxir.ProjectTest do
     end)
   end
 
+  test "Deprecation warning on use of plt_add_deps: true" do
+    in_project(:plt_add_deps_deprecations, fn ->
+      out = capture_io(&Project.cons_apps/0)
+      assert Regex.match?(~r/.*deprecated.*plt_add_deps.*/, out)
+    end)
+  end
+
   test "list_unused_filters? works as intended" do
     assert Project.list_unused_filters?(list_unused_filters: true)
     refute Project.list_unused_filters?(list_unused_filters: nil)
diff --git a/test/fixtures/plt_add_deps_deprecations/mix.exs b/test/fixtures/plt_add_deps_deprecations/mix.exs
new file mode 100644
index 0000000..fc40956
--- /dev/null
+++ b/test/fixtures/plt_add_deps_deprecations/mix.exs
@@ -0,0 +1,13 @@
+defmodule PltAddDepsDeprecations.Mixfile do
+  use Mix.Project
+
+  def project do
+    [
+      app: :plt_add_deps_deprecations,
+      version: "0.1.0",
+      dialyzer: [
+        plt_add_deps: true
+      ]
+    ]
+  end
+end