Skip to content

Commit

Permalink
otp: Polish printouts of scan-code
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi committed Feb 7, 2025
1 parent 050c40c commit 92887c3
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions scripts/scan-code.escript
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,32 @@ execute(Command, Config) ->
maps:get(sarif, Config) =/= undefined andalso
sarif(maps:get(sarif, Config), Errors),

Errors =/= [] andalso erlang:raise(exit, Errors, []),
ok.
SortedErrors = lists:sort(
fun(#{ msg := AMsg } = A, #{ msg := BMsg } = B) ->
if AMsg =:= BMsg ->
A =< B;
true ->
AMsg =< BMsg
end
end, Errors),

[io:format(standard_error, "~ts:\n Msg: ~p\n License: ~ts\n SPDX: ~ts\n", [Path, Msg, License, Spdx]) ||
#{ msg := Msg, spdx := Spdx, license := License, path := Path } <- SortedErrors],

Errors =/= [] andalso erlang:raise(exit, SortedErrors, []),
ok.

compliance_check(Licenses) when is_list(Licenses) ->
lists:foldl(fun ({Path, License, SPDX0, Copyright}, Acc) ->
SPDX = spdx_nonnull(SPDX0),
CopyrightResult = check_copyright(Copyright),
LicenseResult = compliance_check(License),
R = lists:foldl(fun (ok, Acc0) -> Acc0;
({error, Msg}, Acc0) -> [{SPDX, Path, Msg} | Acc0]
({error, Msg}, Acc0) ->
[#{ license => License,
spdx => SPDX,
path => Path,
msg => Msg} | Acc0]
end, [], [CopyrightResult, LicenseResult]),
R ++ Acc
end, [], Licenses);
Expand Down

0 comments on commit 92887c3

Please sign in to comment.