From 77b5181299d3cbcc0a1080ef13123eb56b971070 Mon Sep 17 00:00:00 2001 From: Louis-Philippe Gauthier Date: Fri, 12 Feb 2016 11:18:43 -0500 Subject: Add support for xref_ignores --- src/rebar_prv_xref.erl | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl index f600273..45badd3 100644 --- a/src/rebar_prv_xref.erl +++ b/src/rebar_prv_xref.erl @@ -38,10 +38,10 @@ init(State) -> do(State) -> code:add_pathsa(rebar_state:code_paths(State, all_deps)), XrefChecks = prepare(State), - + XrefIgnores = rebar_state:get(State, xref_ignores, []), %% Run xref checks ?INFO("Running cross reference analysis...", []), - XrefResults = xref_checks(XrefChecks), + XrefResults = xref_checks(XrefChecks, XrefIgnores), %% Run custom queries QueryChecks = rebar_state:get(State, xref_queries, []), @@ -110,16 +110,18 @@ prepare(State) -> sets:from_list(ConfXrefChecks))), XrefChecks. -xref_checks(XrefChecks) -> - lists:foldl(fun run_xref_check/2, [], XrefChecks). +xref_checks(XrefChecks, XrefIgnores) -> + run_xref_checks(XrefChecks, XrefIgnores, []). -run_xref_check(XrefCheck, Acc) -> +run_xref_checks([], _XrefIgnores, Acc) -> + Acc; +run_xref_checks([XrefCheck | T], XrefIgnores, Acc) -> {ok, Results} = xref:analyze(xref, XrefCheck), - case filter_xref_results(XrefCheck, Results) of + case filter_xref_results(XrefCheck, XrefIgnores, Results) of [] -> - Acc; + run_xref_checks(T, XrefIgnores, Acc); FilterResult -> - [{XrefCheck, FilterResult} | Acc] + run_xref_checks(T, XrefIgnores, [{XrefCheck, FilterResult} | Acc]) end. check_query({Query, Value}, Acc) -> @@ -170,7 +172,7 @@ get_behaviour_callbacks(_XrefCheck, _Attributes) -> parse_xref_result({_, MFAt}) -> MFAt; parse_xref_result(MFAt) -> MFAt. -filter_xref_results(XrefCheck, XrefResults) -> +filter_xref_results(XrefCheck, XrefIgnores, XrefResults) -> SearchModules = lists:usort( lists:map( fun({Mt,_Ft,_At}) -> Mt; @@ -178,7 +180,7 @@ filter_xref_results(XrefCheck, XrefResults) -> (_) -> undefined end, XrefResults)), - Ignores = lists:flatmap(fun(Module) -> + Ignores = XrefIgnores ++ lists:flatmap(fun(Module) -> get_xref_ignorelist(Module, XrefCheck) end, SearchModules), -- cgit v1.1