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

前端 未结 3 1496
情深已故
情深已故 2021-01-17 18:13

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.

Ide

3条回答
  •  情歌与酒
    2021-01-17 18:23

    I like Michael Stalker's solution here.

    Treating warnings as errors always can get annoying during TDD, where you might be rapidly refactoring code while running tests.

    Instead, you can make the --warnings-as-errors flag conditional on your Mix env like this:

    defmodule SomeProject.MixProject do
      use Mix.Project
    
      def project do
        [
          elixirc_options: [
            warnings_as_errors: treat_warnings_as_errors?(Mix.env())
          ]
          # ...
        ]
      end
    
      defp treat_warnings_as_errors?(:test), do: false
      defp treat_warnings_as_errors?(_), do: true
    end
    

    Warnings will go ignored when testing, but not for a dev or prod compilation.

提交回复
热议问题