Skip to content

Commit 8c3ba08

Browse files
author
José Valim
committed
Only compute warnings_as_errors if necessary
1 parent bf79066 commit 8c3ba08

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

lib/mix/lib/mix/tasks/compile.xref.ex

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,27 +28,32 @@ defmodule Mix.Tasks.Compile.Xref do
2828
{opts, _, _} =
2929
OptionParser.parse(args, switches: [force: :boolean, warnings_as_errors: :boolean])
3030

31-
warnings_as_errors =
32-
Keyword.get_lazy(opts, :warnings_as_errors, fn ->
33-
Mix.Project.config()[:elixirc_options][:warnings_as_errors]
34-
end)
35-
36-
if needs_xref?(opts) and should_exit?(Mix.Task.run("xref", ["--warnings"]), warnings_as_errors) do
31+
if needs_xref?(opts) and should_exit?(run_xref(), opts) do
3732
exit({:shutdown, 1})
3833
end
3934

4035
write_manifest()
4136
end
4237

38+
defp run_xref do
39+
Mix.Task.run("xref", ["--warnings"])
40+
end
41+
4342
defp needs_xref?(opts) do
4443
!!opts[:force] or Mix.Utils.stale?(E.manifests(), manifests())
4544
end
4645

47-
defp should_exit?(:error, true),
48-
do: true
49-
defp should_exit?(_, _),
46+
defp should_exit?(:error, opts),
47+
do: warnings_as_errors(opts) == true
48+
defp should_exit?(_, _opts),
5049
do: false
5150

51+
defp warnings_as_errors(opts) do
52+
Keyword.get_lazy(opts, :warnings_as_errors, fn ->
53+
Mix.Project.config()[:elixirc_options][:warnings_as_errors]
54+
end)
55+
end
56+
5257
@doc """
5358
Returns xref manifests.
5459
"""

0 commit comments

Comments
 (0)