Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get the compiler to exit early, failing the build, if a compile time warning is raised?

I find the compile time warnings very useful, but I can occasionally miss them, especially if it's on a pull request where the tests are running on a CI server.

Ideally I would specify something in the project mix file that would make the compiler more strict.

I want to this to be in effect for all mix tasks, and I do not want to have to pass the flag to the command, as this is easy to forget.

For example with a project with a compiler warning, this command should fail

mix clean && mix compile

As should this one

mix clean && mix test
like image 957
lpil Avatar asked Aug 13 '15 07:08

lpil


1 Answers

In your mix.exs:

def project do
  [...,
   aliases: aliases]
end

defp aliases do
  ["compile": ["compile --warnings-as-errors"]]
end

Then mix compile will pass --warnings-as-errors to the compile.elixir subtask.

This also works for mix test since it runs the compile task implicitly.


If you don't add an alias, you can still run mix compile --warnings-as-errors and it will do what you expect, but mix test --warnings-as-errors will not do what you expect, since the flag does not reach the compile.elixir task.

like image 154
TalkLittle Avatar answered Oct 28 '22 09:10

TalkLittle