Repository: jeremyjh/dialyxir (elixir)

Issue:
list_unused_filters: true in mix.exs doesn't cause --halt-exit-status to fail
When setting `list_unused_filters: true` via `mix.exs` and subsequently running `mix dialyzer --halt-exit-status`, it causes the number of "Unnessecary skips" to be output, but doesn't fail the build.

```
$ mix dialyzer --halt-exit-status
Finding suitable PLTs
Checking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
PLT is up to date!
ignore_warnings: .dialyzer_ignore.exs

Starting Dialyzer
[
  check_plt: false,
  init_plt: '/Users/aaron/projects/dialyxir_issue/_build/dev/dialyxir_erlang-21.3.2_elixir-1.8.1_deps-dev.plt',
  files_rec: ['/Users/aaron/projects/dialyxir_issue/_build/dev/lib/dialyxir_issue/ebin'],
  warnings: [:unknown]
]
Total errors: 2, Skipped: 2, Unnecessary Skips: 1
done in 0m1.27s
done (passed successfully)
```

Instead, if I want the build to fail, I have to add the command line option `--list-unused-filters`.
```
$ mix dialyzer --list-unused-filters --halt-exit-status
Finding suitable PLTs
Checking PLT...
[:compiler, :elixir, :kernel, :logger, :stdlib]
PLT is up to date!
ignore_warnings: .dialyzer_ignore.exs

Starting Dialyzer
[
  check_plt: false,
  init_plt: '/Users/aaron/projects/dialyxir_issue/_build/dev/dialyxir_erlang-21.3.2_elixir-1.8.1_deps-dev.plt',
  files_rec: ['/Users/aaron/projects/dialyxir_issue/_build/dev/lib/dialyxir_issue/ebin'],
  warnings: [:unknown]
]
Total errors: 2, Skipped: 2, Unnecessary Skips: 1
Unused filters:
{"lib/dialyxir_issue.ex"}
unused filters present
```

## Expected behavior

I would think that setting `list_unused_filters: true` in the mix config should be the same as setting the command line option `--list-unused-filters`. 

## Reproduction case

I've put together a sample app here: https://github.com/aaronrenner/dialyxir_issue. **You must this app run on Elixir 1.8.0 or 1.8.1 to trigger the dialyzer error, because it's related to [an issue in elixir](https://github.com/elixir-lang/elixir/pull/8841)**.

First run `mix dialyzer --halt-exit-status` and notice it doesn't fail as it should. 

Next run `mix dialyzer --list-unused-filters --halt-exit-status` and see that it fails as expected.

Pull request:
Fix list_unused_filter
Configuring list_unused_filter should behave the same as when passing it as a command line argument. If it is not set as a command line argument, the mix setting must be considered.

Fix #313 

Patch:
diff --git a/lib/dialyxir/project.ex b/lib/dialyxir/project.ex
index 6ff6072..0c42b15 100644
--- a/lib/dialyxir/project.ex
+++ b/lib/dialyxir/project.ex
@@ -156,10 +156,13 @@ defmodule Dialyxir.Project do
     dialyzer_config()[:ignore_warnings]
   end
 
-  defp list_unused_filters?(args) do
+  def list_unused_filters?(args) do
     case Keyword.fetch(args, :list_unused_filters) do
-      :error -> dialyzer_config()[:list_unused_filters]
-      {:ok, list_unused_filters} -> list_unused_filters
+      {:ok, list_unused_filters} when not is_nil(list_unused_filters) ->
+        list_unused_filters
+
+      _else ->
+        dialyzer_config()[:list_unused_filters]
     end
   end
 


Test patch:
diff --git a/test/dialyxir/project_test.exs b/test/dialyxir/project_test.exs
index 9fe7302..7d3d5cc 100644
--- a/test/dialyxir/project_test.exs
+++ b/test/dialyxir/project_test.exs
@@ -168,4 +168,14 @@ defmodule Dialyxir.ProjectTest do
       refute Enum.member?(Project.cons_apps(), :logger)
     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)
+
+    # Override in mix.exs
+    in_project(:ignore, fn ->
+      assert Project.list_unused_filters?(list_unused_filters: nil)
+    end)
+  end
 end