From 4eb8941eb204a27ec72296204358b52b2eacdfc3 Mon Sep 17 00:00:00 2001 From: zhongwencool Date: Mon, 21 Oct 2024 16:44:55 +0800 Subject: [PATCH] chore: add dialyzer for ci --- .github/workflows/erlang.yml | 2 ++ src/observer_cli_application.erl | 2 +- src/observer_cli_lib.erl | 4 +--- src/observer_cli_mnesia.erl | 3 +++ src/observer_cli_plugin.erl | 4 +--- src/observer_cli_process.erl | 6 ++++++ src/observer_cli_system.erl | 2 +- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/.github/workflows/erlang.yml b/.github/workflows/erlang.yml index e1005ed..b5a945f 100644 --- a/.github/workflows/erlang.yml +++ b/.github/workflows/erlang.yml @@ -20,4 +20,6 @@ jobs: run: rebar3 compile - name: xref run: rebar3 xref + - name: dialyzer + run: rebar3 dialyzer diff --git a/src/observer_cli_application.erl b/src/observer_cli_application.erl index ff4d9a4..e03c79e 100644 --- a/src/observer_cli_application.erl +++ b/src/observer_cli_application.erl @@ -14,7 +14,7 @@ %% @doc List application info --spec start(ViewOpts) -> no_return when ViewOpts :: view_opts(). +-spec start(ViewOpts) -> quit when ViewOpts :: view_opts(). start(#view_opts{app = App, auto_row = AutoRow} = ViewOpts) -> Pid = spawn_link(fun() -> ?output(?CLEAR), diff --git a/src/observer_cli_lib.erl b/src/observer_cli_lib.erl index 4aedb27..bb13157 100644 --- a/src/observer_cli_lib.erl +++ b/src/observer_cli_lib.erl @@ -35,13 +35,11 @@ uptime() -> [?W(?GREEN, Time, 16)]. %% @doc 0.982342 -> 98.23%, 1 -> 100.0% --spec to_percent(float()) -> string(). to_percent(Float) when Float < 0.1 -> [$0, erlang:float_to_list(Float * 100, [{decimals, 2}]), $%]; to_percent(Float) when Float < 1 -> [erlang:float_to_list(Float * 100, [{decimals, 2}]), $%]; to_percent(undefined) -> "******"; to_percent(_) -> "100.0%". --spec to_list(term()) -> list(). to_list(Atom) when is_atom(Atom) -> atom_to_list(Atom); to_list(Integer) when is_integer(Integer) -> integer_to_list(Integer); to_list(Pid) when is_pid(Pid) -> erlang:pid_to_list(Pid); @@ -273,7 +271,7 @@ to_pid(Str) -> quit end. --spec next_redraw(reference(), pos_integer()) -> reference(). +-spec next_redraw(reference() | ?INIT_TIME_REF, pos_integer()) -> reference(). next_redraw(LastTimeRef, Interval) -> LastTimeRef =/= ?INIT_TIME_REF andalso erlang:cancel_timer(LastTimeRef), erlang:send_after(Interval, self(), redraw). diff --git a/src/observer_cli_mnesia.erl b/src/observer_cli_mnesia.erl index 97987e3..1d232fd 100644 --- a/src/observer_cli_mnesia.erl +++ b/src/observer_cli_mnesia.erl @@ -187,6 +187,7 @@ get_table_list(HideSys, Attr) -> _ -> get_table_list2(Owner, HideSys, Attr) end. +-dialyzer([{nowarn_function, [get_table_list2/3]}]). get_table_list2(Owner, HideSys, Attr) -> {registered_name, RegName} = process_info(Owner, registered_name), WordSize = erlang:system_info(wordsize), @@ -213,6 +214,8 @@ get_table_list2(Owner, HideSys, Attr) -> end, lists:foldl(CollectFun, [], mnesia:system_info(tables)). +-dialyzer([{nowarn_function, [with_storage_type/2]}]). + with_storage_type(Id, Tab0) -> Storage = mnesia:table_info(Id, storage_type), with_storage_type(Id, Storage, Tab0). diff --git a/src/observer_cli_plugin.erl b/src/observer_cli_plugin.erl index defd9eb..21f903b 100644 --- a/src/observer_cli_plugin.erl +++ b/src/observer_cli_plugin.erl @@ -139,9 +139,7 @@ manager(ChildPid, SheetCache, ViewOpts) -> start(ViewOpts#view_opts{plug = PlugOpts#plug{plugs = NewPlugs}}); {error, _} -> manager(ChildPid, SheetCache, ViewOpts) - end; - _ -> - manager(ChildPid, SheetCache, ViewOpts) + end end. update_plugins(CurIndex, Lists, UpdateItems) -> diff --git a/src/observer_cli_process.erl b/src/observer_cli_process.erl index dc0c0d7..3625bc6 100644 --- a/src/observer_cli_process.erl +++ b/src/observer_cli_process.erl @@ -2,6 +2,12 @@ -include("observer_cli.hrl"). +-dialyzer([ + {nowarn_function, [ + render_worker/7, render_reduction_memory/4, get_chart_format/1, chart_format/2 + ]} +]). + -export([start/3]). %% lists:foldl(fun(_X, Acc) -> queue:in('NaN', Acc) end, queue:new(), lists:seq(1, 5)) diff --git a/src/observer_cli_system.erl b/src/observer_cli_system.erl index 29bd40c..c80babb 100644 --- a/src/observer_cli_system.erl +++ b/src/observer_cli_system.erl @@ -158,7 +158,7 @@ get_address(Info) -> get_dist_queue_size(Node) -> case ets:lookup(sys_dist, Node) of [] -> - 0; + not_found; [Dist] -> ConnId = element(3, Dist), {ok, _, _, Size} = erlang:dist_get_stat(ConnId),