Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make dialyzer output file format configurable #2538

Merged
merged 4 commits into from
Apr 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions src/rebar_prv_dialyzer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ desc() ->
"modules from excluded applications\n"
"`exclude_mods` - a list of modules to exclude from PLT files and "
"success typing analysis\n"
"`output_format` - configure whether the dialyzer_warnings file will have "
"the `raw` or `formatted` output\n"
"\n"
"For example, to warn on unmatched returns: \n"
"{dialyzer, [{warnings, [unmatched_returns]}]}.\n"
Expand Down Expand Up @@ -557,18 +559,27 @@ legacy_warnings(Warnings) ->
format_warnings(Opts, Output, Warnings) ->
Warnings1 = rebar_dialyzer_format:format_warnings(Opts, Warnings),
console_warnings(Warnings1),
file_warnings(Output, Warnings),
Config = rebar_opts:get(Opts, dialyzer, []),
OutputFormat = proplists:get_value(output_format, Config, formatted),
file_warnings(Output, Warnings, OutputFormat),
length(Warnings).

console_warnings(Warnings) ->
_ = [?CONSOLE("~ts", [Warning]) || Warning <- Warnings],
ok.

file_warnings(_, []) ->
file_warnings(_, [], _) ->
ok;
file_warnings(Output, Warnings) ->
Warnings1 = [[dialyzer:format_warning(Warning, fullpath), $\n] || Warning <- Warnings],
case file:write_file(Output, Warnings1, [append]) of
file_warnings(Output, Warnings, raw) ->
Warnings1 = [[io_lib:format("~tp.\n", [W]) || W <- Warnings]],
write_file_warnings(Output, Warnings1);
file_warnings(Output, Warnings, formatted) ->
Warnings1 = [[dialyzer:format_warning(Warning, fullpath), $\n]
|| Warning <- Warnings],
write_file_warnings(Output, Warnings1).

write_file_warnings(Output, Warnings) ->
case file:write_file(Output, Warnings, [append]) of
ok ->
ok;
{error, Reason} ->
Expand Down