-
Notifications
You must be signed in to change notification settings - Fork 9
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
Feature: Store hank output in json file #184
base: main
Are you sure you want to change the base?
Changes from all commits
1c9c875
3666eb7
1f547d8
eea6beb
8b542bd
686c17b
6569555
e529329
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,13 @@ opts() -> | |
$u, | ||
"unused_ignores", | ||
boolean, | ||
"Warn on unused ignores (default: true)."}]. | ||
"Warn on unused ignores (default: true)."}, | ||
{output_json_file, | ||
$o, | ||
"output_json_file", | ||
string, | ||
"Emit output (in JSON format) to a file (default: empty string, meaning: do not emit output"} | ||
]. | ||
|
||
%% @private | ||
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, iodata()}. | ||
|
@@ -69,6 +75,7 @@ do(State) -> | |
unused_ignores := UnusedIgnores, | ||
stats := Stats} -> | ||
instrument(Stats, UnusedIgnores, State), | ||
maybe_write_data_to_json_file(Results, State), | ||
{error, format_results(Results)} | ||
catch | ||
Kind:Error:Stack -> | ||
|
@@ -120,6 +127,28 @@ format_result(#{file := File, | |
text := Msg}) -> | ||
hank_utils:format_text("~ts:~tp: ~ts", [File, Line, Msg]). | ||
|
||
-spec maybe_write_data_to_json_file([hank_rule:result()], rebar_state:t()) -> ok. | ||
maybe_write_data_to_json_file(Result, State) -> | ||
{Args, _} = rebar_state:command_parsed_args(State), | ||
ConvertedResult = convert_data_to_binary(Result), | ||
EncodedResult = jsx:encode(ConvertedResult), | ||
Comment on lines
+133
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not terribly wrong, but I would prefer to only do this if we're going to use it (i.e. First try to come up with the name of the output file, if it's not empty,... Only then convert, encode, and emit the output). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And please document the rebar.config option in the README.md |
||
case lists:keyfind(output_json_file, 1, Args) of | ||
{output_json_file, JsonFilePath} -> | ||
ok = file:write_file(JsonFilePath, EncodedResult); | ||
_ -> | ||
JsonFilePassed = proplists:get_value(output_json_file, rebar_state:get(State, hank, []), []), | ||
case JsonFilePassed of | ||
[] -> | ||
ok; | ||
_ -> | ||
ok = file:write_file(JsonFilePassed, EncodedResult) | ||
end | ||
end. | ||
|
||
-spec convert_data_to_binary([hank_rules:result()]) -> list(). | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function doesn't return binaries. Therefore, its name is wrong. A better name would be |
||
convert_data_to_binary(Results) -> | ||
lists:map(fun hank_rule:result_to_json/1, Results). | ||
|
||
%% @private | ||
%% @doc Determines files that should be fully hidden to Hank. | ||
is_hidden(Filename) -> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.