Skip to content

Instantly share code, notes, and snippets.

@nickva
Created January 5, 2023 20:03
Show Gist options
  • Select an option

  • Save nickva/b0a6e9fc987ba5853dd49610cd399081 to your computer and use it in GitHub Desktop.

Select an option

Save nickva/b0a6e9fc987ba5853dd49610cd399081 to your computer and use it in GitHub Desktop.
Run Erlang XRef Ignoring Some Modules
xref:stop(s).
xref:start(s).
xref:set_default(s, [{verbose, false}, {warnings, false}]).
xref:add_release(s, "./src").
xref:add_release(s, code:lib_dir(), {name, otp}).
f().
IgnorePrefixes = [
"hipe", "ibrowse", "hyper", "meck", "metrics", "parse_trans", "eunit_test", "hackney",
"xmerl", "diameter", "erlfdb_nif"
].
ShouldIgnore = fun(M) ->
Ml = atom_to_list(M),
lists:any(fun(Prefix) -> lists:prefix(Prefix, Ml) end, IgnorePrefixes)
end.
IgnoreMods = fun(Res) ->
lists:filter(fun
({{FromM,_,_}, {ToM,_,_}}) ->
not (ShouldIgnore(FromM) orelse ShouldIgnore(ToM));
({M, _, _}) ->
not ShouldIgnore(M)
end, Res)
end.
FmtRow = fun
({M, F, A}) -> io:format("~s:~s/~B~n", [M, F, A]);
({{M1, F1, A1}, {M2, F2, A2}}) -> io:format("~s:~s/~B -> ~s:~s/~B~n", [M1, F1, A1, M2, F2, A2])
end.
% ***** undefined function calls ****
f(Res1), {ok, Res1} = xref:analyze(s, undefined_function_calls), [FmtRow(R) || R <- IgnoreMods(Res1)], ok.
% f(Res2), {ok, Res2} = xref:analyze(s, undefined_functions), [FmtRow(R) || R <- IgnoreMods(Res2)], ok.
% **** unused local functions ****
% f(Res3), {ok, Res3} = xref:analyze(s, locals_not_used), [FmtRow(R) || R <- IgnoreMods(Res3)], ok.
% xref:info(s).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment