From dd9a0bb8a811045f3bb7f9d0075900ed4a3a3051 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 02:55:02 +0200 Subject: Colorize the first dialyzer message --- src/rebar_dialyzer_format.erl | 369 ++++++++++++++++++++++++++++++++++++++++++ src/rebar_prv_dialyzer.erl | 14 +- 2 files changed, 371 insertions(+), 12 deletions(-) create mode 100644 src/rebar_dialyzer_format.erl (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl new file mode 100644 index 0000000..9642d8d --- /dev/null +++ b/src/rebar_dialyzer_format.erl @@ -0,0 +1,369 @@ +-module(rebar_dialyzer_format). + +-export([format/1, bad_arg/2]). + +-define(NR, "\033[0;31m"). +-define(NG, "\033[0;32m"). +-define(NB, "\033[0;34m"). +-define(NW, "\033[0;37m"). +-define(BR, "\033[1;31m"). +-define(BG, "\033[1;32m"). +-define(BB, "\033[1;34m"). +-define(BW, "\033[1;37m"). +-define(R, "\033[0m"). + +format(Warning) -> + Str = try + format_warning(Warning, fullpath) + catch + _:_ -> + dialyzer:format_warning(Warning, fullpath) + end, + case strip(Str) of + ":0: " ++ Unknown -> + Unknown; + Warning1 -> + Warning1 + end. + +strip(Warning) -> + string:strip(Warning, right, $\n). + +%%format(Fmt, Args) -> +%% Args2 = [format("~s\033[1;37m", [A]) || A <- Args], +%% format(Fmt, Args2). + +format(Fmt, Args) -> + io_lib:format(lists:flatten(Fmt), Args). + + +%% Mostrly from: https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl#L220 +%%colorize(Color, Msg) when is_integer(Color) -> +%% colorize(Color, false, Msg). + +%% colorize(Color, false, Msg) when is_integer(Color) -> +%% lists:flatten(format("\033[~B;~Bm~s\033[0m", [0, Color, Msg])); +%% colorize(Color, true, Msg) when is_integer(Color) -> +%% lists:flatten(format("\033[~B;~Bm~s\033[0m", [1, Color, Msg])). + + +%%bw(M) -> +%% colorize(37, true, M). + +%% Based on: https://github.com/erlang/otp/blob/a2670f0822fc6729df956c8ec8c381340ff0a5fb/lib/dialyzer/src/dialyzer.erl#L290 + +format_warning({Tag, {File, Line, _MFA}, Msg}, FOpt) -> + format_warning({Tag, {File, Line}, Msg}, FOpt); +format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), + is_integer(Line) -> + F = case FOpt of + fullpath -> File; + basename -> filename:basename(File) + end, + String = lists:flatten(message_to_string(Msg)), + lists:flatten(format("~s:~w: ~s", [F, Line, String])). + + +%%----------------------------------------------------------------------------- +%% Message classification and pretty-printing below. Messages appear in +%% categories and in more or less alphabetical ordering within each category. +%%----------------------------------------------------------------------------- + +%%----- Warnings for general discrepancies ---------------- +message_to_string({apply, [Args, ArgNs, FailReason, + SigArgs, SigRet, Contract]}) -> + format("Fun application with arguments ~s ", [Args]) ++ + call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); +message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) -> + format("The call ~s:~s~s requires that ~s is of type ~s not ~s\n", + [M, F, Args, Culprit, ExpectedType, FoundType]); +message_to_string({bin_construction, [Culprit, Size, Seg, Type]}) -> + format("Binary construction will fail since the ~s field ~s in" + " segment ~s has type ~s\n", [Culprit, Size, Seg, Type]); +message_to_string({call, [M, F, Args, ArgNs, FailReason, + SigArgs, SigRet, Contract]}) -> + format("The call ~w:~w~s ", [M, F, Args]) ++ + call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); +message_to_string({call_to_missing, [M, F, A]}) -> + format("Call to missing or unexported function ~w:~w/~w\n", [M, F, A]); +message_to_string({exact_eq, [Type1, Op, Type2]}) -> + format("The test ~s ~s ~s can never evaluate to 'true'\n", + [Type1, Op, Type2]); +message_to_string({fun_app_args, [Args, Type]}) -> + format("Fun application with arguments ~s will fail" + " since the function has type ~s\n", [Args, Type]); +message_to_string({fun_app_no_fun, [Op, Type, Arity]}) -> + format("Fun application will fail since ~s :: ~s" + " is not a function of arity ~w\n", [Op, Type, Arity]); +message_to_string({guard_fail, []}) -> + "Clause guard cannot succeed.\n"; +message_to_string({guard_fail, [Arg1, Infix, Arg2]}) -> + format("Guard test ~s ~s ~s can never succeed\n", [Arg1, Infix, Arg2]); +message_to_string({neg_guard_fail, [Arg1, Infix, Arg2]}) -> + format("Guard test not(~s ~s ~s) can never succeed\n", + [Arg1, Infix, Arg2]); +message_to_string({guard_fail, [Guard, Args]}) -> + format("Guard test ~w~s can never succeed\n", [Guard, Args]); +message_to_string({neg_guard_fail, [Guard, Args]}) -> + format("Guard test not(~w~s) can never succeed\n", [Guard, Args]); +message_to_string({guard_fail_pat, [Pat, Type]}) -> + format("Clause guard cannot succeed. The ~s was matched" + " against the type ~s\n", [Pat, Type]); +message_to_string({improper_list_constr, [TlType]}) -> + format("Cons will produce an improper list" + " since its 2nd argument is ~s\n", [TlType]); +message_to_string({no_return, [Type|Name]}) -> + NameString = + case Name of + [] -> "The created fun "; + [F, A] -> format("Function ~w/~w ", [F, A]) + end, + case Type of + no_match -> NameString ++ "has no clauses that will ever match\n"; + only_explicit -> NameString ++ "only terminates with explicit exception\n"; + only_normal -> NameString ++ "has no local return\n"; + both -> NameString ++ "has no local return\n" + end; +message_to_string({record_constr, [RecConstr, FieldDiffs]}) -> + format("Record construction ~s violates the" + " declared type of field ~s\n", [RecConstr, FieldDiffs]); +message_to_string({record_constr, [Name, Field, Type]}) -> + format("Record construction violates the declared type for #~w{}" + " since ~s cannot be of type ~s\n", [Name, Field, Type]); +message_to_string({record_matching, [String, Name]}) -> + format("The ~s violates the" + " declared type for #~w{}\n", [String, Name]); +message_to_string({record_match, [Pat, Type]}) -> + format("Matching of ~s tagged with a record name violates the declared" + " type of ~s\n", [Pat, Type]); +message_to_string({pattern_match, [Pat, Type]}) -> + format("The ~s can never match the type ~s\n", [Pat, Type]); +message_to_string({pattern_match_cov, [Pat, Type]}) -> + format("The ~s can never match since previous" + " clauses completely covered the type ~s\n", + [Pat, Type]); +message_to_string({unmatched_return, [Type]}) -> + format("Expression produces a value of type ~s," + " but this value is unmatched\n", [Type]); +message_to_string({unused_fun, [F, A]}) -> + format("Function ~w/~w will never be called\n", [F, A]); +%%----- Warnings for specs and contracts ------------------- +message_to_string({contract_diff, [M, F, _A, Contract, Sig]}) -> + format("Type specification ~w:~w~s" + " is not equal to the success typing: ~w:~w~s\n", + [M, F, Contract, M, F, Sig]); +message_to_string({contract_subtype, [M, F, _A, Contract, Sig]}) -> + format("Type specification ~w:~w~s" + " is a subtype of the success typing: ~w:~w~s\n", + [M, F, Contract, M, F, Sig]); +message_to_string({contract_supertype, [M, F, _A, Contract, Sig]}) -> + format("Type specification ~w:~w~s" + " is a supertype of the success typing: ~w:~w~s\n", + [M, F, Contract, M, F, Sig]); +message_to_string({contract_range, [Contract, M, F, ArgStrings, Line, CRet]}) -> + format("The contract ~w:~w~s cannot be right because the inferred" + " return for ~w~s on line ~w is ~s\n", + [M, F, Contract, F, ArgStrings, Line, CRet]); +message_to_string({invalid_contract, [M, F, A, Sig]}) -> + format("Invalid type specification for function ~w:~w/~w." + " The success typing is ~s\n", [M, F, A, Sig]); +message_to_string({extra_range, [M, F, A, ExtraRanges, SigRange]}) -> + format("The specification for ~w:~w/~w states that the function" + " might also return ~s but the inferred return is ~s\n", + [M, F, A, ExtraRanges, SigRange]); +message_to_string({overlapping_contract, [M, F, A]}) -> + format("Overloaded contract for ~w:~w/~w has overlapping domains;" + " such contracts are currently unsupported and are simply ignored\n", + [M, F, A]); +message_to_string({spec_missing_fun, [M, F, A]}) -> + format("Contract for function that does not exist: ~w:~w/~w\n", + [M, F, A]); +%%----- Warnings for opaque type violations ------------------- +message_to_string({call_with_opaque, [M, F, Args, ArgNs, ExpArgs]}) -> + format("The call ~w:~w~s contains ~s when ~s\n", + [M, F, Args, form_positions(ArgNs), form_expected(ExpArgs)]); +message_to_string({call_without_opaque, [M, F, Args, [{N,_,_}|_] = ExpectedTriples]}) -> + format([?BW, "The call", ?R, " ~w:~w~s ", ?BW, "does not have" ?R " ~s\n"], + [M, F, bad_arg(N, Args), form_expected_without_opaque(ExpectedTriples)]); +message_to_string({opaque_eq, [Type, _Op, OpaqueType]}) -> + format("Attempt to test for equality between a term of type ~s" + " and a term of opaque type ~s\n", [Type, OpaqueType]); +message_to_string({opaque_guard, [Arg1, Infix, Arg2, ArgNs]}) -> + format("Guard test ~s ~s ~s contains ~s\n", + [Arg1, Infix, Arg2, form_positions(ArgNs)]); +message_to_string({opaque_guard, [Guard, Args]}) -> + format("Guard test ~w~s breaks the opaqueness of its argument\n", + [Guard, Args]); +message_to_string({opaque_match, [Pat, OpaqueType, OpaqueTerm]}) -> + Term = if OpaqueType =:= OpaqueTerm -> "the term"; + true -> OpaqueTerm + end, + format("The attempt to match a term of type ~s against the ~s" + " breaks the opaqueness of ~s\n", [OpaqueType, Pat, Term]); +message_to_string({opaque_neq, [Type, _Op, OpaqueType]}) -> + format("Attempt to test for inequality between a term of type ~s" + " and a term of opaque type ~s\n", [Type, OpaqueType]); +message_to_string({opaque_type_test, [Fun, Args, Arg, ArgType]}) -> + format("The type test ~s~s breaks the opaqueness of the term ~s~s\n", + [Fun, Args, Arg, ArgType]); +message_to_string({opaque_size, [SizeType, Size]}) -> + format("The size ~s breaks the opaqueness of ~s\n", + [SizeType, Size]); +message_to_string({opaque_call, [M, F, Args, Culprit, OpaqueType]}) -> + format("The call ~s:~s~s breaks the opaqueness of the term ~s :: ~s\n", + [M, F, Args, Culprit, OpaqueType]); +%%----- Warnings for concurrency errors -------------------- +message_to_string({race_condition, [M, F, Args, Reason]}) -> + format("The call ~w:~w~s ~s\n", [M, F, Args, Reason]); +%%----- Warnings for behaviour errors -------------------- +message_to_string({callback_type_mismatch, [B, F, A, ST, CT]}) -> + format("The inferred return type of ~w/~w (~s) has nothing in common" + " with ~s, which is the expected return type for the callback of" + " ~w behaviour\n", [F, A, ST, CT, B]); +message_to_string({callback_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> + format("The inferred type for the ~s argument of ~w/~w (~s) is" + " not a supertype of ~s, which is expected type for this" + " argument in the callback of the ~w behaviour\n", + [ordinal(N), F, A, ST, CT, B]); +message_to_string({callback_spec_type_mismatch, [B, F, A, ST, CT]}) -> + format("The return type ~s in the specification of ~w/~w is not a" + " subtype of ~s, which is the expected return type for the" + " callback of ~w behaviour\n", [ST, F, A, CT, B]); +message_to_string({callback_spec_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> + format("The specified type for the ~s argument of ~w/~w (~s) is" + " not a supertype of ~s, which is expected type for this" + " argument in the callback of the ~w behaviour\n", + [ordinal(N), F, A, ST, CT, B]); +message_to_string({callback_missing, [B, F, A]}) -> + format("Undefined callback function ~w/~w (behaviour '~w')\n", + [F, A, B]); +message_to_string({callback_info_missing, [B]}) -> + format("Callback info about the ~w behaviour is not available\n", [B]); +%%----- Warnings for unknown functions, types, and behaviours ------------- +message_to_string({unknown_type, {M, F, A}}) -> + format("Unknown type ~w:~w/~w", [M, F, A]); +message_to_string({unknown_function, {M, F, A}}) -> + format("Unknown function ~w:~w/~w", [M, F, A]); +message_to_string({unknown_behaviour, B}) -> + format("Unknown behaviour ~w", [B]). + +%%----------------------------------------------------------------------------- +%% Auxiliary functions below +%%----------------------------------------------------------------------------- + +call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, + {IsOverloaded, Contract}) -> + PositionString = form_position_string(ArgNs), + case FailReason of + only_sig -> + case ArgNs =:= [] of + true -> + %% We do not know which argument(s) caused the failure + format("will never return since the success typing arguments" + " are ~s\n", [SigArgs]); + false -> + format("will never return since it differs in the ~s argument" + " from the success typing arguments: ~s\n", + [PositionString, SigArgs]) + end; + only_contract -> + case (ArgNs =:= []) orelse IsOverloaded of + true -> + %% We do not know which arguments caused the failure + format("breaks the contract ~s\n", [Contract]); + false -> + format("breaks the contract ~s in the ~s argument\n", + [Contract, PositionString]) + end; + both -> + format("will never return since the success typing is ~s -> ~s" + " and the contract is ~s\n", [SigArgs, SigRet, Contract]) + end. + +form_positions(ArgNs) -> + case ArgNs of + [_] -> "an opaque term as "; + [_,_|_] -> "opaque terms as " + end ++ form_position_string(ArgNs) ++ + case ArgNs of + [_] -> " argument"; + [_,_|_] -> " arguments" + end. + +%% We know which positions N are to blame; +%% the list of triples will never be empty. +form_expected_without_opaque([{N, T, TStr}]) -> + case erl_types:t_is_opaque(T) of + true -> + format([?BW, "an opaque term of type", ?NG, " ~s ", ?BW, "as "], [TStr]); + false -> + format([?BW, "a term of type ", ?NG, "~s ", ?BW, "(with opaque subterms) as "], [TStr]) + end ++ form_position_string([N]) ++ ?BW ++ " argument" ++ ?R; +form_expected_without_opaque(ExpectedTriples) -> %% TODO: can do much better here + {ArgNs, _Ts, _TStrs} = lists:unzip3(ExpectedTriples), + "opaque terms as " ++ form_position_string(ArgNs) ++ " arguments". + +form_expected(ExpectedArgs) -> + case ExpectedArgs of + [T] -> + TS = erl_types:t_to_string(T), + case erl_types:t_is_opaque(T) of + true -> format("an opaque term of type ~s is expected", [TS]); + false -> format("a structured term of type ~s is expected", [TS]) + end; + [_,_|_] -> "terms of different types are expected in these positions" + end. + +form_position_string(ArgNs) -> + case ArgNs of + [] -> ""; + [N1] -> ordinal(N1); + [_,_|_] -> + [Last|Prevs] = lists:reverse(ArgNs), + ", " ++ Head = lists:flatten([format(", ~s",[ordinal(N)]) || + N <- lists:reverse(Prevs)]), + Head ++ " and " ++ ordinal(Last) + end. + +ordinal(1) -> ?BB ++ "1" ++ ?R ++ "st"; +ordinal(2) -> ?BB ++ "2" ++ ?R ++ "nd"; +ordinal(3) -> ?BB ++ "3" ++ ?R ++ "rd"; +ordinal(N) when is_integer(N) -> format(?BB ++ "~w" ++ ?R ++ "th", [N]). + + +bad_arg(N, Args) -> + Args1 = seperate_args(Args), + Args2 = highlight(N, Args1), + join_args(Args2). + + +highlight(1, [Arg | Rest]) -> + [[?NR, Arg, ?R] | Rest]; + +highlight(N, [Arg | Rest]) -> + [Arg | highlight(N - 1, Rest)]. + +seperate_args([$( | S]) -> + seperate_args([], S, "", []). + +seperate_args([], [$,, Next | R], Arg, Args) -> + seperate_args([], R, [Next], [lists:reverse(Arg) | Args]); +seperate_args([], [$)], Arg, Args) -> + lists:reverse([lists:reverse(Arg) | Args]); +seperate_args([C | D], [C | R], Arg, Args) -> + seperate_args(D, R, [C | Arg], Args); +seperate_args(D, [${ | R], Arg, Args) -> + seperate_args([$}|D], R, [${ | Arg], Args); +seperate_args(D, [$' | R], Arg, Args) -> + seperate_args([$'|D], R, [$' | Arg], Args); +seperate_args(D, [$" | R], Arg, Args) -> + seperate_args([$"|D], R, [$" | Arg], Args); +seperate_args(D, [$( | R], Arg, Args) -> + seperate_args([$)|D], R, [$( | Arg], Args); +seperate_args(D, [$< | R], Arg, Args) -> + seperate_args([$>|D], R, [$< | Arg], Args); +seperate_args(D, [C | R], Arg, Args) -> + seperate_args(D, R, [C | Arg], Args). + +join_args(Args) -> + [$(, string:join(Args, ", "), $)]. diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index ef14b81..035155b 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -408,15 +408,8 @@ format_warnings(Output, Warnings) -> length(Warnings1). format_warnings(Warnings) -> - [format_warning(Warning) || Warning <- Warnings]. - -format_warning(Warning) -> - case strip(dialyzer:format_warning(Warning, fullpath)) of - ":0: " ++ Unknown -> - Unknown; - Warning1 -> - Warning1 - end. + [rebar_dialyzer_format:format(Warning) || Warning <- Warnings]. + console_warnings(Warnings) -> _ = [?CONSOLE("~s", [Warning]) || Warning <- Warnings], @@ -433,9 +426,6 @@ file_warnings(Output, Warnings) -> throw({output_file_error, Output, Reason}) end. -strip(Warning) -> - string:strip(Warning, right, $\n). - no_warnings() -> [no_return, no_unused, -- cgit v1.1 From 6f7f3eabb8304df8689fa9fe12b826854d14e4c2 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 03:34:25 +0200 Subject: Add 'will never return' warning to nice warnings --- src/rebar_dialyzer_format.erl | 63 ++++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 9642d8d..f18c199 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -75,14 +75,16 @@ message_to_string({apply, [Args, ArgNs, FailReason, format("Fun application with arguments ~s ", [Args]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) -> - format("The call ~s:~s~s requires that ~s is of type ~s not ~s\n", + format(?BW "The call" ?R " ~s:~s~s " ?BW "requires that" + ?R " ~s " ?BW "is of type " ?NG "~s" ?BW " not " ?NR "~s" + ?R "\n", [M, F, Args, Culprit, ExpectedType, FoundType]); message_to_string({bin_construction, [Culprit, Size, Seg, Type]}) -> format("Binary construction will fail since the ~s field ~s in" " segment ~s has type ~s\n", [Culprit, Size, Seg, Type]); message_to_string({call, [M, F, Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> - format("The call ~w:~w~s ", [M, F, Args]) ++ + format(?BW "The call" ?R " ~w:~w~s ", [M, F, bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({call_to_missing, [M, F, A]}) -> format("Call to missing or unexported function ~w:~w/~w\n", [M, F, A]); @@ -259,12 +261,13 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, case ArgNs =:= [] of true -> %% We do not know which argument(s) caused the failure - format("will never return since the success typing arguments" - " are ~s\n", [SigArgs]); + format(?BW "will never return since the success typing arguments" + " are " ?R "~s\n", [SigArgs]); false -> - format("will never return since it differs in the ~s argument" - " from the success typing arguments: ~s\n", - [PositionString, SigArgs]) + format(?BW "will never return since it differs in the" ?R + " ~s " ?BW "argument from the success typing" + " arguments:" ?R " ~s\n", + [PositionString, good_arg(ArgNs, SigArgs)]) end; only_contract -> case (ArgNs =:= []) orelse IsOverloaded of @@ -332,36 +335,60 @@ ordinal(N) when is_integer(N) -> format(?BB ++ "~w" ++ ?R ++ "th", [N]). bad_arg(N, Args) -> + color_arg(N, ?NR, Args). + +good_arg(N, Args) -> + color_arg(N, ?NG, Args). +color_arg(N, C, Args) when is_integer(N) -> + color_arg([N], C, Args); +color_arg(Ns, C, Args) -> Args1 = seperate_args(Args), - Args2 = highlight(N, Args1), + Args2 = highlight(Ns, 1, C, Args1), join_args(Args2). -highlight(1, [Arg | Rest]) -> - [[?NR, Arg, ?R] | Rest]; +highlight([], _N, _C, Rest) -> + Rest; + +highlight([N | Nr], N, C, [Arg | Rest]) -> + [[C, Arg, ?R] | highlight(Nr, N+1, C, Rest)]; -highlight(N, [Arg | Rest]) -> - [Arg | highlight(N - 1, Rest)]. +highlight(Ns, N, C, [Arg | Rest]) -> + [Arg | highlight(Ns, N + 1, C, Rest)]. seperate_args([$( | S]) -> seperate_args([], S, "", []). -seperate_args([], [$,, Next | R], Arg, Args) -> - seperate_args([], R, [Next], [lists:reverse(Arg) | Args]); +%% We strip this space since dialyzer is inconsistant in adding or not adding +%% it .... +seperate_args([], [$,, $\s | R], Arg, Args) -> + seperate_args([], R, [], [lists:reverse(Arg) | Args]); + +seperate_args([], [$, | R], Arg, Args) -> + seperate_args([], R, [], [lists:reverse(Arg) | Args]); + seperate_args([], [$)], Arg, Args) -> lists:reverse([lists:reverse(Arg) | Args]); seperate_args([C | D], [C | R], Arg, Args) -> seperate_args(D, R, [C | Arg], Args); +%% Brackets seperate_args(D, [${ | R], Arg, Args) -> seperate_args([$}|D], R, [${ | Arg], Args); -seperate_args(D, [$' | R], Arg, Args) -> - seperate_args([$'|D], R, [$' | Arg], Args); -seperate_args(D, [$" | R], Arg, Args) -> - seperate_args([$"|D], R, [$" | Arg], Args); + seperate_args(D, [$( | R], Arg, Args) -> seperate_args([$)|D], R, [$( | Arg], Args); + +seperate_args(D, [$[ | R], Arg, Args) -> + seperate_args([$]|D], R, [$[ | Arg], Args); + seperate_args(D, [$< | R], Arg, Args) -> seperate_args([$>|D], R, [$< | Arg], Args); +%% 'strings' +seperate_args(D, [$' | R], Arg, Args) -> + seperate_args([$'|D], R, [$' | Arg], Args); +seperate_args(D, [$" | R], Arg, Args) -> + seperate_args([$"|D], R, [$" | Arg], Args); + seperate_args(D, [C | R], Arg, Args) -> seperate_args(D, R, [C | Arg], Args). -- cgit v1.1 From 59cbba3f1a43647b0d6eaca4ba4c8a00c4010f62 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 06:41:59 +0200 Subject: Add more messages, split up display in more then 1 line --- src/rebar_dialyzer_format.erl | 70 ++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 27 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index f18c199..321d6e3 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -34,7 +34,7 @@ strip(Warning) -> %% format(Fmt, Args2). format(Fmt, Args) -> - io_lib:format(lists:flatten(Fmt), Args). + io_lib:format(lists:flatten(Fmt ++ ?R), Args). %% Mostrly from: https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl#L220 @@ -61,7 +61,7 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), basename -> filename:basename(File) end, String = lists:flatten(message_to_string(Msg)), - lists:flatten(format("~s:~w: ~s", [F, Line, String])). + lists:flatten(format("~s:~w~n~s", [F, Line, String])). %%----------------------------------------------------------------------------- @@ -98,7 +98,7 @@ message_to_string({fun_app_no_fun, [Op, Type, Arity]}) -> format("Fun application will fail since ~s :: ~s" " is not a function of arity ~w\n", [Op, Type, Arity]); message_to_string({guard_fail, []}) -> - "Clause guard cannot succeed.\n"; + ?BW "Clause guard cannot succeed.\n" ?R; message_to_string({guard_fail, [Arg1, Infix, Arg2]}) -> format("Guard test ~s ~s ~s can never succeed\n", [Arg1, Infix, Arg2]); message_to_string({neg_guard_fail, [Arg1, Infix, Arg2]}) -> @@ -117,14 +117,14 @@ message_to_string({improper_list_constr, [TlType]}) -> message_to_string({no_return, [Type|Name]}) -> NameString = case Name of - [] -> "The created fun "; - [F, A] -> format("Function ~w/~w ", [F, A]) + [] -> ?BW "The created fun "; + [F, A] -> format(?BW "Function " ?NR "~w/~w ", [F, A]) end, case Type of - no_match -> NameString ++ "has no clauses that will ever match\n"; - only_explicit -> NameString ++ "only terminates with explicit exception\n"; - only_normal -> NameString ++ "has no local return\n"; - both -> NameString ++ "has no local return\n" + no_match -> NameString ++ ?BW "has no clauses that will ever match\n" ?R; + only_explicit -> NameString ++ ?BW "only terminates with explicit exception\n" ?R; + only_normal -> NameString ++ ?BW "has no local return\n" ?R; + both -> NameString ++ ?BW "has no local return\n" ?R end; message_to_string({record_constr, [RecConstr, FieldDiffs]}) -> format("Record construction ~s violates the" @@ -139,11 +139,12 @@ message_to_string({record_match, [Pat, Type]}) -> format("Matching of ~s tagged with a record name violates the declared" " type of ~s\n", [Pat, Type]); message_to_string({pattern_match, [Pat, Type]}) -> - format("The ~s can never match the type ~s\n", [Pat, Type]); + format(?BW"The ~s"?BW" can never match the type "?NG"~s\n", + [bad_pat(Pat), Type]); message_to_string({pattern_match_cov, [Pat, Type]}) -> - format("The ~s can never match since previous" - " clauses completely covered the type ~s\n", - [Pat, Type]); + format(?BW "The ~s"?BW" can never match since previous" + " clauses completely covered the type "?NG"~s\n", + [bad_pat(Pat), Type]); message_to_string({unmatched_return, [Type]}) -> format("Expression produces a value of type ~s," " but this value is unmatched\n", [Type]); @@ -167,8 +168,8 @@ message_to_string({contract_range, [Contract, M, F, ArgStrings, Line, CRet]}) -> " return for ~w~s on line ~w is ~s\n", [M, F, Contract, F, ArgStrings, Line, CRet]); message_to_string({invalid_contract, [M, F, A, Sig]}) -> - format("Invalid type specification for function ~w:~w/~w." - " The success typing is ~s\n", [M, F, A, Sig]); + format(?BW "Invalid type specification for function" ?R " ~w:~w/~w." + ?BW " The success typing is" ?R " ~s\n", [M, F, A, Sig]); message_to_string({extra_range, [M, F, A, ExtraRanges, SigRange]}) -> format("The specification for ~w:~w/~w states that the function" " might also return ~s but the inferred return is ~s\n", @@ -219,13 +220,15 @@ message_to_string({race_condition, [M, F, Args, Reason]}) -> format("The call ~w:~w~s ~s\n", [M, F, Args, Reason]); %%----- Warnings for behaviour errors -------------------- message_to_string({callback_type_mismatch, [B, F, A, ST, CT]}) -> - format("The inferred return type of ~w/~w (~s) has nothing in common" - " with ~s, which is the expected return type for the callback of" - " ~w behaviour\n", [F, A, ST, CT, B]); + format(?BW"The inferred return type of"?R" ~w/~w (~s) "?BW + "has nothing in common with"?R" ~s, "?BW"which is the expected" + " return type for the callback of"?R" ~w "?BW"behaviour\n", + [F, A, ST, CT, B]); message_to_string({callback_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> - format("The inferred type for the ~s argument of ~w/~w (~s) is" - " not a supertype of ~s, which is expected type for this" - " argument in the callback of the ~w behaviour\n", + format(?BW"The inferred type for the"?R" ~s "?BW"argument of"?R + " ~w/~w (~s) "?BW"is not a supertype of"?R" ~s"?BW", which is" + "expected type for this argument in the callback of the"?R" ~w " + ?BW"behaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_spec_type_mismatch, [B, F, A, ST, CT]}) -> format("The return type ~s in the specification of ~w/~w is not a" @@ -240,7 +243,8 @@ message_to_string({callback_missing, [B, F, A]}) -> format("Undefined callback function ~w/~w (behaviour '~w')\n", [F, A, B]); message_to_string({callback_info_missing, [B]}) -> - format("Callback info about the ~w behaviour is not available\n", [B]); + format(?BW "Callback info about the " ?NR "~w" ?BW + " behaviour is not available\n" ?R, [B]); %%----- Warnings for unknown functions, types, and behaviours ------------- message_to_string({unknown_type, {M, F, A}}) -> format("Unknown type ~w:~w/~w", [M, F, A]); @@ -273,14 +277,17 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, case (ArgNs =:= []) orelse IsOverloaded of true -> %% We do not know which arguments caused the failure - format("breaks the contract ~s\n", [Contract]); + format(?BW "breaks the contract"?R" ~s\n", [Contract]); false -> - format("breaks the contract ~s in the ~s argument\n", - [Contract, PositionString]) + format(?BW "breaks the contract"?R" ~s "?BW"in the"?R + " ~s "?BW"argument\n", + [good_arg(ArgNs, Contract), PositionString]) end; both -> - format("will never return since the success typing is ~s -> ~s" - " and the contract is ~s\n", [SigArgs, SigRet, Contract]) + format(?BW "will never return since the success typing is " + ?R"~s "?BW"->"?R" ~s " ?BW"and the contract is "?R"~s\n", + [good_arg(ArgNs, SigArgs), SigRet, + good_arg(ArgNs, Contract)]) end. form_positions(ArgNs) -> @@ -334,6 +341,14 @@ ordinal(3) -> ?BB ++ "3" ++ ?R ++ "rd"; ordinal(N) when is_integer(N) -> format(?BB ++ "~w" ++ ?R ++ "th", [N]). +bad_pat("pattern " ++ P) -> + "pattern " ?NR ++ P ++ ?R; +bad_pat("variable " ++ P) -> + "variable " ?NR ++ P ++ ?R; +bad_pat(P) -> + "pattern " ?NR ++ P ++ ?R. + + bad_arg(N, Args) -> color_arg(N, ?NR, Args). @@ -394,3 +409,4 @@ seperate_args(D, [C | R], Arg, Args) -> join_args(Args) -> [$(, string:join(Args, ", "), $)]. + -- cgit v1.1 From cbbd8b60a1835a46882aacf1db326ee362ae67a7 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 06:58:48 +0200 Subject: Shorten filenames slightly --- src/rebar_dialyzer_format.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 321d6e3..a6a6574 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -57,7 +57,7 @@ format_warning({Tag, {File, Line, _MFA}, Msg}, FOpt) -> format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), is_integer(Line) -> F = case FOpt of - fullpath -> File; + fullpath -> re:replace(File, "^.*/_build/", "_build/"); basename -> filename:basename(File) end, String = lists:flatten(message_to_string(Msg)), @@ -371,9 +371,20 @@ highlight([N | Nr], N, C, [Arg | Rest]) -> highlight(Ns, N, C, [Arg | Rest]) -> [Arg | highlight(Ns, N + 1, C, Rest)]. +%% highlight([], _N, _C, Rest) -> +%% [[?NG, A, ?R] || A <- Rest]; + +%% highlight([N | Nr], N, C, [Arg | Rest]) -> +%% [[?NR, Arg, ?R] | highlight(Nr, N+1, C, Rest)]; + +%% highlight(Ns, N, C, [Arg | Rest]) -> +%% [[?NG, Arg, ?R] | highlight(Ns, N + 1, C, Rest)]. + seperate_args([$( | S]) -> seperate_args([], S, "", []). + + %% We strip this space since dialyzer is inconsistant in adding or not adding %% it .... seperate_args([], [$,, $\s | R], Arg, Args) -> -- cgit v1.1 From bba67f8b211ebd1fc50f335bbaa3e69d0633fee1 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 07:08:06 +0200 Subject: Add no local return styling --- src/rebar_dialyzer_format.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index a6a6574..e4c0183 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -149,7 +149,7 @@ message_to_string({unmatched_return, [Type]}) -> format("Expression produces a value of type ~s," " but this value is unmatched\n", [Type]); message_to_string({unused_fun, [F, A]}) -> - format("Function ~w/~w will never be called\n", [F, A]); + format(?BW "Function "?NR"~w/~w"?BW" will never be called\n", [F, A]); %%----- Warnings for specs and contracts ------------------- message_to_string({contract_diff, [M, F, _A, Contract, Sig]}) -> format("Type specification ~w:~w~s" -- cgit v1.1 From 3ea484530f07bc8cc526084c882ee4749f2a2153 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 18:29:04 +0200 Subject: Formating for inproper list construction --- src/rebar_dialyzer_format.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index e4c0183..d463958 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -100,7 +100,7 @@ message_to_string({fun_app_no_fun, [Op, Type, Arity]}) -> message_to_string({guard_fail, []}) -> ?BW "Clause guard cannot succeed.\n" ?R; message_to_string({guard_fail, [Arg1, Infix, Arg2]}) -> - format("Guard test ~s ~s ~s can never succeed\n", [Arg1, Infix, Arg2]); + format(?BW "Guard test "?R"~s ~s ~s"?BW" can never succeed\n", [Arg1, Infix, Arg2]); message_to_string({neg_guard_fail, [Arg1, Infix, Arg2]}) -> format("Guard test not(~s ~s ~s) can never succeed\n", [Arg1, Infix, Arg2]); @@ -112,8 +112,8 @@ message_to_string({guard_fail_pat, [Pat, Type]}) -> format("Clause guard cannot succeed. The ~s was matched" " against the type ~s\n", [Pat, Type]); message_to_string({improper_list_constr, [TlType]}) -> - format("Cons will produce an improper list" - " since its 2nd argument is ~s\n", [TlType]); + format(?BW "Cons will produce an improper list" + " since its "?NB"2"?R"nd"?BW" argument is"?R" ~s\n", [TlType]); message_to_string({no_return, [Type|Name]}) -> NameString = case Name of -- cgit v1.1 From 2d93ba32c1cad5e3951cc390a4b93999a70fbf37 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 19:30:28 +0200 Subject: Color the remaining functions in basic a way --- src/rebar_dialyzer_format.erl | 141 ++++++++++++++++++++++-------------------- 1 file changed, 75 insertions(+), 66 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index d463958..ae498bd 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -72,7 +72,8 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), %%----- Warnings for general discrepancies ---------------- message_to_string({apply, [Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> - format("Fun application with arguments ~s ", [Args]) ++ + format(?BW"Fun application with arguments "?R"~s ", + [bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) -> format(?BW "The call" ?R " ~s:~s~s " ?BW "requires that" @@ -80,37 +81,42 @@ message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) -> ?R "\n", [M, F, Args, Culprit, ExpectedType, FoundType]); message_to_string({bin_construction, [Culprit, Size, Seg, Type]}) -> - format("Binary construction will fail since the ~s field ~s in" - " segment ~s has type ~s\n", [Culprit, Size, Seg, Type]); + format(?BW "Binary construction will fail since the"?NB" ~s "?BW"field"?R + " ~s"?BW" in segment"?R" ~s"?BW" has type"?R" ~s\n", + [Culprit, Size, Seg, Type]); message_to_string({call, [M, F, Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> format(?BW "The call" ?R " ~w:~w~s ", [M, F, bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({call_to_missing, [M, F, A]}) -> - format("Call to missing or unexported function ~w:~w/~w\n", [M, F, A]); + format(?BW"Call to missing or unexported function "?R"~w:~w/~w\n", + [M, F, A]); message_to_string({exact_eq, [Type1, Op, Type2]}) -> - format("The test ~s ~s ~s can never evaluate to 'true'\n", + format(?BW"The test "?R"~s ~s ~s"?BW" can never evaluate to 'true'\n", [Type1, Op, Type2]); message_to_string({fun_app_args, [Args, Type]}) -> - format("Fun application with arguments ~s will fail" - " since the function has type ~s\n", [Args, Type]); + format(?BW"Fun application with arguments "?R"~s"?BW" will fail" + " since the function has type "?R"~s\n", [Args, Type]); message_to_string({fun_app_no_fun, [Op, Type, Arity]}) -> - format("Fun application will fail since ~s :: ~s" - " is not a function of arity ~w\n", [Op, Type, Arity]); + format(?BW"Fun application will fail since "?R"~s "?BW"::"?R" ~s" + " is not a function of arity "?R"~w\n", [Op, Type, Arity]); message_to_string({guard_fail, []}) -> ?BW "Clause guard cannot succeed.\n" ?R; message_to_string({guard_fail, [Arg1, Infix, Arg2]}) -> - format(?BW "Guard test "?R"~s ~s ~s"?BW" can never succeed\n", [Arg1, Infix, Arg2]); + format(?BW "Guard test "?R"~s ~s ~s"?BW" can never succeed\n", + [Arg1, Infix, Arg2]); message_to_string({neg_guard_fail, [Arg1, Infix, Arg2]}) -> - format("Guard test not(~s ~s ~s) can never succeed\n", + format(?BW "Guard test not("?R"~s ~s ~s"?BW") can never succeed\n", [Arg1, Infix, Arg2]); message_to_string({guard_fail, [Guard, Args]}) -> - format("Guard test ~w~s can never succeed\n", [Guard, Args]); + format(?BW "Guard test "?R"~w~s"?BW" can never succeed\n", + [Guard, Args]); message_to_string({neg_guard_fail, [Guard, Args]}) -> - format("Guard test not(~w~s) can never succeed\n", [Guard, Args]); + format(?BW"Guard test not("?R"~w~s"?BW") can never succeed\n", + [Guard, Args]); message_to_string({guard_fail_pat, [Pat, Type]}) -> - format("Clause guard cannot succeed. The ~s was matched" - " against the type ~s\n", [Pat, Type]); + format(?BW"Clause guard cannot succeed. The "?R"~s"?BW" was matched" + " against the type "?R"~s\n", [Pat, Type]); message_to_string({improper_list_constr, [TlType]}) -> format(?BW "Cons will produce an improper list" " since its "?NB"2"?R"nd"?BW" argument is"?R" ~s\n", [TlType]); @@ -127,17 +133,18 @@ message_to_string({no_return, [Type|Name]}) -> both -> NameString ++ ?BW "has no local return\n" ?R end; message_to_string({record_constr, [RecConstr, FieldDiffs]}) -> - format("Record construction ~s violates the" - " declared type of field ~s\n", [RecConstr, FieldDiffs]); + format(?BW"Record construction "?R"~s"?BW" violates the" + " declared type of field "?R"~s\n", [RecConstr, FieldDiffs]); message_to_string({record_constr, [Name, Field, Type]}) -> - format("Record construction violates the declared type for #~w{}" - " since ~s cannot be of type ~s\n", [Name, Field, Type]); + format(?BW"Record construction violates the declared type for "?R"#~w{}" ?BW + " since "?R"~s"?BW" cannot be of type "?R"~s\n", + [Name, Field, Type]); message_to_string({record_matching, [String, Name]}) -> - format("The ~s violates the" - " declared type for #~w{}\n", [String, Name]); + format(?BW"The "?R"~s"?BW" violates the" + " declared type for "?R"#~w{}\n", [String, Name]); message_to_string({record_match, [Pat, Type]}) -> - format("Matching of ~s tagged with a record name violates the declared" - " type of ~s\n", [Pat, Type]); + format(?BW"Matching of "?R"~s"?BW" tagged with a record name violates the" + " declared type of "?R"~s\n", [Pat, Type]); message_to_string({pattern_match, [Pat, Type]}) -> format(?BW"The ~s"?BW" can never match the type "?NG"~s\n", [bad_pat(Pat), Type]); @@ -146,78 +153,79 @@ message_to_string({pattern_match_cov, [Pat, Type]}) -> " clauses completely covered the type "?NG"~s\n", [bad_pat(Pat), Type]); message_to_string({unmatched_return, [Type]}) -> - format("Expression produces a value of type ~s," + format(?BW "Expression produces a value of type "?R"~s"?BW"," " but this value is unmatched\n", [Type]); message_to_string({unused_fun, [F, A]}) -> format(?BW "Function "?NR"~w/~w"?BW" will never be called\n", [F, A]); %%----- Warnings for specs and contracts ------------------- message_to_string({contract_diff, [M, F, _A, Contract, Sig]}) -> - format("Type specification ~w:~w~s" - " is not equal to the success typing: ~w:~w~s\n", + format(?BW"Type specification "?R"~w:~w~s"?BW + " is not equal to the success typing: "?R"~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_subtype, [M, F, _A, Contract, Sig]}) -> - format("Type specification ~w:~w~s" - " is a subtype of the success typing: ~w:~w~s\n", + format(?BW"Type specification "?R"~w:~w~s"?BW + " is a subtype of the success typing: "?R"~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_supertype, [M, F, _A, Contract, Sig]}) -> - format("Type specification ~w:~w~s" - " is a supertype of the success typing: ~w:~w~s\n", + format(?BW"Type specification "?R"~w:~w~s"?BW + " is a supertype of the success typing: "?R"~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_range, [Contract, M, F, ArgStrings, Line, CRet]}) -> - format("The contract ~w:~w~s cannot be right because the inferred" - " return for ~w~s on line ~w is ~s\n", + format(?BW"The contract "?R"~w:~w~s"?BW" cannot be right because the" + " inferred return for "?R"~w~s"?BW" on line "?R"~w"?BW" is "?R"~s\n", [M, F, Contract, F, ArgStrings, Line, CRet]); message_to_string({invalid_contract, [M, F, A, Sig]}) -> format(?BW "Invalid type specification for function" ?R " ~w:~w/~w." ?BW " The success typing is" ?R " ~s\n", [M, F, A, Sig]); message_to_string({extra_range, [M, F, A, ExtraRanges, SigRange]}) -> - format("The specification for ~w:~w/~w states that the function" - " might also return ~s but the inferred return is ~s\n", + format(?BW"The specification for "?R"~w:~w/~w"?BW" states that the function" + " might also return "?R"~s"?BW" but the inferred return is "?R"~s\n", [M, F, A, ExtraRanges, SigRange]); message_to_string({overlapping_contract, [M, F, A]}) -> - format("Overloaded contract for ~w:~w/~w has overlapping domains;" - " such contracts are currently unsupported and are simply ignored\n", - [M, F, A]); + format(?BW"Overloaded contract for "?R"~w:~w/~w"?BW" has overlapping" + " domains; such contracts are currently unsupported and are simply " + "ignored\n", [M, F, A]); message_to_string({spec_missing_fun, [M, F, A]}) -> - format("Contract for function that does not exist: ~w:~w/~w\n", + format(?BW"Contract for function that does not exist: "?R"~w:~w/~w\n", [M, F, A]); %%----- Warnings for opaque type violations ------------------- message_to_string({call_with_opaque, [M, F, Args, ArgNs, ExpArgs]}) -> - format("The call ~w:~w~s contains ~s when ~s\n", + format(?BW"The call "?R"~w:~w~s"?BW" contains "?R"~s"?BW" when "?R"~s\n", [M, F, Args, form_positions(ArgNs), form_expected(ExpArgs)]); message_to_string({call_without_opaque, [M, F, Args, [{N,_,_}|_] = ExpectedTriples]}) -> format([?BW, "The call", ?R, " ~w:~w~s ", ?BW, "does not have" ?R " ~s\n"], [M, F, bad_arg(N, Args), form_expected_without_opaque(ExpectedTriples)]); message_to_string({opaque_eq, [Type, _Op, OpaqueType]}) -> - format("Attempt to test for equality between a term of type ~s" - " and a term of opaque type ~s\n", [Type, OpaqueType]); + format(?BW"Attempt to test for equality between a term of type "?R"~s"?BW + " and a term of opaque type "?R"~s\n", [Type, OpaqueType]); message_to_string({opaque_guard, [Arg1, Infix, Arg2, ArgNs]}) -> - format("Guard test ~s ~s ~s contains ~s\n", + format(?BW"Guard test "?R"~s ~s ~s"?BW" contains "?R"~s\n", [Arg1, Infix, Arg2, form_positions(ArgNs)]); message_to_string({opaque_guard, [Guard, Args]}) -> - format("Guard test ~w~s breaks the opaqueness of its argument\n", - [Guard, Args]); + format(?BW"Guard test "?R"~w~s"?BW" breaks the opaqueness of its" + " argument\n", [Guard, Args]); message_to_string({opaque_match, [Pat, OpaqueType, OpaqueTerm]}) -> Term = if OpaqueType =:= OpaqueTerm -> "the term"; true -> OpaqueTerm end, - format("The attempt to match a term of type ~s against the ~s" - " breaks the opaqueness of ~s\n", [OpaqueType, Pat, Term]); + format(?BW"The attempt to match a term of type "?R"~s"?BW" against the" + ?R" ~s"?BW" breaks the opaqueness of "?R"~s\n", + [OpaqueType, Pat, Term]); message_to_string({opaque_neq, [Type, _Op, OpaqueType]}) -> - format("Attempt to test for inequality between a term of type ~s" - " and a term of opaque type ~s\n", [Type, OpaqueType]); + format(?BW"Attempt to test for inequality between a term of type "?R"~s" + ?BW" and a term of opaque type "?R"~s\n", [Type, OpaqueType]); message_to_string({opaque_type_test, [Fun, Args, Arg, ArgType]}) -> - format("The type test ~s~s breaks the opaqueness of the term ~s~s\n", - [Fun, Args, Arg, ArgType]); + format(?BW"The type test "?R"~s~s"?BW" breaks the opaqueness of the term " + ?R"~s~s\n", [Fun, Args, Arg, ArgType]); message_to_string({opaque_size, [SizeType, Size]}) -> - format("The size ~s breaks the opaqueness of ~s\n", + format(?BW"The size "?R"~s"?BW" breaks the opaqueness of "?R"~s\n", [SizeType, Size]); message_to_string({opaque_call, [M, F, Args, Culprit, OpaqueType]}) -> - format("The call ~s:~s~s breaks the opaqueness of the term ~s :: ~s\n", - [M, F, Args, Culprit, OpaqueType]); + format(?BW"The call "?R"~s:~s~s"?BW" breaks the opaqueness of the term"?R + " ~s :: ~s\n", [M, F, Args, Culprit, OpaqueType]); %%----- Warnings for concurrency errors -------------------- message_to_string({race_condition, [M, F, Args, Reason]}) -> - format("The call ~w:~w~s ~s\n", [M, F, Args, Reason]); + format(?BW"The call "?R"~w:~w~s ~s\n", [M, F, Args, Reason]); %%----- Warnings for behaviour errors -------------------- message_to_string({callback_type_mismatch, [B, F, A, ST, CT]}) -> format(?BW"The inferred return type of"?R" ~w/~w (~s) "?BW @@ -231,27 +239,28 @@ message_to_string({callback_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> ?BW"behaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_spec_type_mismatch, [B, F, A, ST, CT]}) -> - format("The return type ~s in the specification of ~w/~w is not a" - " subtype of ~s, which is the expected return type for the" - " callback of ~w behaviour\n", [ST, F, A, CT, B]); + format(?BW"The return type "?R"~s"?BW" in the specification of "?R + "~w/~w"?BW" is not a subtype of "?R"~s"?BW", which is the expected" + " return type for the callback of "?R"~w"?BW" behaviour\n", + [ST, F, A, CT, B]); message_to_string({callback_spec_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> - format("The specified type for the ~s argument of ~w/~w (~s) is" - " not a supertype of ~s, which is expected type for this" - " argument in the callback of the ~w behaviour\n", - [ordinal(N), F, A, ST, CT, B]); + format(?BW"The specified type for the "?R"~s"?BW" argument of "?R + "~w/~w (~s)"?BW" is not a supertype of "?R"~s"?BW", which is" + " expected type for this argument in the callback of the "?R"~w" + ?BW" behaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_missing, [B, F, A]}) -> - format("Undefined callback function ~w/~w (behaviour '~w')\n", - [F, A, B]); + format(?BW"Undefined callback function "?R"~w/~w"?BW" (behaviour " ?R + "'~w'"?BW")\n",[F, A, B]); message_to_string({callback_info_missing, [B]}) -> format(?BW "Callback info about the " ?NR "~w" ?BW " behaviour is not available\n" ?R, [B]); %%----- Warnings for unknown functions, types, and behaviours ------------- message_to_string({unknown_type, {M, F, A}}) -> - format("Unknown type ~w:~w/~w", [M, F, A]); + format(?BW"Unknown type "?NR"~w:~w/~w", [M, F, A]); message_to_string({unknown_function, {M, F, A}}) -> - format("Unknown function ~w:~w/~w", [M, F, A]); + format(?BW"Unknown function "?NR"~w:~w/~w", [M, F, A]); message_to_string({unknown_behaviour, B}) -> - format("Unknown behaviour ~w", [B]). + format(?BW"Unknown behaviour "?NR"~w", [B]). %%----------------------------------------------------------------------------- %% Auxiliary functions below -- cgit v1.1 From 5ad1687fe504199a63a9c4623fd3c7b1fe49e8fc Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 20:11:33 +0200 Subject: Remove color login from text --- src/rebar_dialyzer_format.erl | 317 +++++++++++++++++++++++------------------- 1 file changed, 176 insertions(+), 141 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index ae498bd..e40950f 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -29,12 +29,14 @@ format(Warning) -> strip(Warning) -> string:strip(Warning, right, $\n). -%%format(Fmt, Args) -> -%% Args2 = [format("~s\033[1;37m", [A]) || A <- Args], -%% format(Fmt, Args2). +%%fmt(Fmt, Args) -> +%% Args2 = [fmt("~s\033[1;37m", [A]) || A <- Args], +%% fmt(Fmt, Args2). -format(Fmt, Args) -> - io_lib:format(lists:flatten(Fmt ++ ?R), Args). +fmt(Fmt) -> + fmt(Fmt, []). +fmt(Fmt, Args) -> + io_lib:format(cfmt(Fmt), Args). %% Mostrly from: https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl#L220 @@ -42,9 +44,9 @@ format(Fmt, Args) -> %% colorize(Color, false, Msg). %% colorize(Color, false, Msg) when is_integer(Color) -> -%% lists:flatten(format("\033[~B;~Bm~s\033[0m", [0, Color, Msg])); +%% lists:flatten(fmt("\033[~B;~Bm~s\033[0m", [0, Color, Msg])); %% colorize(Color, true, Msg) when is_integer(Color) -> -%% lists:flatten(format("\033[~B;~Bm~s\033[0m", [1, Color, Msg])). +%% lists:flatten(fmt("\033[~B;~Bm~s\033[0m", [1, Color, Msg])). %%bw(M) -> @@ -61,9 +63,43 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), basename -> filename:basename(File) end, String = lists:flatten(message_to_string(Msg)), - lists:flatten(format("~s:~w~n~s", [F, Line, String])). + lists:flatten(fmt("~s:~w~n~s", [F, Line, String])). + +cfmt(S) -> + lists:flatten(cfmt_(S)) ++ ?R. + +cfmt_([$~,$!,$! | S]) -> + [?R | cfmt(S)]; + +cfmt_([$~,$!,$r | S]) -> + [?NR | cfmt(S)]; +cfmt_([$~,$!,$R | S]) -> + [?BR | cfmt(S)]; + +cfmt_([$~,$!,$g | S]) -> + [?NG | cfmt(S)]; +cfmt_([$~,$!,$G | S]) -> + [?BG | cfmt(S)]; + +cfmt_([$~,$!,$b | S]) -> + [?NB | cfmt(S)]; +cfmt_([$~,$!,$B | S]) -> + [?BB | cfmt(S)]; + +cfmt_([$~,$!,$w | S]) -> + [?NW | cfmt(S)]; +cfmt_([$~,$!,$W | S]) -> + [?BW | cfmt(S)]; + +cfmt_([$~,$~ | S]) -> + [$~,$~ | cfmt(S)]; +cfmt_([C | S]) -> + [C | cfmt(S)]; +cfmt_([]) -> + []. + %%----------------------------------------------------------------------------- %% Message classification and pretty-printing below. Messages appear in %% categories and in more or less alphabetical ordering within each category. @@ -72,195 +108,195 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), %%----- Warnings for general discrepancies ---------------- message_to_string({apply, [Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> - format(?BW"Fun application with arguments "?R"~s ", + fmt("~!WFun application with arguments ~!!~s ", [bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) -> - format(?BW "The call" ?R " ~s:~s~s " ?BW "requires that" - ?R " ~s " ?BW "is of type " ?NG "~s" ?BW " not " ?NR "~s" - ?R "\n", + fmt("~!WThe call~!! ~s:~s~s ~!Wrequires that" + "~!! ~s ~!Wis of type ~!g~s~!W not ~!r~s" + "~!!\n", [M, F, Args, Culprit, ExpectedType, FoundType]); message_to_string({bin_construction, [Culprit, Size, Seg, Type]}) -> - format(?BW "Binary construction will fail since the"?NB" ~s "?BW"field"?R - " ~s"?BW" in segment"?R" ~s"?BW" has type"?R" ~s\n", + fmt("~!WBinary construction will fail since the ~!b~s~!W field~!!" + " ~s~!W in segment~!! ~s~!W has type~!! ~s\n", [Culprit, Size, Seg, Type]); message_to_string({call, [M, F, Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> - format(?BW "The call" ?R " ~w:~w~s ", [M, F, bad_arg(ArgNs, Args)]) ++ + fmt("~!WThe call~!! ~w:~w~s ", [M, F, bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({call_to_missing, [M, F, A]}) -> - format(?BW"Call to missing or unexported function "?R"~w:~w/~w\n", + fmt("~!WCall to missing or unexported function ~!!~w:~w/~w\n", [M, F, A]); message_to_string({exact_eq, [Type1, Op, Type2]}) -> - format(?BW"The test "?R"~s ~s ~s"?BW" can never evaluate to 'true'\n", + fmt("~!WThe test ~!!~s ~s ~s~!W can never evaluate to 'true'\n", [Type1, Op, Type2]); message_to_string({fun_app_args, [Args, Type]}) -> - format(?BW"Fun application with arguments "?R"~s"?BW" will fail" - " since the function has type "?R"~s\n", [Args, Type]); + fmt("~!WFun application with arguments ~!!~s~!W will fail" + " since the function has type ~!!~s\n", [Args, Type]); message_to_string({fun_app_no_fun, [Op, Type, Arity]}) -> - format(?BW"Fun application will fail since "?R"~s "?BW"::"?R" ~s" - " is not a function of arity "?R"~w\n", [Op, Type, Arity]); + fmt("~!WFun application will fail since ~!!~s ~!W::~!! ~s" + " is not a function of arity ~!!~w\n", [Op, Type, Arity]); message_to_string({guard_fail, []}) -> - ?BW "Clause guard cannot succeed.\n" ?R; + "~!WClause guard cannot succeed.\n~!!"; message_to_string({guard_fail, [Arg1, Infix, Arg2]}) -> - format(?BW "Guard test "?R"~s ~s ~s"?BW" can never succeed\n", + fmt("~!WGuard test ~!!~s ~s ~s~!W can never succeed\n", [Arg1, Infix, Arg2]); message_to_string({neg_guard_fail, [Arg1, Infix, Arg2]}) -> - format(?BW "Guard test not("?R"~s ~s ~s"?BW") can never succeed\n", + fmt("~!WGuard test not(~!!~s ~s ~s~!W) can never succeed\n", [Arg1, Infix, Arg2]); message_to_string({guard_fail, [Guard, Args]}) -> - format(?BW "Guard test "?R"~w~s"?BW" can never succeed\n", + fmt("~!WGuard test ~!!~w~s~!W can never succeed\n", [Guard, Args]); message_to_string({neg_guard_fail, [Guard, Args]}) -> - format(?BW"Guard test not("?R"~w~s"?BW") can never succeed\n", + fmt("~!WGuard test not(~!!~w~s~!W) can never succeed\n", [Guard, Args]); message_to_string({guard_fail_pat, [Pat, Type]}) -> - format(?BW"Clause guard cannot succeed. The "?R"~s"?BW" was matched" - " against the type "?R"~s\n", [Pat, Type]); + fmt("~!WClause guard cannot succeed. The ~!!~s~!W was matched" + " against the type ~!!~s\n", [Pat, Type]); message_to_string({improper_list_constr, [TlType]}) -> - format(?BW "Cons will produce an improper list" - " since its "?NB"2"?R"nd"?BW" argument is"?R" ~s\n", [TlType]); + fmt("~!WCons will produce an improper list" + " since its ~!b2~!!nd~!W argument is~!! ~s\n", [TlType]); message_to_string({no_return, [Type|Name]}) -> NameString = case Name of - [] -> ?BW "The created fun "; - [F, A] -> format(?BW "Function " ?NR "~w/~w ", [F, A]) + [] -> "~!WThe created fun "; + [F, A] -> fmt("~!WFunction ~!r~w/~w ", [F, A]) end, case Type of - no_match -> NameString ++ ?BW "has no clauses that will ever match\n" ?R; - only_explicit -> NameString ++ ?BW "only terminates with explicit exception\n" ?R; - only_normal -> NameString ++ ?BW "has no local return\n" ?R; - both -> NameString ++ ?BW "has no local return\n" ?R + no_match -> fmt("~s~!Whas no clauses that will ever match\n",[NameString]); + only_explicit -> fmt("~s~!Wonly terminates with explicit exception\n", [NameString]); + only_normal -> fmt("~s~!W~!Whas no local return\n", [NameString]); + both -> fmt("~s~!W~!Whas no local return\n", [NameString]) end; message_to_string({record_constr, [RecConstr, FieldDiffs]}) -> - format(?BW"Record construction "?R"~s"?BW" violates the" - " declared type of field "?R"~s\n", [RecConstr, FieldDiffs]); + fmt("~!WRecord construction ~!!~s~!W violates the" + " declared type of field ~!!~s\n", [RecConstr, FieldDiffs]); message_to_string({record_constr, [Name, Field, Type]}) -> - format(?BW"Record construction violates the declared type for "?R"#~w{}" ?BW - " since "?R"~s"?BW" cannot be of type "?R"~s\n", + fmt("~!WRecord construction violates the declared type for ~!!#~w{}~!W" + " since ~!!~s~!W cannot be of type ~!!~s\n", [Name, Field, Type]); message_to_string({record_matching, [String, Name]}) -> - format(?BW"The "?R"~s"?BW" violates the" - " declared type for "?R"#~w{}\n", [String, Name]); + fmt("~!WThe ~!!~s~!W violates the" + " declared type for ~!!#~w{}\n", [String, Name]); message_to_string({record_match, [Pat, Type]}) -> - format(?BW"Matching of "?R"~s"?BW" tagged with a record name violates the" - " declared type of "?R"~s\n", [Pat, Type]); + fmt("~!WMatching of ~!!~s~!W tagged with a record name violates the" + " declared type of ~!!~s\n", [Pat, Type]); message_to_string({pattern_match, [Pat, Type]}) -> - format(?BW"The ~s"?BW" can never match the type "?NG"~s\n", + fmt("~!WThe ~s~!W can never match the type ~!g~s\n", [bad_pat(Pat), Type]); message_to_string({pattern_match_cov, [Pat, Type]}) -> - format(?BW "The ~s"?BW" can never match since previous" - " clauses completely covered the type "?NG"~s\n", + fmt("~!WThe ~s~!W can never match since previous" + " clauses completely covered the type ~!g~s\n", [bad_pat(Pat), Type]); message_to_string({unmatched_return, [Type]}) -> - format(?BW "Expression produces a value of type "?R"~s"?BW"," + fmt("~!WExpression produces a value of type ~!!~s~!W," " but this value is unmatched\n", [Type]); message_to_string({unused_fun, [F, A]}) -> - format(?BW "Function "?NR"~w/~w"?BW" will never be called\n", [F, A]); + fmt("~!WFunction ~!r~w/~w~!W will never be called\n", [F, A]); %%----- Warnings for specs and contracts ------------------- message_to_string({contract_diff, [M, F, _A, Contract, Sig]}) -> - format(?BW"Type specification "?R"~w:~w~s"?BW - " is not equal to the success typing: "?R"~w:~w~s\n", + fmt("~!WType specification ~!!~w:~w~s~!W" + " is not equal to the success typing: ~!!~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_subtype, [M, F, _A, Contract, Sig]}) -> - format(?BW"Type specification "?R"~w:~w~s"?BW - " is a subtype of the success typing: "?R"~w:~w~s\n", + fmt("~!WType specification ~!!~w:~w~s~!W" + " is a subtype of the success typing: ~!!~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_supertype, [M, F, _A, Contract, Sig]}) -> - format(?BW"Type specification "?R"~w:~w~s"?BW - " is a supertype of the success typing: "?R"~w:~w~s\n", + fmt("~!WType specification ~!!~w:~w~s~!W" + " is a supertype of the success typing: ~!!~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_range, [Contract, M, F, ArgStrings, Line, CRet]}) -> - format(?BW"The contract "?R"~w:~w~s"?BW" cannot be right because the" - " inferred return for "?R"~w~s"?BW" on line "?R"~w"?BW" is "?R"~s\n", + fmt("~!WThe contract ~!!~w:~w~s~!W cannot be right because the" + " inferred return for ~!!~w~s~!W on line ~!!~w~!W is ~!!~s\n", [M, F, Contract, F, ArgStrings, Line, CRet]); message_to_string({invalid_contract, [M, F, A, Sig]}) -> - format(?BW "Invalid type specification for function" ?R " ~w:~w/~w." - ?BW " The success typing is" ?R " ~s\n", [M, F, A, Sig]); + fmt("~!WInvalid type specification for function~!! ~w:~w/~w." + "~!W The success typing is~!! ~s\n", [M, F, A, Sig]); message_to_string({extra_range, [M, F, A, ExtraRanges, SigRange]}) -> - format(?BW"The specification for "?R"~w:~w/~w"?BW" states that the function" - " might also return "?R"~s"?BW" but the inferred return is "?R"~s\n", + fmt("~!WThe specification for ~!!~w:~w/~w~!W states that the function" + " might also return ~!!~s~!W but the inferred return is ~!!~s\n", [M, F, A, ExtraRanges, SigRange]); message_to_string({overlapping_contract, [M, F, A]}) -> - format(?BW"Overloaded contract for "?R"~w:~w/~w"?BW" has overlapping" + fmt("~!WOverloaded contract for ~!!~w:~w/~w~!W has overlapping" " domains; such contracts are currently unsupported and are simply " "ignored\n", [M, F, A]); message_to_string({spec_missing_fun, [M, F, A]}) -> - format(?BW"Contract for function that does not exist: "?R"~w:~w/~w\n", + fmt("~!WContract for function that does not exist: ~!!~w:~w/~w\n", [M, F, A]); %%----- Warnings for opaque type violations ------------------- message_to_string({call_with_opaque, [M, F, Args, ArgNs, ExpArgs]}) -> - format(?BW"The call "?R"~w:~w~s"?BW" contains "?R"~s"?BW" when "?R"~s\n", + fmt("~!WThe call ~!!~w:~w~s~!W contains ~!!~s~!W when ~!!~s\n", [M, F, Args, form_positions(ArgNs), form_expected(ExpArgs)]); message_to_string({call_without_opaque, [M, F, Args, [{N,_,_}|_] = ExpectedTriples]}) -> - format([?BW, "The call", ?R, " ~w:~w~s ", ?BW, "does not have" ?R " ~s\n"], - [M, F, bad_arg(N, Args), form_expected_without_opaque(ExpectedTriples)]); + fmt("~!WThe call ~!!~w:~w~s ~!Wdoes not have~!! ~s\n", + [M, F, bad_arg(N, Args), form_expected_without_opaque(ExpectedTriples)]); message_to_string({opaque_eq, [Type, _Op, OpaqueType]}) -> - format(?BW"Attempt to test for equality between a term of type "?R"~s"?BW - " and a term of opaque type "?R"~s\n", [Type, OpaqueType]); + fmt("~!WAttempt to test for equality between a term of type ~!!~s~!W" + " and a term of opaque type ~!!~s\n", [Type, OpaqueType]); message_to_string({opaque_guard, [Arg1, Infix, Arg2, ArgNs]}) -> - format(?BW"Guard test "?R"~s ~s ~s"?BW" contains "?R"~s\n", + fmt("~!WGuard test ~!!~s ~s ~s~!W contains ~!!~s\n", [Arg1, Infix, Arg2, form_positions(ArgNs)]); message_to_string({opaque_guard, [Guard, Args]}) -> - format(?BW"Guard test "?R"~w~s"?BW" breaks the opaqueness of its" + fmt("~!WGuard test ~!!~w~s~!W breaks the opaqueness of its" " argument\n", [Guard, Args]); message_to_string({opaque_match, [Pat, OpaqueType, OpaqueTerm]}) -> Term = if OpaqueType =:= OpaqueTerm -> "the term"; true -> OpaqueTerm end, - format(?BW"The attempt to match a term of type "?R"~s"?BW" against the" - ?R" ~s"?BW" breaks the opaqueness of "?R"~s\n", + fmt("~!WThe attempt to match a term of type ~!!~s~!W against the" + "~!! ~s~!W breaks the opaqueness of ~!!~s\n", [OpaqueType, Pat, Term]); message_to_string({opaque_neq, [Type, _Op, OpaqueType]}) -> - format(?BW"Attempt to test for inequality between a term of type "?R"~s" - ?BW" and a term of opaque type "?R"~s\n", [Type, OpaqueType]); + fmt("~!WAttempt to test for inequality between a term of type ~!!~s" + "~!W and a term of opaque type ~!!~s\n", [Type, OpaqueType]); message_to_string({opaque_type_test, [Fun, Args, Arg, ArgType]}) -> - format(?BW"The type test "?R"~s~s"?BW" breaks the opaqueness of the term " - ?R"~s~s\n", [Fun, Args, Arg, ArgType]); + fmt("~!WThe type test ~!!~s~s~!W breaks the opaqueness of the term " + "~!!~s~s\n", [Fun, Args, Arg, ArgType]); message_to_string({opaque_size, [SizeType, Size]}) -> - format(?BW"The size "?R"~s"?BW" breaks the opaqueness of "?R"~s\n", + fmt("~!WThe size ~!!~s~!W breaks the opaqueness of ~!!~s\n", [SizeType, Size]); message_to_string({opaque_call, [M, F, Args, Culprit, OpaqueType]}) -> - format(?BW"The call "?R"~s:~s~s"?BW" breaks the opaqueness of the term"?R + fmt("~!WThe call ~!!~s:~s~s~!W breaks the opaqueness of the term~!!" " ~s :: ~s\n", [M, F, Args, Culprit, OpaqueType]); %%----- Warnings for concurrency errors -------------------- message_to_string({race_condition, [M, F, Args, Reason]}) -> - format(?BW"The call "?R"~w:~w~s ~s\n", [M, F, Args, Reason]); + fmt("~!WThe call ~!!~w:~w~s ~s\n", [M, F, Args, Reason]); %%----- Warnings for behaviour errors -------------------- message_to_string({callback_type_mismatch, [B, F, A, ST, CT]}) -> - format(?BW"The inferred return type of"?R" ~w/~w (~s) "?BW - "has nothing in common with"?R" ~s, "?BW"which is the expected" - " return type for the callback of"?R" ~w "?BW"behaviour\n", + fmt("~!WThe inferred return type of~!! ~w/~w (~s) ~!W" + "has nothing in common with~!! ~s, ~!Wwhich is the expected" + " return type for the callback of~!! ~w ~!Wbehaviour\n", [F, A, ST, CT, B]); message_to_string({callback_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> - format(?BW"The inferred type for the"?R" ~s "?BW"argument of"?R - " ~w/~w (~s) "?BW"is not a supertype of"?R" ~s"?BW", which is" - "expected type for this argument in the callback of the"?R" ~w " - ?BW"behaviour\n", + fmt("~!WThe inferred type for the~!! ~s ~!Wargument of~!!" + " ~w/~w (~s) ~!Wis not a supertype of~!! ~s~!W, which is" + "expected type for this argument in the callback of the~!! ~w " + "~!Wbehaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_spec_type_mismatch, [B, F, A, ST, CT]}) -> - format(?BW"The return type "?R"~s"?BW" in the specification of "?R - "~w/~w"?BW" is not a subtype of "?R"~s"?BW", which is the expected" - " return type for the callback of "?R"~w"?BW" behaviour\n", + fmt("~!WThe return type ~!!~s~!W in the specification of ~!!" + "~w/~w~!W is not a subtype of ~!!~s~!W, which is the expected" + " return type for the callback of ~!!~w~!W behaviour\n", [ST, F, A, CT, B]); message_to_string({callback_spec_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> - format(?BW"The specified type for the "?R"~s"?BW" argument of "?R - "~w/~w (~s)"?BW" is not a supertype of "?R"~s"?BW", which is" - " expected type for this argument in the callback of the "?R"~w" - ?BW" behaviour\n", [ordinal(N), F, A, ST, CT, B]); + fmt("~!WThe specified type for the ~!!~s~!W argument of ~!!" + "~w/~w (~s)~!W is not a supertype of ~!!~s~!W, which is" + " expected type for this argument in the callback of the ~!!~w" + "~!W behaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_missing, [B, F, A]}) -> - format(?BW"Undefined callback function "?R"~w/~w"?BW" (behaviour " ?R - "'~w'"?BW")\n",[F, A, B]); + fmt("~!WUndefined callback function ~!!~w/~w~!W (behaviour ~!!" + "'~w'~!W)\n",[F, A, B]); message_to_string({callback_info_missing, [B]}) -> - format(?BW "Callback info about the " ?NR "~w" ?BW - " behaviour is not available\n" ?R, [B]); + fmt("~!WCallback info about the ~!r~w~!W" + " behaviour is not available\n", [B]); %%----- Warnings for unknown functions, types, and behaviours ------------- message_to_string({unknown_type, {M, F, A}}) -> - format(?BW"Unknown type "?NR"~w:~w/~w", [M, F, A]); + fmt("~!WUnknown type ~!r~w:~w/~w", [M, F, A]); message_to_string({unknown_function, {M, F, A}}) -> - format(?BW"Unknown function "?NR"~w:~w/~w", [M, F, A]); + fmt("~!WUnknown function ~!r~w:~w/~w", [M, F, A]); message_to_string({unknown_behaviour, B}) -> - format(?BW"Unknown behaviour "?NR"~w", [B]). + fmt("~!WUnknown behaviour ~!r~w", [B]). %%----------------------------------------------------------------------------- %% Auxiliary functions below @@ -274,27 +310,27 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, case ArgNs =:= [] of true -> %% We do not know which argument(s) caused the failure - format(?BW "will never return since the success typing arguments" - " are " ?R "~s\n", [SigArgs]); + fmt("~!Wwill never return since the success typing arguments" + " are ~!!~s\n", [SigArgs]); false -> - format(?BW "will never return since it differs in the" ?R - " ~s " ?BW "argument from the success typing" - " arguments:" ?R " ~s\n", + fmt("~!Wwill never return since it differs in the~!!" + " ~s ~!Wargument from the success typing" + " arguments:~!! ~s\n", [PositionString, good_arg(ArgNs, SigArgs)]) end; only_contract -> case (ArgNs =:= []) orelse IsOverloaded of true -> %% We do not know which arguments caused the failure - format(?BW "breaks the contract"?R" ~s\n", [Contract]); + fmt("~!Wbreaks the contract~!! ~s\n", [Contract]); false -> - format(?BW "breaks the contract"?R" ~s "?BW"in the"?R - " ~s "?BW"argument\n", + fmt("~!Wbreaks the contract~!! ~s ~!Win the~!!" + " ~s ~!Wargument\n", [good_arg(ArgNs, Contract), PositionString]) end; both -> - format(?BW "will never return since the success typing is " - ?R"~s "?BW"->"?R" ~s " ?BW"and the contract is "?R"~s\n", + fmt("~!Wwill never return since the success typing is " + "~!!~s ~!W->~!! ~s ~!Wand the contract is ~!!~s\n", [good_arg(ArgNs, SigArgs), SigRet, good_arg(ArgNs, Contract)]) end. @@ -312,12 +348,14 @@ form_positions(ArgNs) -> %% We know which positions N are to blame; %% the list of triples will never be empty. form_expected_without_opaque([{N, T, TStr}]) -> - case erl_types:t_is_opaque(T) of - true -> - format([?BW, "an opaque term of type", ?NG, " ~s ", ?BW, "as "], [TStr]); - false -> - format([?BW, "a term of type ", ?NG, "~s ", ?BW, "(with opaque subterms) as "], [TStr]) - end ++ form_position_string([N]) ++ ?BW ++ " argument" ++ ?R; + FStr = case erl_types:t_is_opaque(T) of + true -> + "~!Wan opaque term of type~!g ~s ~!Was "; + false -> + "~!Wa term of type ~!g~s ~!W(with opaque subterms) as " + end ++ form_position_string([N]) ++ "~!W argument", + fmt(FStr, [TStr]); + form_expected_without_opaque(ExpectedTriples) -> %% TODO: can do much better here {ArgNs, _Ts, _TStrs} = lists:unzip3(ExpectedTriples), "opaque terms as " ++ form_position_string(ArgNs) ++ " arguments". @@ -327,10 +365,13 @@ form_expected(ExpectedArgs) -> [T] -> TS = erl_types:t_to_string(T), case erl_types:t_is_opaque(T) of - true -> format("an opaque term of type ~s is expected", [TS]); - false -> format("a structured term of type ~s is expected", [TS]) + true -> fmt("~!Wan opaque term of type ~!!~s~!W is" + " expected", [TS]); + false -> fmt("~!Wa structured term of type ~!!~s~!W is" + " expected", [TS]) end; - [_,_|_] -> "terms of different types are expected in these positions" + [_,_|_] -> fmt("~!Wterms of different types are expected in these" + " positions", []) end. form_position_string(ArgNs) -> @@ -339,30 +380,30 @@ form_position_string(ArgNs) -> [N1] -> ordinal(N1); [_,_|_] -> [Last|Prevs] = lists:reverse(ArgNs), - ", " ++ Head = lists:flatten([format(", ~s",[ordinal(N)]) || + ", " ++ Head = lists:flatten([fmt(", ~s",[ordinal(N)]) || N <- lists:reverse(Prevs)]), Head ++ " and " ++ ordinal(Last) end. -ordinal(1) -> ?BB ++ "1" ++ ?R ++ "st"; -ordinal(2) -> ?BB ++ "2" ++ ?R ++ "nd"; -ordinal(3) -> ?BB ++ "3" ++ ?R ++ "rd"; -ordinal(N) when is_integer(N) -> format(?BB ++ "~w" ++ ?R ++ "th", [N]). +ordinal(1) -> fmt("~!B1~!!st"); +ordinal(2) -> fmt("~!B2~!!nd"); +ordinal(3) -> fmt("~!B3~!!rd"); +ordinal(N) when is_integer(N) -> fmt("~!B~w~!!th", [N]). bad_pat("pattern " ++ P) -> - "pattern " ?NR ++ P ++ ?R; + fmt("pattern ~!r~s",[P]); bad_pat("variable " ++ P) -> - "variable " ?NR ++ P ++ ?R; + fmt("variable ~!r~s",[P]); bad_pat(P) -> - "pattern " ?NR ++ P ++ ?R. + fmt("~!r~s",[P]). bad_arg(N, Args) -> - color_arg(N, ?NR, Args). + color_arg(N, g, Args). good_arg(N, Args) -> - color_arg(N, ?NG, Args). + color_arg(N, r, Args). color_arg(N, C, Args) when is_integer(N) -> color_arg([N], C, Args); color_arg(Ns, C, Args) -> @@ -374,27 +415,21 @@ color_arg(Ns, C, Args) -> highlight([], _N, _C, Rest) -> Rest; -highlight([N | Nr], N, C, [Arg | Rest]) -> - [[C, Arg, ?R] | highlight(Nr, N+1, C, Rest)]; +highlight([N | Nr], N, g, [Arg | Rest]) -> + [fmt("~!g~s", [Arg]) | highlight(Nr, N+1, g, Rest)]; + +highlight([N | Nr], N, r, [Arg | Rest]) -> + [fmt("~!r~s", [Arg]) | highlight(Nr, N+1, r, Rest)]; highlight(Ns, N, C, [Arg | Rest]) -> [Arg | highlight(Ns, N + 1, C, Rest)]. -%% highlight([], _N, _C, Rest) -> -%% [[?NG, A, ?R] || A <- Rest]; - -%% highlight([N | Nr], N, C, [Arg | Rest]) -> -%% [[?NR, Arg, ?R] | highlight(Nr, N+1, C, Rest)]; - -%% highlight(Ns, N, C, [Arg | Rest]) -> -%% [[?NG, Arg, ?R] | highlight(Ns, N + 1, C, Rest)]. - seperate_args([$( | S]) -> seperate_args([], S, "", []). -%% We strip this space since dialyzer is inconsistant in adding or not adding +%% We strip this space since dialyzer is inconsistant in adding or not adding %% it .... seperate_args([], [$,, $\s | R], Arg, Args) -> seperate_args([], R, [], [lists:reverse(Arg) | Args]); -- cgit v1.1 From a6f067cb045fc008a5f78da03669f40755fb8d46 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 20:15:15 +0200 Subject: Add missing colors to cfmt --- src/rebar_dialyzer_format.erl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index e40950f..0057b2d 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -4,11 +4,17 @@ -define(NR, "\033[0;31m"). -define(NG, "\033[0;32m"). +-define(NY, "\033[0;33m"). -define(NB, "\033[0;34m"). +-define(NM, "\033[0;35m"). +-define(NC, "\033[0;36m"). -define(NW, "\033[0;37m"). -define(BR, "\033[1;31m"). -define(BG, "\033[1;32m"). +-define(NY, "\033[1;33m"). -define(BB, "\033[1;34m"). +-define(BM, "\033[1;35m"). +-define(BC, "\033[1;36m"). -define(BW, "\033[1;37m"). -define(R, "\033[0m"). @@ -83,11 +89,26 @@ cfmt_([$~,$!,$g | S]) -> cfmt_([$~,$!,$G | S]) -> [?BG | cfmt(S)]; +cfmt_([$~,$!,$y | S]) -> + [?NY | cfmt(S)]; +cfmt_([$~,$!,$Y | S]) -> + [?BY | cfmt(S)]; + cfmt_([$~,$!,$b | S]) -> [?NB | cfmt(S)]; cfmt_([$~,$!,$B | S]) -> [?BB | cfmt(S)]; +cfmt_([$~,$!,$m | S]) -> + [?NM | cfmt(S)]; +cfmt_([$~,$!,$M | S]) -> + [?BM | cfmt(S)]; + +cfmt_([$~,$!,$c | S]) -> + [?NC | cfmt(S)]; +cfmt_([$~,$!,$C | S]) -> + [?BC | cfmt(S)]; + cfmt_([$~,$!,$w | S]) -> [?NW | cfmt(S)]; cfmt_([$~,$!,$W | S]) -> -- cgit v1.1 From e6ef19ecb3ae489ac0996b39d87df8d85905fd31 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 20:32:03 +0200 Subject: Make it easy to switch colors off in cfmt --- src/rebar_dialyzer_format.erl | 106 +++++++++++++++++++++++------------------- 1 file changed, 58 insertions(+), 48 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 0057b2d..3f3e1c8 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -1,6 +1,7 @@ -module(rebar_dialyzer_format). --export([format/1, bad_arg/2]). +-export([format/1]). + -define(NR, "\033[0;31m"). -define(NG, "\033[0;32m"). @@ -11,7 +12,7 @@ -define(NW, "\033[0;37m"). -define(BR, "\033[1;31m"). -define(BG, "\033[1;32m"). --define(NY, "\033[1;33m"). +-define(BY, "\033[1;33m"). -define(BB, "\033[1;34m"). -define(BM, "\033[1;35m"). -define(BC, "\033[1;36m"). @@ -19,6 +20,7 @@ -define(R, "\033[0m"). format(Warning) -> + format_warning(Warning, fullpath), Str = try format_warning(Warning, fullpath) catch @@ -72,53 +74,61 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), lists:flatten(fmt("~s:~w~n~s", [F, Line, String])). - cfmt(S) -> - lists:flatten(cfmt_(S)) ++ ?R. - -cfmt_([$~,$!,$! | S]) -> - [?R | cfmt(S)]; - -cfmt_([$~,$!,$r | S]) -> - [?NR | cfmt(S)]; -cfmt_([$~,$!,$R | S]) -> - [?BR | cfmt(S)]; - -cfmt_([$~,$!,$g | S]) -> - [?NG | cfmt(S)]; -cfmt_([$~,$!,$G | S]) -> - [?BG | cfmt(S)]; - -cfmt_([$~,$!,$y | S]) -> - [?NY | cfmt(S)]; -cfmt_([$~,$!,$Y | S]) -> - [?BY | cfmt(S)]; - -cfmt_([$~,$!,$b | S]) -> - [?NB | cfmt(S)]; -cfmt_([$~,$!,$B | S]) -> - [?BB | cfmt(S)]; - -cfmt_([$~,$!,$m | S]) -> - [?NM | cfmt(S)]; -cfmt_([$~,$!,$M | S]) -> - [?BM | cfmt(S)]; - -cfmt_([$~,$!,$c | S]) -> - [?NC | cfmt(S)]; -cfmt_([$~,$!,$C | S]) -> - [?BC | cfmt(S)]; - -cfmt_([$~,$!,$w | S]) -> - [?NW | cfmt(S)]; -cfmt_([$~,$!,$W | S]) -> - [?BW | cfmt(S)]; - -cfmt_([$~,$~ | S]) -> - [$~,$~ | cfmt(S)]; -cfmt_([C | S]) -> - [C | cfmt(S)]; -cfmt_([]) -> + cfmt(S, true). +cfmt(S, true) -> + lists:flatten(cfmt_(S, true)) ++ ?R; +cfmt(S, false) -> + lists:flatten(cfmt_(S, false)). + +cfmt_([$~,$!,_C | S], false) -> + cfmt_(S, false); + +cfmt_([$~,$!,$! | S], Enabled) -> + [?R | cfmt_(S, Enabled)]; + +cfmt_([$~,$!,$r | S], Enabled) -> + [?NR | cfmt_(S, Enabled)]; +cfmt_([$~,$!,$R | S], Enabled) -> + [?BR | cfmt_(S, Enabled)]; + +cfmt_([$~,$!,$g | S], Enabled) -> + [?NG | cfmt_(S, Enabled)]; +cfmt_([$~,$!,$G | S], Enabled) -> + [?BG | cfmt_(S, Enabled)]; + +cfmt_([$~,$!,$y | S], Enabled) -> + [?NY | cfmt_(S, Enabled)]; +cfmt_([$~,$!,$Y | S], Enabled) -> + [?BY | cfmt_(S, Enabled)]; + +cfmt_([$~,$!,$b | S], Enabled) -> + [?NB | cfmt_(S, Enabled)]; +cfmt_([$~,$!,$B | S], Enabled) -> + [?BB | cfmt_(S, Enabled)]; + +cfmt_([$~,$!,$m | S], Enabled) -> + [?NM | cfmt_(S, Enabled)]; +cfmt_([$~,$!,$M | S], Enabled) -> + [?BM | cfmt_(S, Enabled)]; + +cfmt_([$~,$!,$c | S], Enabled) -> + [?NC | cfmt_(S, Enabled)]; +cfmt_([$~,$!,$C | S], Enabled) -> + [?BC | cfmt_(S, Enabled)]; + +cfmt_([$~,$!,$w | S], Enabled) -> + [?NW | cfmt_(S, Enabled)]; +cfmt_([$~,$!,$W | S], Enabled) -> + [?BW | cfmt_(S, Enabled)]; + +cfmt_([$~,$~ | S], Enabled) -> + [$~,$~ | cfmt_(S, Enabled)]; + +cfmt_([C | S], Enabled) -> + [C | cfmt_(S, Enabled)]; + +cfmt_([], _Enabled) -> []. %%----------------------------------------------------------------------------- -- cgit v1.1 From c49327c8177cd46f3285b43fe08c929a83add154 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 20:35:21 +0200 Subject: Check term cap for color output --- src/rebar_dialyzer_format.erl | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 3f3e1c8..56a30aa 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -47,21 +47,6 @@ fmt(Fmt, Args) -> io_lib:format(cfmt(Fmt), Args). -%% Mostrly from: https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl#L220 -%%colorize(Color, Msg) when is_integer(Color) -> -%% colorize(Color, false, Msg). - -%% colorize(Color, false, Msg) when is_integer(Color) -> -%% lists:flatten(fmt("\033[~B;~Bm~s\033[0m", [0, Color, Msg])); -%% colorize(Color, true, Msg) when is_integer(Color) -> -%% lists:flatten(fmt("\033[~B;~Bm~s\033[0m", [1, Color, Msg])). - - -%%bw(M) -> -%% colorize(37, true, M). - -%% Based on: https://github.com/erlang/otp/blob/a2670f0822fc6729df956c8ec8c381340ff0a5fb/lib/dialyzer/src/dialyzer.erl#L290 - format_warning({Tag, {File, Line, _MFA}, Msg}, FOpt) -> format_warning({Tag, {File, Line}, Msg}, FOpt); format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), @@ -74,8 +59,24 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), lists:flatten(fmt("~s:~w~n~s", [F, Line, String])). +%% FROM https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl +%% @doc Query the term enviroment +%% For reasons of simplicity, we don't parse terminal capabilities yet, although +%% a later version could do so. Rather, we provide a simple match-list of terminal +%% capabilities. +%% @end +-spec query_term_env() -> full | dumb. +query_term_env() -> + term_capabilities(os:getenv("TERM")). + +-spec term_capabilities(string()) -> full | dumb. +term_capabilities("xterm") -> full; +term_capabilities("dumb") -> dumb; +term_capabilities(_) -> full. %% Default to the backwards compatible version. + + cfmt(S) -> - cfmt(S, true). + cfmt(S, query_term_env() =:= full). cfmt(S, true) -> lists:flatten(cfmt_(S, true)) ++ ?R; cfmt(S, false) -> -- cgit v1.1 From de7b8b84bff1987b9ae98442cdfcaa0c3f1230e0 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 20:41:36 +0200 Subject: Remove dubplicated call to format_warning --- src/rebar_dialyzer_format.erl | 1 - 1 file changed, 1 deletion(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 56a30aa..ae5f6ef 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -20,7 +20,6 @@ -define(R, "\033[0m"). format(Warning) -> - format_warning(Warning, fullpath), Str = try format_warning(Warning, fullpath) catch -- cgit v1.1 From ffe84add6799e67e0b4f5fbca2b0b6f1da87d363 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 21:40:04 +0200 Subject: Fix colors for bad and good args --- src/rebar_dialyzer_format.erl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index ae5f6ef..5e84049 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -431,10 +431,11 @@ bad_pat(P) -> bad_arg(N, Args) -> - color_arg(N, g, Args). + color_arg(N, r, Args). good_arg(N, Args) -> - color_arg(N, r, Args). + color_arg(N, g, Args). + color_arg(N, C, Args) when is_integer(N) -> color_arg([N], C, Args); color_arg(Ns, C, Args) -> -- cgit v1.1 From f0812710e38dc1492faf3e141dd51ac7d2be6de4 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 22:11:30 +0200 Subject: Enable highlighting in contracts --- src/rebar_dialyzer_format.erl | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 5e84049..1f9e241 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -1,7 +1,6 @@ -module(rebar_dialyzer_format). --export([format/1]). - +-export([format/1, bad_arg/2, seperate_args/1]). -define(NR, "\033[0;31m"). -define(NG, "\033[0;32m"). @@ -353,11 +352,11 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, case (ArgNs =:= []) orelse IsOverloaded of true -> %% We do not know which arguments caused the failure - fmt("~!Wbreaks the contract~!! ~s\n", [Contract]); + fmt("~!Wbreaks the contract~!! ~s\n", [good_arg(ArgNs, Contract)]); false -> fmt("~!Wbreaks the contract~!! ~s ~!Win the~!!" " ~s ~!Wargument\n", - [good_arg(ArgNs, Contract), PositionString]) + [good_arg(ArgNs, Contract), PositionString]) end; both -> fmt("~!Wwill never return since the success typing is " @@ -439,10 +438,9 @@ good_arg(N, Args) -> color_arg(N, C, Args) when is_integer(N) -> color_arg([N], C, Args); color_arg(Ns, C, Args) -> - Args1 = seperate_args(Args), + {Args1, Rest} =seperate_args(Args), Args2 = highlight(Ns, 1, C, Args1), - join_args(Args2). - + join_args(Args2) ++ Rest. highlight([], _N, _C, Rest) -> Rest; @@ -469,8 +467,8 @@ seperate_args([], [$,, $\s | R], Arg, Args) -> seperate_args([], [$, | R], Arg, Args) -> seperate_args([], R, [], [lists:reverse(Arg) | Args]); -seperate_args([], [$)], Arg, Args) -> - lists:reverse([lists:reverse(Arg) | Args]); +seperate_args([], [$) | Rest], Arg, Args) -> + {lists:reverse([lists:reverse(Arg) | Args]), Rest}; seperate_args([C | D], [C | R], Arg, Args) -> seperate_args(D, R, [C | Arg], Args); %% Brackets -- cgit v1.1 From f49ddaaf7588b9a73aaf5a7cb85f00faadf03948 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 22:23:32 +0200 Subject: Fix some indentation and add debug on format errors --- src/rebar_dialyzer_format.erl | 157 +++++++++++++++++++++--------------------- 1 file changed, 80 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 1f9e241..ef8eab1 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -1,6 +1,8 @@ -module(rebar_dialyzer_format). --export([format/1, bad_arg/2, seperate_args/1]). +-include("rebar.hrl"). + +-export([format/1]). -define(NR, "\033[0;31m"). -define(NG, "\033[0;32m"). @@ -22,7 +24,9 @@ format(Warning) -> Str = try format_warning(Warning, fullpath) catch - _:_ -> + Error:Reason -> + ?DEBUG("Failed to pretty format warning: ~p:~p", + [Error, Reason]), dialyzer:format_warning(Warning, fullpath) end, case strip(Str) of @@ -139,53 +143,53 @@ cfmt_([], _Enabled) -> message_to_string({apply, [Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> fmt("~!WFun application with arguments ~!!~s ", - [bad_arg(ArgNs, Args)]) ++ + [bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) -> fmt("~!WThe call~!! ~s:~s~s ~!Wrequires that" - "~!! ~s ~!Wis of type ~!g~s~!W not ~!r~s" - "~!!\n", - [M, F, Args, Culprit, ExpectedType, FoundType]); + "~!! ~s ~!Wis of type ~!g~s~!W not ~!r~s" + "~!!\n", + [M, F, Args, Culprit, ExpectedType, FoundType]); message_to_string({bin_construction, [Culprit, Size, Seg, Type]}) -> fmt("~!WBinary construction will fail since the ~!b~s~!W field~!!" - " ~s~!W in segment~!! ~s~!W has type~!! ~s\n", - [Culprit, Size, Seg, Type]); + " ~s~!W in segment~!! ~s~!W has type~!! ~s\n", + [Culprit, Size, Seg, Type]); message_to_string({call, [M, F, Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> fmt("~!WThe call~!! ~w:~w~s ", [M, F, bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({call_to_missing, [M, F, A]}) -> fmt("~!WCall to missing or unexported function ~!!~w:~w/~w\n", - [M, F, A]); + [M, F, A]); message_to_string({exact_eq, [Type1, Op, Type2]}) -> fmt("~!WThe test ~!!~s ~s ~s~!W can never evaluate to 'true'\n", - [Type1, Op, Type2]); + [Type1, Op, Type2]); message_to_string({fun_app_args, [Args, Type]}) -> fmt("~!WFun application with arguments ~!!~s~!W will fail" - " since the function has type ~!!~s\n", [Args, Type]); + " since the function has type ~!!~s\n", [Args, Type]); message_to_string({fun_app_no_fun, [Op, Type, Arity]}) -> fmt("~!WFun application will fail since ~!!~s ~!W::~!! ~s" - " is not a function of arity ~!!~w\n", [Op, Type, Arity]); + " is not a function of arity ~!!~w\n", [Op, Type, Arity]); message_to_string({guard_fail, []}) -> "~!WClause guard cannot succeed.\n~!!"; message_to_string({guard_fail, [Arg1, Infix, Arg2]}) -> fmt("~!WGuard test ~!!~s ~s ~s~!W can never succeed\n", - [Arg1, Infix, Arg2]); + [Arg1, Infix, Arg2]); message_to_string({neg_guard_fail, [Arg1, Infix, Arg2]}) -> fmt("~!WGuard test not(~!!~s ~s ~s~!W) can never succeed\n", - [Arg1, Infix, Arg2]); + [Arg1, Infix, Arg2]); message_to_string({guard_fail, [Guard, Args]}) -> fmt("~!WGuard test ~!!~w~s~!W can never succeed\n", - [Guard, Args]); + [Guard, Args]); message_to_string({neg_guard_fail, [Guard, Args]}) -> fmt("~!WGuard test not(~!!~w~s~!W) can never succeed\n", - [Guard, Args]); + [Guard, Args]); message_to_string({guard_fail_pat, [Pat, Type]}) -> fmt("~!WClause guard cannot succeed. The ~!!~s~!W was matched" - " against the type ~!!~s\n", [Pat, Type]); + " against the type ~!!~s\n", [Pat, Type]); message_to_string({improper_list_constr, [TlType]}) -> fmt("~!WCons will produce an improper list" - " since its ~!b2~!!nd~!W argument is~!! ~s\n", [TlType]); + " since its ~!b2~!!nd~!W argument is~!! ~s\n", [TlType]); message_to_string({no_return, [Type|Name]}) -> NameString = case Name of @@ -200,126 +204,126 @@ message_to_string({no_return, [Type|Name]}) -> end; message_to_string({record_constr, [RecConstr, FieldDiffs]}) -> fmt("~!WRecord construction ~!!~s~!W violates the" - " declared type of field ~!!~s\n", [RecConstr, FieldDiffs]); + " declared type of field ~!!~s\n", [RecConstr, FieldDiffs]); message_to_string({record_constr, [Name, Field, Type]}) -> fmt("~!WRecord construction violates the declared type for ~!!#~w{}~!W" - " since ~!!~s~!W cannot be of type ~!!~s\n", - [Name, Field, Type]); + " since ~!!~s~!W cannot be of type ~!!~s\n", + [Name, Field, Type]); message_to_string({record_matching, [String, Name]}) -> fmt("~!WThe ~!!~s~!W violates the" - " declared type for ~!!#~w{}\n", [String, Name]); + " declared type for ~!!#~w{}\n", [String, Name]); message_to_string({record_match, [Pat, Type]}) -> fmt("~!WMatching of ~!!~s~!W tagged with a record name violates the" - " declared type of ~!!~s\n", [Pat, Type]); + " declared type of ~!!~s\n", [Pat, Type]); message_to_string({pattern_match, [Pat, Type]}) -> fmt("~!WThe ~s~!W can never match the type ~!g~s\n", - [bad_pat(Pat), Type]); + [bad_pat(Pat), Type]); message_to_string({pattern_match_cov, [Pat, Type]}) -> fmt("~!WThe ~s~!W can never match since previous" - " clauses completely covered the type ~!g~s\n", - [bad_pat(Pat), Type]); + " clauses completely covered the type ~!g~s\n", + [bad_pat(Pat), Type]); message_to_string({unmatched_return, [Type]}) -> fmt("~!WExpression produces a value of type ~!!~s~!W," - " but this value is unmatched\n", [Type]); + " but this value is unmatched\n", [Type]); message_to_string({unused_fun, [F, A]}) -> fmt("~!WFunction ~!r~w/~w~!W will never be called\n", [F, A]); %%----- Warnings for specs and contracts ------------------- message_to_string({contract_diff, [M, F, _A, Contract, Sig]}) -> fmt("~!WType specification ~!!~w:~w~s~!W" - " is not equal to the success typing: ~!!~w:~w~s\n", - [M, F, Contract, M, F, Sig]); + " is not equal to the success typing: ~!!~w:~w~s\n", + [M, F, Contract, M, F, Sig]); message_to_string({contract_subtype, [M, F, _A, Contract, Sig]}) -> fmt("~!WType specification ~!!~w:~w~s~!W" - " is a subtype of the success typing: ~!!~w:~w~s\n", - [M, F, Contract, M, F, Sig]); + " is a subtype of the success typing: ~!!~w:~w~s\n", + [M, F, Contract, M, F, Sig]); message_to_string({contract_supertype, [M, F, _A, Contract, Sig]}) -> fmt("~!WType specification ~!!~w:~w~s~!W" - " is a supertype of the success typing: ~!!~w:~w~s\n", - [M, F, Contract, M, F, Sig]); + " is a supertype of the success typing: ~!!~w:~w~s\n", + [M, F, Contract, M, F, Sig]); message_to_string({contract_range, [Contract, M, F, ArgStrings, Line, CRet]}) -> fmt("~!WThe contract ~!!~w:~w~s~!W cannot be right because the" - " inferred return for ~!!~w~s~!W on line ~!!~w~!W is ~!!~s\n", - [M, F, Contract, F, ArgStrings, Line, CRet]); + " inferred return for ~!!~w~s~!W on line ~!!~w~!W is ~!!~s\n", + [M, F, Contract, F, ArgStrings, Line, CRet]); message_to_string({invalid_contract, [M, F, A, Sig]}) -> fmt("~!WInvalid type specification for function~!! ~w:~w/~w." - "~!W The success typing is~!! ~s\n", [M, F, A, Sig]); + "~!W The success typing is~!! ~s\n", [M, F, A, Sig]); message_to_string({extra_range, [M, F, A, ExtraRanges, SigRange]}) -> fmt("~!WThe specification for ~!!~w:~w/~w~!W states that the function" - " might also return ~!!~s~!W but the inferred return is ~!!~s\n", - [M, F, A, ExtraRanges, SigRange]); + " might also return ~!!~s~!W but the inferred return is ~!!~s\n", + [M, F, A, ExtraRanges, SigRange]); message_to_string({overlapping_contract, [M, F, A]}) -> fmt("~!WOverloaded contract for ~!!~w:~w/~w~!W has overlapping" - " domains; such contracts are currently unsupported and are simply " - "ignored\n", [M, F, A]); + " domains; such contracts are currently unsupported and are simply " + "ignored\n", [M, F, A]); message_to_string({spec_missing_fun, [M, F, A]}) -> fmt("~!WContract for function that does not exist: ~!!~w:~w/~w\n", - [M, F, A]); + [M, F, A]); %%----- Warnings for opaque type violations ------------------- message_to_string({call_with_opaque, [M, F, Args, ArgNs, ExpArgs]}) -> fmt("~!WThe call ~!!~w:~w~s~!W contains ~!!~s~!W when ~!!~s\n", - [M, F, Args, form_positions(ArgNs), form_expected(ExpArgs)]); + [M, F, Args, form_positions(ArgNs), form_expected(ExpArgs)]); message_to_string({call_without_opaque, [M, F, Args, [{N,_,_}|_] = ExpectedTriples]}) -> fmt("~!WThe call ~!!~w:~w~s ~!Wdoes not have~!! ~s\n", [M, F, bad_arg(N, Args), form_expected_without_opaque(ExpectedTriples)]); message_to_string({opaque_eq, [Type, _Op, OpaqueType]}) -> fmt("~!WAttempt to test for equality between a term of type ~!!~s~!W" - " and a term of opaque type ~!!~s\n", [Type, OpaqueType]); + " and a term of opaque type ~!!~s\n", [Type, OpaqueType]); message_to_string({opaque_guard, [Arg1, Infix, Arg2, ArgNs]}) -> fmt("~!WGuard test ~!!~s ~s ~s~!W contains ~!!~s\n", - [Arg1, Infix, Arg2, form_positions(ArgNs)]); + [Arg1, Infix, Arg2, form_positions(ArgNs)]); message_to_string({opaque_guard, [Guard, Args]}) -> fmt("~!WGuard test ~!!~w~s~!W breaks the opaqueness of its" - " argument\n", [Guard, Args]); + " argument\n", [Guard, Args]); message_to_string({opaque_match, [Pat, OpaqueType, OpaqueTerm]}) -> Term = if OpaqueType =:= OpaqueTerm -> "the term"; true -> OpaqueTerm end, fmt("~!WThe attempt to match a term of type ~!!~s~!W against the" - "~!! ~s~!W breaks the opaqueness of ~!!~s\n", - [OpaqueType, Pat, Term]); + "~!! ~s~!W breaks the opaqueness of ~!!~s\n", + [OpaqueType, Pat, Term]); message_to_string({opaque_neq, [Type, _Op, OpaqueType]}) -> fmt("~!WAttempt to test for inequality between a term of type ~!!~s" - "~!W and a term of opaque type ~!!~s\n", [Type, OpaqueType]); + "~!W and a term of opaque type ~!!~s\n", [Type, OpaqueType]); message_to_string({opaque_type_test, [Fun, Args, Arg, ArgType]}) -> fmt("~!WThe type test ~!!~s~s~!W breaks the opaqueness of the term " - "~!!~s~s\n", [Fun, Args, Arg, ArgType]); + "~!!~s~s\n", [Fun, Args, Arg, ArgType]); message_to_string({opaque_size, [SizeType, Size]}) -> fmt("~!WThe size ~!!~s~!W breaks the opaqueness of ~!!~s\n", - [SizeType, Size]); + [SizeType, Size]); message_to_string({opaque_call, [M, F, Args, Culprit, OpaqueType]}) -> fmt("~!WThe call ~!!~s:~s~s~!W breaks the opaqueness of the term~!!" - " ~s :: ~s\n", [M, F, Args, Culprit, OpaqueType]); + " ~s :: ~s\n", [M, F, Args, Culprit, OpaqueType]); %%----- Warnings for concurrency errors -------------------- message_to_string({race_condition, [M, F, Args, Reason]}) -> fmt("~!WThe call ~!!~w:~w~s ~s\n", [M, F, Args, Reason]); %%----- Warnings for behaviour errors -------------------- message_to_string({callback_type_mismatch, [B, F, A, ST, CT]}) -> fmt("~!WThe inferred return type of~!! ~w/~w (~s) ~!W" - "has nothing in common with~!! ~s, ~!Wwhich is the expected" - " return type for the callback of~!! ~w ~!Wbehaviour\n", - [F, A, ST, CT, B]); + "has nothing in common with~!! ~s, ~!Wwhich is the expected" + " return type for the callback of~!! ~w ~!Wbehaviour\n", + [F, A, ST, CT, B]); message_to_string({callback_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> fmt("~!WThe inferred type for the~!! ~s ~!Wargument of~!!" - " ~w/~w (~s) ~!Wis not a supertype of~!! ~s~!W, which is" - "expected type for this argument in the callback of the~!! ~w " - "~!Wbehaviour\n", - [ordinal(N), F, A, ST, CT, B]); + " ~w/~w (~s) ~!Wis not a supertype of~!! ~s~!W, which is" + "expected type for this argument in the callback of the~!! ~w " + "~!Wbehaviour\n", + [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_spec_type_mismatch, [B, F, A, ST, CT]}) -> fmt("~!WThe return type ~!!~s~!W in the specification of ~!!" - "~w/~w~!W is not a subtype of ~!!~s~!W, which is the expected" - " return type for the callback of ~!!~w~!W behaviour\n", - [ST, F, A, CT, B]); + "~w/~w~!W is not a subtype of ~!!~s~!W, which is the expected" + " return type for the callback of ~!!~w~!W behaviour\n", + [ST, F, A, CT, B]); message_to_string({callback_spec_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> fmt("~!WThe specified type for the ~!!~s~!W argument of ~!!" - "~w/~w (~s)~!W is not a supertype of ~!!~s~!W, which is" - " expected type for this argument in the callback of the ~!!~w" - "~!W behaviour\n", [ordinal(N), F, A, ST, CT, B]); + "~w/~w (~s)~!W is not a supertype of ~!!~s~!W, which is" + " expected type for this argument in the callback of the ~!!~w" + "~!W behaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_missing, [B, F, A]}) -> fmt("~!WUndefined callback function ~!!~w/~w~!W (behaviour ~!!" - "'~w'~!W)\n",[F, A, B]); + "'~w'~!W)\n",[F, A, B]); message_to_string({callback_info_missing, [B]}) -> fmt("~!WCallback info about the ~!r~w~!W" - " behaviour is not available\n", [B]); + " behaviour is not available\n", [B]); %%----- Warnings for unknown functions, types, and behaviours ------------- message_to_string({unknown_type, {M, F, A}}) -> fmt("~!WUnknown type ~!r~w:~w/~w", [M, F, A]); @@ -344,9 +348,9 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, " are ~!!~s\n", [SigArgs]); false -> fmt("~!Wwill never return since it differs in the~!!" - " ~s ~!Wargument from the success typing" - " arguments:~!! ~s\n", - [PositionString, good_arg(ArgNs, SigArgs)]) + " ~s ~!Wargument from the success typing" + " arguments:~!! ~s\n", + [PositionString, good_arg(ArgNs, SigArgs)]) end; only_contract -> case (ArgNs =:= []) orelse IsOverloaded of @@ -355,14 +359,14 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, fmt("~!Wbreaks the contract~!! ~s\n", [good_arg(ArgNs, Contract)]); false -> fmt("~!Wbreaks the contract~!! ~s ~!Win the~!!" - " ~s ~!Wargument\n", + " ~s ~!Wargument\n", [good_arg(ArgNs, Contract), PositionString]) end; both -> fmt("~!Wwill never return since the success typing is " - "~!!~s ~!W->~!! ~s ~!Wand the contract is ~!!~s\n", - [good_arg(ArgNs, SigArgs), SigRet, - good_arg(ArgNs, Contract)]) + "~!!~s ~!W->~!! ~s ~!Wand the contract is ~!!~s\n", + [good_arg(ArgNs, SigArgs), SigRet, + good_arg(ArgNs, Contract)]) end. form_positions(ArgNs) -> @@ -396,12 +400,12 @@ form_expected(ExpectedArgs) -> TS = erl_types:t_to_string(T), case erl_types:t_is_opaque(T) of true -> fmt("~!Wan opaque term of type ~!!~s~!W is" - " expected", [TS]); + " expected", [TS]); false -> fmt("~!Wa structured term of type ~!!~s~!W is" - " expected", [TS]) + " expected", [TS]) end; [_,_|_] -> fmt("~!Wterms of different types are expected in these" - " positions", []) + " positions", []) end. form_position_string(ArgNs) -> @@ -494,4 +498,3 @@ seperate_args(D, [C | R], Arg, Args) -> join_args(Args) -> [$(, string:join(Args, ", "), $)]. - -- cgit v1.1 From 3c917be234a3a994880c871b1d63c37b0a04696a Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Mon, 21 Sep 2015 22:42:44 +0200 Subject: Split out colour printing code in own module --- src/rebar_colour.erl | 101 ++++++++++++++++++++++++++++++++++++++++++ src/rebar_dialyzer_format.erl | 99 ++--------------------------------------- 2 files changed, 104 insertions(+), 96 deletions(-) create mode 100644 src/rebar_colour.erl (limited to 'src') diff --git a/src/rebar_colour.erl b/src/rebar_colour.erl new file mode 100644 index 0000000..bff080d --- /dev/null +++ b/src/rebar_colour.erl @@ -0,0 +1,101 @@ +-module(rebar_colour). + +-export([format/1, format/2]). + +-define(NR, "\033[0;31m"). +-define(NG, "\033[0;32m"). +-define(NY, "\033[0;33m"). +-define(NB, "\033[0;34m"). +-define(NM, "\033[0;35m"). +-define(NC, "\033[0;36m"). +-define(NW, "\033[0;37m"). +-define(BR, "\033[1;31m"). +-define(BG, "\033[1;32m"). +-define(BY, "\033[1;33m"). +-define(BB, "\033[1;34m"). +-define(BM, "\033[1;35m"). +-define(BC, "\033[1;36m"). +-define(BW, "\033[1;37m"). +-define(R, "\033[0m"). + +format(Fmt) -> + format(Fmt, []). +format(Fmt, Args) -> + io_lib:format(cfmt(Fmt), Args). + +%% FROM https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl +%% @doc Query the term enviroment +%% For reasons of simplicity, we don't parse terminal capabilities yet, although +%% a later version could do so. Rather, we provide a simple match-list of terminal +%% capabilities. +%% @end +-spec query_term_env() -> full | dumb. +query_term_env() -> + term_capabilities(os:getenv("TERM")). + +-spec term_capabilities(string()) -> full | dumb. +term_capabilities("xterm") -> full; +term_capabilities("dumb") -> dumb; +term_capabilities(_) -> full. %% Default to the backwards compatible version. + + +cfmt(S) -> + cfmt(S, query_term_env() =:= full). + +cfmt(S, Enabled) -> + lists:flatten(cfmt_(S, ?R, Enabled)). + +cfmt_([$~,$!,_C | S], Last, false) -> + cfmt_(S, Last, false); + +cfmt_([$~,$!,$! | S], _Last, Enabled) -> + [?R | cfmt_(S, ?R, Enabled)]; + +cfmt_([$~,$!,$r | S], _Last, Enabled) -> + [?NR | cfmt_(S, ?NR, Enabled)]; +cfmt_([$~,$!,$R | S], _Last, Enabled) -> + [?BR | cfmt_(S, ?BR, Enabled)]; + +cfmt_([$~,$!,$g | S], _Last, Enabled) -> + [?NG | cfmt_(S, ?NG, Enabled)]; +cfmt_([$~,$!,$G | S], _Last, Enabled) -> + [?BG | cfmt_(S, ?BG, Enabled)]; + +cfmt_([$~,$!,$y | S], _Last, Enabled) -> + [?NY | cfmt_(S, ?NY, Enabled)]; +cfmt_([$~,$!,$Y | S], _Last, Enabled) -> + [?BY | cfmt_(S, ?BY, Enabled)]; + +cfmt_([$~,$!,$b | S], _Last, Enabled) -> + [?NB | cfmt_(S, ?NB, Enabled)]; +cfmt_([$~,$!,$B | S], _Last, Enabled) -> + [?BB | cfmt_(S, ?BB, Enabled)]; + +cfmt_([$~,$!,$m | S], _Last, Enabled) -> + [?NM | cfmt_(S, ?NM, Enabled)]; +cfmt_([$~,$!,$M | S], _Last, Enabled) -> + [?BM | cfmt_(S, ?BM, Enabled)]; + +cfmt_([$~,$!,$c | S], _Last, Enabled) -> + [?NC | cfmt_(S, ?NC, Enabled)]; +cfmt_([$~,$!,$C | S], _Last, Enabled) -> + [?BC | cfmt_(S, ?BC, Enabled)]; + +cfmt_([$~,$!,$w | S], _Last, Enabled) -> + [?NW | cfmt_(S, ?NW, Enabled)]; +cfmt_([$~,$!,$W | S], _Last, Enabled) -> + [?BW | cfmt_(S, ?BW, Enabled)]; + +cfmt_([$~,$~ | S], Last, Enabled) -> + [$~,$~ | cfmt_(S, Last, Enabled)]; + +cfmt_([$~,$s| S], Last, Enabled) -> + [$~,$s, Last | cfmt_(S, Last, Enabled)]; + +cfmt_([C | S], Last, Enabled) -> + [C | cfmt_(S, Last, Enabled)]; + +cfmt_([], _Last, false) -> + ""; +cfmt_([], _Last, _Enabled) -> + ?R. diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index ef8eab1..282f359 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -4,21 +4,7 @@ -export([format/1]). --define(NR, "\033[0;31m"). --define(NG, "\033[0;32m"). --define(NY, "\033[0;33m"). --define(NB, "\033[0;34m"). --define(NM, "\033[0;35m"). --define(NC, "\033[0;36m"). --define(NW, "\033[0;37m"). --define(BR, "\033[1;31m"). --define(BG, "\033[1;32m"). --define(BY, "\033[1;33m"). --define(BB, "\033[1;34m"). --define(BM, "\033[1;35m"). --define(BC, "\033[1;36m"). --define(BW, "\033[1;37m"). --define(R, "\033[0m"). + format(Warning) -> Str = try @@ -39,15 +25,10 @@ format(Warning) -> strip(Warning) -> string:strip(Warning, right, $\n). -%%fmt(Fmt, Args) -> -%% Args2 = [fmt("~s\033[1;37m", [A]) || A <- Args], -%% fmt(Fmt, Args2). - fmt(Fmt) -> - fmt(Fmt, []). + rebar_colour:format(Fmt, []). fmt(Fmt, Args) -> - io_lib:format(cfmt(Fmt), Args). - + rebar_colour:format(Fmt, Args). format_warning({Tag, {File, Line, _MFA}, Msg}, FOpt) -> format_warning({Tag, {File, Line}, Msg}, FOpt); @@ -60,80 +41,6 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), String = lists:flatten(message_to_string(Msg)), lists:flatten(fmt("~s:~w~n~s", [F, Line, String])). - -%% FROM https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl -%% @doc Query the term enviroment -%% For reasons of simplicity, we don't parse terminal capabilities yet, although -%% a later version could do so. Rather, we provide a simple match-list of terminal -%% capabilities. -%% @end --spec query_term_env() -> full | dumb. -query_term_env() -> - term_capabilities(os:getenv("TERM")). - --spec term_capabilities(string()) -> full | dumb. -term_capabilities("xterm") -> full; -term_capabilities("dumb") -> dumb; -term_capabilities(_) -> full. %% Default to the backwards compatible version. - - -cfmt(S) -> - cfmt(S, query_term_env() =:= full). -cfmt(S, true) -> - lists:flatten(cfmt_(S, true)) ++ ?R; -cfmt(S, false) -> - lists:flatten(cfmt_(S, false)). - -cfmt_([$~,$!,_C | S], false) -> - cfmt_(S, false); - -cfmt_([$~,$!,$! | S], Enabled) -> - [?R | cfmt_(S, Enabled)]; - -cfmt_([$~,$!,$r | S], Enabled) -> - [?NR | cfmt_(S, Enabled)]; -cfmt_([$~,$!,$R | S], Enabled) -> - [?BR | cfmt_(S, Enabled)]; - -cfmt_([$~,$!,$g | S], Enabled) -> - [?NG | cfmt_(S, Enabled)]; -cfmt_([$~,$!,$G | S], Enabled) -> - [?BG | cfmt_(S, Enabled)]; - -cfmt_([$~,$!,$y | S], Enabled) -> - [?NY | cfmt_(S, Enabled)]; -cfmt_([$~,$!,$Y | S], Enabled) -> - [?BY | cfmt_(S, Enabled)]; - -cfmt_([$~,$!,$b | S], Enabled) -> - [?NB | cfmt_(S, Enabled)]; -cfmt_([$~,$!,$B | S], Enabled) -> - [?BB | cfmt_(S, Enabled)]; - -cfmt_([$~,$!,$m | S], Enabled) -> - [?NM | cfmt_(S, Enabled)]; -cfmt_([$~,$!,$M | S], Enabled) -> - [?BM | cfmt_(S, Enabled)]; - -cfmt_([$~,$!,$c | S], Enabled) -> - [?NC | cfmt_(S, Enabled)]; -cfmt_([$~,$!,$C | S], Enabled) -> - [?BC | cfmt_(S, Enabled)]; - -cfmt_([$~,$!,$w | S], Enabled) -> - [?NW | cfmt_(S, Enabled)]; -cfmt_([$~,$!,$W | S], Enabled) -> - [?BW | cfmt_(S, Enabled)]; - -cfmt_([$~,$~ | S], Enabled) -> - [$~,$~ | cfmt_(S, Enabled)]; - -cfmt_([C | S], Enabled) -> - [C | cfmt_(S, Enabled)]; - -cfmt_([], _Enabled) -> - []. - %%----------------------------------------------------------------------------- %% Message classification and pretty-printing below. Messages appear in %% categories and in more or less alphabetical ordering within each category. -- cgit v1.1 From a00cc833adc0584b07d795ab8eb92cb16f96d82e Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Tue, 22 Sep 2015 00:57:38 +0200 Subject: Fix bad string caused by missing fmt call --- src/rebar_dialyzer_format.erl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 282f359..9299b1a 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -100,14 +100,14 @@ message_to_string({improper_list_constr, [TlType]}) -> message_to_string({no_return, [Type|Name]}) -> NameString = case Name of - [] -> "~!WThe created fun "; + [] -> fmt("~!WThe created fun "); [F, A] -> fmt("~!WFunction ~!r~w/~w ", [F, A]) end, case Type of no_match -> fmt("~s~!Whas no clauses that will ever match\n",[NameString]); only_explicit -> fmt("~s~!Wonly terminates with explicit exception\n", [NameString]); - only_normal -> fmt("~s~!W~!Whas no local return\n", [NameString]); - both -> fmt("~s~!W~!Whas no local return\n", [NameString]) + only_normal -> fmt("~s~!Whas no local return\n", [NameString]); + both -> fmt("~s~!Whas no local return\n", [NameString]) end; message_to_string({record_constr, [RecConstr, FieldDiffs]}) -> fmt("~!WRecord construction ~!!~s~!W violates the" -- cgit v1.1 From 6557820cc740748ce15c486a06ea6239101e3b28 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Tue, 22 Sep 2015 02:06:20 +0200 Subject: Remove rebar_colour and replace it with cf --- src/rebar_colour.erl | 101 ------------------------------------------ src/rebar_dialyzer_format.erl | 5 +-- 2 files changed, 2 insertions(+), 104 deletions(-) delete mode 100644 src/rebar_colour.erl (limited to 'src') diff --git a/src/rebar_colour.erl b/src/rebar_colour.erl deleted file mode 100644 index bff080d..0000000 --- a/src/rebar_colour.erl +++ /dev/null @@ -1,101 +0,0 @@ --module(rebar_colour). - --export([format/1, format/2]). - --define(NR, "\033[0;31m"). --define(NG, "\033[0;32m"). --define(NY, "\033[0;33m"). --define(NB, "\033[0;34m"). --define(NM, "\033[0;35m"). --define(NC, "\033[0;36m"). --define(NW, "\033[0;37m"). --define(BR, "\033[1;31m"). --define(BG, "\033[1;32m"). --define(BY, "\033[1;33m"). --define(BB, "\033[1;34m"). --define(BM, "\033[1;35m"). --define(BC, "\033[1;36m"). --define(BW, "\033[1;37m"). --define(R, "\033[0m"). - -format(Fmt) -> - format(Fmt, []). -format(Fmt, Args) -> - io_lib:format(cfmt(Fmt), Args). - -%% FROM https://github.com/erlware/erlware_commons/blob/49bc69e35a282bde4a0a6a8f211b5f77d8585256/src/ec_cmd_log.erl -%% @doc Query the term enviroment -%% For reasons of simplicity, we don't parse terminal capabilities yet, although -%% a later version could do so. Rather, we provide a simple match-list of terminal -%% capabilities. -%% @end --spec query_term_env() -> full | dumb. -query_term_env() -> - term_capabilities(os:getenv("TERM")). - --spec term_capabilities(string()) -> full | dumb. -term_capabilities("xterm") -> full; -term_capabilities("dumb") -> dumb; -term_capabilities(_) -> full. %% Default to the backwards compatible version. - - -cfmt(S) -> - cfmt(S, query_term_env() =:= full). - -cfmt(S, Enabled) -> - lists:flatten(cfmt_(S, ?R, Enabled)). - -cfmt_([$~,$!,_C | S], Last, false) -> - cfmt_(S, Last, false); - -cfmt_([$~,$!,$! | S], _Last, Enabled) -> - [?R | cfmt_(S, ?R, Enabled)]; - -cfmt_([$~,$!,$r | S], _Last, Enabled) -> - [?NR | cfmt_(S, ?NR, Enabled)]; -cfmt_([$~,$!,$R | S], _Last, Enabled) -> - [?BR | cfmt_(S, ?BR, Enabled)]; - -cfmt_([$~,$!,$g | S], _Last, Enabled) -> - [?NG | cfmt_(S, ?NG, Enabled)]; -cfmt_([$~,$!,$G | S], _Last, Enabled) -> - [?BG | cfmt_(S, ?BG, Enabled)]; - -cfmt_([$~,$!,$y | S], _Last, Enabled) -> - [?NY | cfmt_(S, ?NY, Enabled)]; -cfmt_([$~,$!,$Y | S], _Last, Enabled) -> - [?BY | cfmt_(S, ?BY, Enabled)]; - -cfmt_([$~,$!,$b | S], _Last, Enabled) -> - [?NB | cfmt_(S, ?NB, Enabled)]; -cfmt_([$~,$!,$B | S], _Last, Enabled) -> - [?BB | cfmt_(S, ?BB, Enabled)]; - -cfmt_([$~,$!,$m | S], _Last, Enabled) -> - [?NM | cfmt_(S, ?NM, Enabled)]; -cfmt_([$~,$!,$M | S], _Last, Enabled) -> - [?BM | cfmt_(S, ?BM, Enabled)]; - -cfmt_([$~,$!,$c | S], _Last, Enabled) -> - [?NC | cfmt_(S, ?NC, Enabled)]; -cfmt_([$~,$!,$C | S], _Last, Enabled) -> - [?BC | cfmt_(S, ?BC, Enabled)]; - -cfmt_([$~,$!,$w | S], _Last, Enabled) -> - [?NW | cfmt_(S, ?NW, Enabled)]; -cfmt_([$~,$!,$W | S], _Last, Enabled) -> - [?BW | cfmt_(S, ?BW, Enabled)]; - -cfmt_([$~,$~ | S], Last, Enabled) -> - [$~,$~ | cfmt_(S, Last, Enabled)]; - -cfmt_([$~,$s| S], Last, Enabled) -> - [$~,$s, Last | cfmt_(S, Last, Enabled)]; - -cfmt_([C | S], Last, Enabled) -> - [C | cfmt_(S, Last, Enabled)]; - -cfmt_([], _Last, false) -> - ""; -cfmt_([], _Last, _Enabled) -> - ?R. diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index 9299b1a..d75c914 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -5,7 +5,6 @@ -export([format/1]). - format(Warning) -> Str = try format_warning(Warning, fullpath) @@ -26,9 +25,9 @@ strip(Warning) -> string:strip(Warning, right, $\n). fmt(Fmt) -> - rebar_colour:format(Fmt, []). + cf:format(Fmt, []). fmt(Fmt, Args) -> - rebar_colour:format(Fmt, Args). + cf:format(Fmt, Args). format_warning({Tag, {File, Line, _MFA}, Msg}, FOpt) -> format_warning({Tag, {File, Line}, Msg}, FOpt); -- cgit v1.1 From ea95e68ab0bfb7344687ea08ca566b185673cd99 Mon Sep 17 00:00:00 2001 From: "Heinz N. Gies" Date: Tue, 22 Sep 2015 17:16:14 +0200 Subject: Use bold instead of bold white for text --- src/rebar_dialyzer_format.erl | 178 +++++++++++++++++++++--------------------- 1 file changed, 89 insertions(+), 89 deletions(-) (limited to 'src') diff --git a/src/rebar_dialyzer_format.erl b/src/rebar_dialyzer_format.erl index d75c914..fbda8d0 100644 --- a/src/rebar_dialyzer_format.erl +++ b/src/rebar_dialyzer_format.erl @@ -48,195 +48,195 @@ format_warning({_Tag, {File, Line}, Msg}, FOpt) when is_list(File), %%----- Warnings for general discrepancies ---------------- message_to_string({apply, [Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> - fmt("~!WFun application with arguments ~!!~s ", + fmt("~!^Fun application with arguments ~!!~s ", [bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({app_call, [M, F, Args, Culprit, ExpectedType, FoundType]}) -> - fmt("~!WThe call~!! ~s:~s~s ~!Wrequires that" - "~!! ~s ~!Wis of type ~!g~s~!W not ~!r~s" + fmt("~!^The call~!! ~s:~s~s ~!^requires that" + "~!! ~s ~!^is of type ~!g~s~!^ not ~!r~s" "~!!\n", [M, F, Args, Culprit, ExpectedType, FoundType]); message_to_string({bin_construction, [Culprit, Size, Seg, Type]}) -> - fmt("~!WBinary construction will fail since the ~!b~s~!W field~!!" - " ~s~!W in segment~!! ~s~!W has type~!! ~s\n", + fmt("~!^Binary construction will fail since the ~!b~s~!^ field~!!" + " ~s~!^ in segment~!! ~s~!^ has type~!! ~s\n", [Culprit, Size, Seg, Type]); message_to_string({call, [M, F, Args, ArgNs, FailReason, SigArgs, SigRet, Contract]}) -> - fmt("~!WThe call~!! ~w:~w~s ", [M, F, bad_arg(ArgNs, Args)]) ++ + fmt("~!^The call~!! ~w:~w~s ", [M, F, bad_arg(ArgNs, Args)]) ++ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, Contract); message_to_string({call_to_missing, [M, F, A]}) -> - fmt("~!WCall to missing or unexported function ~!!~w:~w/~w\n", + fmt("~!^Call to missing or unexported function ~!!~w:~w/~w\n", [M, F, A]); message_to_string({exact_eq, [Type1, Op, Type2]}) -> - fmt("~!WThe test ~!!~s ~s ~s~!W can never evaluate to 'true'\n", + fmt("~!^The test ~!!~s ~s ~s~!^ can never evaluate to 'true'\n", [Type1, Op, Type2]); message_to_string({fun_app_args, [Args, Type]}) -> - fmt("~!WFun application with arguments ~!!~s~!W will fail" + fmt("~!^Fun application with arguments ~!!~s~!^ will fail" " since the function has type ~!!~s\n", [Args, Type]); message_to_string({fun_app_no_fun, [Op, Type, Arity]}) -> - fmt("~!WFun application will fail since ~!!~s ~!W::~!! ~s" + fmt("~!^Fun application will fail since ~!!~s ~!^::~!! ~s" " is not a function of arity ~!!~w\n", [Op, Type, Arity]); message_to_string({guard_fail, []}) -> - "~!WClause guard cannot succeed.\n~!!"; + "~!^Clause guard cannot succeed.\n~!!"; message_to_string({guard_fail, [Arg1, Infix, Arg2]}) -> - fmt("~!WGuard test ~!!~s ~s ~s~!W can never succeed\n", + fmt("~!^Guard test ~!!~s ~s ~s~!^ can never succeed\n", [Arg1, Infix, Arg2]); message_to_string({neg_guard_fail, [Arg1, Infix, Arg2]}) -> - fmt("~!WGuard test not(~!!~s ~s ~s~!W) can never succeed\n", + fmt("~!^Guard test not(~!!~s ~s ~s~!^) can never succeed\n", [Arg1, Infix, Arg2]); message_to_string({guard_fail, [Guard, Args]}) -> - fmt("~!WGuard test ~!!~w~s~!W can never succeed\n", + fmt("~!^Guard test ~!!~w~s~!^ can never succeed\n", [Guard, Args]); message_to_string({neg_guard_fail, [Guard, Args]}) -> - fmt("~!WGuard test not(~!!~w~s~!W) can never succeed\n", + fmt("~!^Guard test not(~!!~w~s~!^) can never succeed\n", [Guard, Args]); message_to_string({guard_fail_pat, [Pat, Type]}) -> - fmt("~!WClause guard cannot succeed. The ~!!~s~!W was matched" + fmt("~!^Clause guard cannot succeed. The ~!!~s~!^ was matched" " against the type ~!!~s\n", [Pat, Type]); message_to_string({improper_list_constr, [TlType]}) -> - fmt("~!WCons will produce an improper list" - " since its ~!b2~!!nd~!W argument is~!! ~s\n", [TlType]); + fmt("~!^Cons will produce an improper list" + " since its ~!b2~!!nd~!^ argument is~!! ~s\n", [TlType]); message_to_string({no_return, [Type|Name]}) -> NameString = case Name of - [] -> fmt("~!WThe created fun "); - [F, A] -> fmt("~!WFunction ~!r~w/~w ", [F, A]) + [] -> fmt("~!^The created fun "); + [F, A] -> fmt("~!^Function ~!r~w/~w ", [F, A]) end, case Type of - no_match -> fmt("~s~!Whas no clauses that will ever match\n",[NameString]); - only_explicit -> fmt("~s~!Wonly terminates with explicit exception\n", [NameString]); - only_normal -> fmt("~s~!Whas no local return\n", [NameString]); - both -> fmt("~s~!Whas no local return\n", [NameString]) + no_match -> fmt("~s~!^has no clauses that will ever match\n",[NameString]); + only_explicit -> fmt("~s~!^only terminates with explicit exception\n", [NameString]); + only_normal -> fmt("~s~!^has no local return\n", [NameString]); + both -> fmt("~s~!^has no local return\n", [NameString]) end; message_to_string({record_constr, [RecConstr, FieldDiffs]}) -> - fmt("~!WRecord construction ~!!~s~!W violates the" + fmt("~!^Record construction ~!!~s~!^ violates the" " declared type of field ~!!~s\n", [RecConstr, FieldDiffs]); message_to_string({record_constr, [Name, Field, Type]}) -> - fmt("~!WRecord construction violates the declared type for ~!!#~w{}~!W" - " since ~!!~s~!W cannot be of type ~!!~s\n", + fmt("~!^Record construction violates the declared type for ~!!#~w{}~!^" + " since ~!!~s~!^ cannot be of type ~!!~s\n", [Name, Field, Type]); message_to_string({record_matching, [String, Name]}) -> - fmt("~!WThe ~!!~s~!W violates the" + fmt("~!^The ~!!~s~!^ violates the" " declared type for ~!!#~w{}\n", [String, Name]); message_to_string({record_match, [Pat, Type]}) -> - fmt("~!WMatching of ~!!~s~!W tagged with a record name violates the" + fmt("~!^Matching of ~!!~s~!^ tagged with a record name violates the" " declared type of ~!!~s\n", [Pat, Type]); message_to_string({pattern_match, [Pat, Type]}) -> - fmt("~!WThe ~s~!W can never match the type ~!g~s\n", + fmt("~!^The ~s~!^ can never match the type ~!g~s\n", [bad_pat(Pat), Type]); message_to_string({pattern_match_cov, [Pat, Type]}) -> - fmt("~!WThe ~s~!W can never match since previous" + fmt("~!^The ~s~!^ can never match since previous" " clauses completely covered the type ~!g~s\n", [bad_pat(Pat), Type]); message_to_string({unmatched_return, [Type]}) -> - fmt("~!WExpression produces a value of type ~!!~s~!W," + fmt("~!^Expression produces a value of type ~!!~s~!^," " but this value is unmatched\n", [Type]); message_to_string({unused_fun, [F, A]}) -> - fmt("~!WFunction ~!r~w/~w~!W will never be called\n", [F, A]); + fmt("~!^Function ~!r~w/~w~!^ will never be called\n", [F, A]); %%----- Warnings for specs and contracts ------------------- message_to_string({contract_diff, [M, F, _A, Contract, Sig]}) -> - fmt("~!WType specification ~!!~w:~w~s~!W" + fmt("~!^Type specification ~!!~w:~w~s~!^" " is not equal to the success typing: ~!!~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_subtype, [M, F, _A, Contract, Sig]}) -> - fmt("~!WType specification ~!!~w:~w~s~!W" + fmt("~!^Type specification ~!!~w:~w~s~!^" " is a subtype of the success typing: ~!!~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_supertype, [M, F, _A, Contract, Sig]}) -> - fmt("~!WType specification ~!!~w:~w~s~!W" + fmt("~!^Type specification ~!!~w:~w~s~!^" " is a supertype of the success typing: ~!!~w:~w~s\n", [M, F, Contract, M, F, Sig]); message_to_string({contract_range, [Contract, M, F, ArgStrings, Line, CRet]}) -> - fmt("~!WThe contract ~!!~w:~w~s~!W cannot be right because the" - " inferred return for ~!!~w~s~!W on line ~!!~w~!W is ~!!~s\n", + fmt("~!^The contract ~!!~w:~w~s~!^ cannot be right because the" + " inferred return for ~!!~w~s~!^ on line ~!!~w~!^ is ~!!~s\n", [M, F, Contract, F, ArgStrings, Line, CRet]); message_to_string({invalid_contract, [M, F, A, Sig]}) -> - fmt("~!WInvalid type specification for function~!! ~w:~w/~w." - "~!W The success typing is~!! ~s\n", [M, F, A, Sig]); + fmt("~!^Invalid type specification for function~!! ~w:~w/~w." + "~!^ The success typing is~!! ~s\n", [M, F, A, Sig]); message_to_string({extra_range, [M, F, A, ExtraRanges, SigRange]}) -> - fmt("~!WThe specification for ~!!~w:~w/~w~!W states that the function" - " might also return ~!!~s~!W but the inferred return is ~!!~s\n", + fmt("~!^The specification for ~!!~w:~w/~w~!^ states that the function" + " might also return ~!!~s~!^ but the inferred return is ~!!~s\n", [M, F, A, ExtraRanges, SigRange]); message_to_string({overlapping_contract, [M, F, A]}) -> - fmt("~!WOverloaded contract for ~!!~w:~w/~w~!W has overlapping" + fmt("~!^Overloaded contract for ~!!~w:~w/~w~!^ has overlapping" " domains; such contracts are currently unsupported and are simply " "ignored\n", [M, F, A]); message_to_string({spec_missing_fun, [M, F, A]}) -> - fmt("~!WContract for function that does not exist: ~!!~w:~w/~w\n", + fmt("~!^Contract for function that does not exist: ~!!~w:~w/~w\n", [M, F, A]); %%----- Warnings for opaque type violations ------------------- message_to_string({call_with_opaque, [M, F, Args, ArgNs, ExpArgs]}) -> - fmt("~!WThe call ~!!~w:~w~s~!W contains ~!!~s~!W when ~!!~s\n", + fmt("~!^The call ~!!~w:~w~s~!^ contains ~!!~s~!^ when ~!!~s\n", [M, F, Args, form_positions(ArgNs), form_expected(ExpArgs)]); message_to_string({call_without_opaque, [M, F, Args, [{N,_,_}|_] = ExpectedTriples]}) -> - fmt("~!WThe call ~!!~w:~w~s ~!Wdoes not have~!! ~s\n", + fmt("~!^The call ~!!~w:~w~s ~!^does not have~!! ~s\n", [M, F, bad_arg(N, Args), form_expected_without_opaque(ExpectedTriples)]); message_to_string({opaque_eq, [Type, _Op, OpaqueType]}) -> - fmt("~!WAttempt to test for equality between a term of type ~!!~s~!W" + fmt("~!^Attempt to test for equality between a term of type ~!!~s~!^" " and a term of opaque type ~!!~s\n", [Type, OpaqueType]); message_to_string({opaque_guard, [Arg1, Infix, Arg2, ArgNs]}) -> - fmt("~!WGuard test ~!!~s ~s ~s~!W contains ~!!~s\n", + fmt("~!^Guard test ~!!~s ~s ~s~!^ contains ~!!~s\n", [Arg1, Infix, Arg2, form_positions(ArgNs)]); message_to_string({opaque_guard, [Guard, Args]}) -> - fmt("~!WGuard test ~!!~w~s~!W breaks the opaqueness of its" + fmt("~!^Guard test ~!!~w~s~!^ breaks the opaqueness of its" " argument\n", [Guard, Args]); message_to_string({opaque_match, [Pat, OpaqueType, OpaqueTerm]}) -> Term = if OpaqueType =:= OpaqueTerm -> "the term"; true -> OpaqueTerm end, - fmt("~!WThe attempt to match a term of type ~!!~s~!W against the" - "~!! ~s~!W breaks the opaqueness of ~!!~s\n", + fmt("~!^The attempt to match a term of type ~!!~s~!^ against the" + "~!! ~s~!^ breaks the opaqueness of ~!!~s\n", [OpaqueType, Pat, Term]); message_to_string({opaque_neq, [Type, _Op, OpaqueType]}) -> - fmt("~!WAttempt to test for inequality between a term of type ~!!~s" - "~!W and a term of opaque type ~!!~s\n", [Type, OpaqueType]); + fmt("~!^Attempt to test for inequality between a term of type ~!!~s" + "~!^ and a term of opaque type ~!!~s\n", [Type, OpaqueType]); message_to_string({opaque_type_test, [Fun, Args, Arg, ArgType]}) -> - fmt("~!WThe type test ~!!~s~s~!W breaks the opaqueness of the term " + fmt("~!^The type test ~!!~s~s~!^ breaks the opaqueness of the term " "~!!~s~s\n", [Fun, Args, Arg, ArgType]); message_to_string({opaque_size, [SizeType, Size]}) -> - fmt("~!WThe size ~!!~s~!W breaks the opaqueness of ~!!~s\n", + fmt("~!^The size ~!!~s~!^ breaks the opaqueness of ~!!~s\n", [SizeType, Size]); message_to_string({opaque_call, [M, F, Args, Culprit, OpaqueType]}) -> - fmt("~!WThe call ~!!~s:~s~s~!W breaks the opaqueness of the term~!!" + fmt("~!^The call ~!!~s:~s~s~!^ breaks the opaqueness of the term~!!" " ~s :: ~s\n", [M, F, Args, Culprit, OpaqueType]); %%----- Warnings for concurrency errors -------------------- message_to_string({race_condition, [M, F, Args, Reason]}) -> - fmt("~!WThe call ~!!~w:~w~s ~s\n", [M, F, Args, Reason]); + fmt("~!^The call ~!!~w:~w~s ~s\n", [M, F, Args, Reason]); %%----- Warnings for behaviour errors -------------------- message_to_string({callback_type_mismatch, [B, F, A, ST, CT]}) -> - fmt("~!WThe inferred return type of~!! ~w/~w (~s) ~!W" - "has nothing in common with~!! ~s, ~!Wwhich is the expected" - " return type for the callback of~!! ~w ~!Wbehaviour\n", + fmt("~!^The inferred return type of~!! ~w/~w (~s) ~!^" + "has nothing in common with~!! ~s, ~!^which is the expected" + " return type for the callback of~!! ~w ~!^behaviour\n", [F, A, ST, CT, B]); message_to_string({callback_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> - fmt("~!WThe inferred type for the~!! ~s ~!Wargument of~!!" - " ~w/~w (~s) ~!Wis not a supertype of~!! ~s~!W, which is" + fmt("~!^The inferred type for the~!! ~s ~!^argument of~!!" + " ~w/~w (~s) ~!^is not a supertype of~!! ~s~!^, which is" "expected type for this argument in the callback of the~!! ~w " - "~!Wbehaviour\n", + "~!^behaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_spec_type_mismatch, [B, F, A, ST, CT]}) -> - fmt("~!WThe return type ~!!~s~!W in the specification of ~!!" - "~w/~w~!W is not a subtype of ~!!~s~!W, which is the expected" - " return type for the callback of ~!!~w~!W behaviour\n", + fmt("~!^The return type ~!!~s~!^ in the specification of ~!!" + "~w/~w~!^ is not a subtype of ~!!~s~!^, which is the expected" + " return type for the callback of ~!!~w~!^ behaviour\n", [ST, F, A, CT, B]); message_to_string({callback_spec_arg_type_mismatch, [B, F, A, N, ST, CT]}) -> - fmt("~!WThe specified type for the ~!!~s~!W argument of ~!!" - "~w/~w (~s)~!W is not a supertype of ~!!~s~!W, which is" + fmt("~!^The specified type for the ~!!~s~!^ argument of ~!!" + "~w/~w (~s)~!^ is not a supertype of ~!!~s~!^, which is" " expected type for this argument in the callback of the ~!!~w" - "~!W behaviour\n", [ordinal(N), F, A, ST, CT, B]); + "~!^ behaviour\n", [ordinal(N), F, A, ST, CT, B]); message_to_string({callback_missing, [B, F, A]}) -> - fmt("~!WUndefined callback function ~!!~w/~w~!W (behaviour ~!!" - "'~w'~!W)\n",[F, A, B]); + fmt("~!^Undefined callback function ~!!~w/~w~!^ (behaviour ~!!" + "'~w'~!^)\n",[F, A, B]); message_to_string({callback_info_missing, [B]}) -> - fmt("~!WCallback info about the ~!r~w~!W" + fmt("~!^Callback info about the ~!r~w~!^" " behaviour is not available\n", [B]); %%----- Warnings for unknown functions, types, and behaviours ------------- message_to_string({unknown_type, {M, F, A}}) -> - fmt("~!WUnknown type ~!r~w:~w/~w", [M, F, A]); + fmt("~!^Unknown type ~!r~w:~w/~w", [M, F, A]); message_to_string({unknown_function, {M, F, A}}) -> - fmt("~!WUnknown function ~!r~w:~w/~w", [M, F, A]); + fmt("~!^Unknown function ~!r~w:~w/~w", [M, F, A]); message_to_string({unknown_behaviour, B}) -> - fmt("~!WUnknown behaviour ~!r~w", [B]). + fmt("~!^Unknown behaviour ~!r~w", [B]). %%----------------------------------------------------------------------------- %% Auxiliary functions below @@ -250,11 +250,11 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, case ArgNs =:= [] of true -> %% We do not know which argument(s) caused the failure - fmt("~!Wwill never return since the success typing arguments" + fmt("~!^will never return since the success typing arguments" " are ~!!~s\n", [SigArgs]); false -> - fmt("~!Wwill never return since it differs in the~!!" - " ~s ~!Wargument from the success typing" + fmt("~!^will never return since it differs in the~!!" + " ~s ~!^argument from the success typing" " arguments:~!! ~s\n", [PositionString, good_arg(ArgNs, SigArgs)]) end; @@ -262,15 +262,15 @@ call_or_apply_to_string(ArgNs, FailReason, SigArgs, SigRet, case (ArgNs =:= []) orelse IsOverloaded of true -> %% We do not know which arguments caused the failure - fmt("~!Wbreaks the contract~!! ~s\n", [good_arg(ArgNs, Contract)]); + fmt("~!^breaks the contract~!! ~s\n", [good_arg(ArgNs, Contract)]); false -> - fmt("~!Wbreaks the contract~!! ~s ~!Win the~!!" - " ~s ~!Wargument\n", + fmt("~!^breaks the contract~!! ~s ~!^in the~!!" + " ~s ~!^argument\n", [good_arg(ArgNs, Contract), PositionString]) end; both -> - fmt("~!Wwill never return since the success typing is " - "~!!~s ~!W->~!! ~s ~!Wand the contract is ~!!~s\n", + fmt("~!^will never return since the success typing is " + "~!!~s ~!^->~!! ~s ~!^and the contract is ~!!~s\n", [good_arg(ArgNs, SigArgs), SigRet, good_arg(ArgNs, Contract)]) end. @@ -290,10 +290,10 @@ form_positions(ArgNs) -> form_expected_without_opaque([{N, T, TStr}]) -> FStr = case erl_types:t_is_opaque(T) of true -> - "~!Wan opaque term of type~!g ~s ~!Was "; + "~!^an opaque term of type~!g ~s ~!^as "; false -> - "~!Wa term of type ~!g~s ~!W(with opaque subterms) as " - end ++ form_position_string([N]) ++ "~!W argument", + "~!^a term of type ~!g~s ~!^(with opaque subterms) as " + end ++ form_position_string([N]) ++ "~!^ argument", fmt(FStr, [TStr]); form_expected_without_opaque(ExpectedTriples) -> %% TODO: can do much better here @@ -305,12 +305,12 @@ form_expected(ExpectedArgs) -> [T] -> TS = erl_types:t_to_string(T), case erl_types:t_is_opaque(T) of - true -> fmt("~!Wan opaque term of type ~!!~s~!W is" + true -> fmt("~!^an opaque term of type ~!!~s~!^ is" " expected", [TS]); - false -> fmt("~!Wa structured term of type ~!!~s~!W is" + false -> fmt("~!^a structured term of type ~!!~s~!^ is" " expected", [TS]) end; - [_,_|_] -> fmt("~!Wterms of different types are expected in these" + [_,_|_] -> fmt("~!^terms of different types are expected in these" " positions", []) end. -- cgit v1.1