-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
dialyxir.ex
84 lines (65 loc) · 2.04 KB
/
dialyxir.ex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
defmodule Dialyxir.Formatter.Dialyxir do
@moduledoc false
alias Dialyxir.Formatter.Utils
@behaviour Dialyxir.Formatter
@impl Dialyxir.Formatter
def format(dialyzer_warning = {_tag, {file, location}, message}) do
{warning_name, arguments} = message
base_name = Path.relative_to_cwd(file)
formatted =
try do
warning = Utils.warning(warning_name)
string = warning.format_long(arguments)
"""
#{base_name}:#{Utils.format_location(location)}:#{warning_name}
#{string}
"""
rescue
e ->
message = """
Unknown error occurred: #{inspect(e)}
"""
wrap_error_message(message, dialyzer_warning)
catch
{:error, :unknown_warning, warning_name} ->
message = """
Unknown warning:
#{inspect(warning_name)}
"""
wrap_error_message(message, dialyzer_warning)
{:error, :lexing, warning} ->
message = """
Failed to lex warning:
#{inspect(warning)}
"""
wrap_error_message(message, dialyzer_warning)
{:error, :parsing, failing_string} ->
message = """
Failed to parse warning:
#{inspect(failing_string)}
"""
wrap_error_message(message, dialyzer_warning)
{:error, :pretty_printing, failing_string} ->
message = """
Failed to pretty print warning:
#{inspect(failing_string)}
"""
wrap_error_message(message, dialyzer_warning)
{:error, :formatting, code} ->
message = """
Failed to format warning:
#{inspect(code)}
"""
wrap_error_message(message, dialyzer_warning)
end
formatted <> String.duplicate("_", 80)
end
defp wrap_error_message(message, warning) do
"""
Please file a bug in https://github.com/jeremyjh/dialyxir/issues with this message.
#{message}
Legacy warning:
#{Dialyxir.Formatter.Dialyzer.format(warning)}
"""
end
end