Current section

Files

Jump to
go_over src go_over.erl
Raw

src/go_over.erl

-module(go_over).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/go_over.gleam").
-export([print_warnings/2, main/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/go_over.gleam", 19).
?DOC(false).
-spec print_warnings_count(list(go_over@warning:warning())) -> list(go_over@warning:warning()).
print_warnings_count(Vulns) ->
_pipe = (<<<<<<"⛔ "/utf8,
(erlang:integer_to_binary(erlang:length(Vulns)))/binary>>/binary,
" WARNING(s) FOUND!"/utf8>>/binary,
(<<"\n-----------------------------------------------\n"/utf8>>)/binary>>),
gleam_stdlib:print_error(_pipe),
Vulns.
-file("src/go_over.gleam", 30).
?DOC(false).
-spec print_warnings(list(go_over@warning:warning()), go_over@config:config()) -> nil.
print_warnings(Vulns, Conf) ->
case erlang:element(6, Conf) of
minimal ->
_pipe = Vulns,
_pipe@1 = print_warnings_count(_pipe),
_pipe@2 = gleam@list:map(
_pipe@1,
fun go_over@warning:format_as_string_minimal/1
),
_pipe@3 = gleam@string:join(_pipe@2, <<""/utf8>>),
gleam_stdlib:print_error(_pipe@3);
j_s_o_n ->
_pipe@4 = Vulns,
_pipe@5 = gleam@list:map(
_pipe@4,
fun go_over@warning:format_as_json/1
),
_pipe@6 = gleam@json:preprocessed_array(_pipe@5),
_pipe@7 = gleam@json:to_string(_pipe@6),
gleam_stdlib:print_error(_pipe@7);
_ ->
_pipe@8 = Vulns,
_pipe@9 = print_warnings_count(_pipe@8),
_pipe@10 = gleam@list:map(
_pipe@9,
fun go_over@warning:format_as_string/1
),
_pipe@11 = gleam@string:join(
_pipe@10,
<<"\n-----------------------------------------------\n"/utf8>>
),
gleam_stdlib:print_error(_pipe@11)
end,
shellout_ffi:os_exit(1).
-file("src/go_over.gleam", 56).
?DOC(false).
-spec main() -> nil.
main() ->
Conf@1 = case go_over@config:spin_up(
go_over@config:read_config(<<"gleam.toml"/utf8>>),
shellout_ffi:start_arguments()
) of
{error, E} ->
gleam_stdlib:println_error(E),
shellout_ffi:os_exit(0),
go_over@util@util:do_panic();
{ok, Conf} ->
Conf
end,
go_over@util@globals:set_verbose(erlang:element(7, Conf@1)),
go_over@util@globals:set_use_global_cache(erlang:element(8, Conf@1)),
go_over@util@globals:set_force(erlang:element(5, Conf@1)),
Spinner = go_over@util@spinner:new_spinner(<<"Let's do this!"/utf8>>),
gxyz@function:ignore_result(
erlang:element(5, Conf@1),
gxyz@function:freeze1(
fun simplifile_erl:delete/1,
go_over@util@globals:go_over_path()
)
),
go_over@util@spinner:set_text_spinner(Spinner, <<"Reading manifest"/utf8>>),
Pkgs = begin
_pipe = go_over@packages:read_manifest(<<"manifest.toml"/utf8>>),
_pipe@1 = go_over@config:filter_dev_dependencies(Conf@1, _pipe),
_pipe@2 = go_over@config:filter_packages(Conf@1, _pipe@1),
go_over@config:filter_indirect(Conf@1, _pipe@2)
end,
go_over@util@spinner:set_text_spinner(
Spinner,
<<"Checking packages: "/utf8,
(go_over@util@print:raw(<<"vulnerable"/utf8>>, <<"red"/utf8>>))/binary>>
),
Vulnerable_warnings = go_over@sources:get_vulnerable_warnings(Pkgs, Conf@1),
go_over@util@spinner:set_text_spinner(
Spinner,
<<"Checking packages: "/utf8,
(go_over@util@print:raw(<<"retired"/utf8>>, <<"yellow"/utf8>>))/binary>>
),
Retired_warnings = begin
_pipe@3 = Pkgs,
_pipe@4 = gleam@list:filter(
_pipe@3,
fun(P) -> erlang:element(6, P) =:= package_source_hex end
),
go_over@sources:get_retired_warnings(_pipe@4, Conf@1)
end,
Hex_warnings = gxyz@function:iff(
erlang:element(3, Conf@1) orelse not gleam@list:is_empty(
erlang:element(10, Conf@1)
),
fun() ->
Msg = case {erlang:element(3, Conf@1),
not gleam@list:is_empty(erlang:element(10, Conf@1))} of
{true, true} ->
<<"outdated & licenses"/utf8>>;
{true, false} ->
<<"outdated"/utf8>>;
{false, true} ->
<<"licenses"/utf8>>;
{false, false} ->
go_over@util@util:do_panic()
end,
go_over@util@spinner:set_text_spinner(
Spinner,
<<"Checking packages: "/utf8,
(go_over@util@print:raw(Msg, <<"brightmagenta"/utf8>>))/binary>>
),
_pipe@5 = Pkgs,
_pipe@6 = gleam@list:filter(
_pipe@5,
fun(P@1) -> erlang:element(6, P@1) =:= package_source_hex end
),
go_over@sources:get_hex_warnings(_pipe@6, Conf@1)
end,
[]
),
go_over@util@spinner:set_text_spinner(
Spinner,
<<"Filtering warnings"/utf8>>
),
Warnings = begin
_pipe@7 = lists:append(Retired_warnings, Vulnerable_warnings),
_pipe@8 = lists:append(_pipe@7, Hex_warnings),
go_over@config:filter_severity(Conf@1, _pipe@8)
end,
go_over@util@spinner:stop_spinner(Spinner),
case Warnings of
[] ->
go_over@util@print:success(<<"✅ No warnings found!"/utf8>>);
Vulns ->
print_warnings(Vulns, Conf@1)
end.