Skip to content

Commit bb43d07

Browse files
committed
Unify warnings under ExDoc.Utils.warn/1
1 parent 050916a commit bb43d07

File tree

9 files changed

+23
-19
lines changed

9 files changed

+23
-19
lines changed

lib/ex_doc/autolink.ex

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,12 @@ defmodule ExDoc.Autolink do
131131
end
132132

133133
defp warn(message, {file, line}, id) do
134-
warning = IO.ANSI.format([:yellow, "warning: ", :reset])
135-
136134
stacktrace =
137135
" #{file}" <>
138136
if(line, do: ":#{line}", else: "") <>
139137
if(id, do: ": #{id}", else: "")
140138

141-
IO.puts(:stderr, [warning, message, ?\n, stacktrace, ?\n])
139+
ExDoc.Utils.warning([message, ?\n, stacktrace, ?\n])
142140
end
143141

144142
defp warn(ref, file_line, id, visibility, metadata)

lib/ex_doc/formatter/epub.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ defmodule ExDoc.Formatter.EPUB do
7575
html = Templates.extra_template(config, title, title_content, content)
7676

7777
if File.regular?(output) do
78-
IO.puts(:stderr, "warning: file #{Path.relative_to_cwd(output)} already exists")
78+
ExDoc.Utils.warning("file #{Path.relative_to_cwd(output)} already exists")
7979
end
8080

8181
File.write!(output, html)

lib/ex_doc/formatter/html.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ defmodule ExDoc.Formatter.HTML do
161161
:ok
162162

163163
true ->
164-
IO.warn(
164+
ExDoc.Utils.warning(
165165
"ExDoc is outputting to an existing directory. " <>
166166
"Beware documentation output may be mixed with other entries"
167167
)
@@ -263,7 +263,7 @@ defmodule ExDoc.Formatter.HTML do
263263
html = Templates.extra_template(config, node, extra_type(extension), nodes_map, refs)
264264

265265
if File.regular?(output) do
266-
IO.puts(:stderr, "warning: file #{Path.relative_to_cwd(output)} already exists")
266+
ExDoc.Utils.warning("file #{Path.relative_to_cwd(output)} already exists")
267267
end
268268

269269
File.write!(output, html)
@@ -556,7 +556,7 @@ defmodule ExDoc.Formatter.HTML do
556556

557557
defp generate_redirect(filename, config, redirect_to) do
558558
unless case_sensitive_file_regular?("#{config.output}/#{redirect_to}") do
559-
IO.puts(:stderr, "warning: #{filename} redirects to #{redirect_to}, which does not exist")
559+
ExDoc.Utils.warning("#{filename} redirects to #{redirect_to}, which does not exist")
560560
end
561561

562562
content = Templates.redirect_template(config, redirect_to)

lib/ex_doc/language.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,7 @@ defmodule ExDoc.Language do
142142
def get(:erlang, _module), do: {:ok, ExDoc.Language.Erlang}
143143

144144
def get(language, module) when is_atom(language) and is_atom(module) do
145-
ExDoc.WarningCounter.increment()
146-
147-
IO.warn(
148-
"skipping module #{module}, reason: unsupported language (#{language})",
149-
[]
150-
)
145+
ExDoc.Utils.warning("skipping module #{module}, reason: unsupported language (#{language})")
151146

152147
:error
153148
end

lib/ex_doc/language/elixir.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ defmodule ExDoc.Language.Elixir do
4040
}
4141

4242
true ->
43-
IO.warn("skipping docs for module #{inspect(module)}, reason: :no_debug_info", [])
43+
ExDoc.Utils.warning("skipping docs for module #{inspect(module)}, reason: :no_debug_info")
4444
end
4545
end
4646

lib/ex_doc/language/erlang.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ defmodule ExDoc.Language.Erlang do
3131
}
3232
}
3333
else
34-
IO.warn("skipping docs for module #{inspect(module)}, reason: :no_debug_info", [])
34+
ExDoc.Utils.warning("skipping docs for module #{inspect(module)}, reason: :no_debug_info")
3535
end
3636
end
3737

lib/ex_doc/markdown/earmark.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ defmodule ExDoc.Markdown.Earmark do
4848
defp print_messages(messages, options) do
4949
for {severity, line, message} <- messages do
5050
file = options[:file]
51-
ExDoc.WarningCounter.increment()
52-
IO.warn("#{inspect(__MODULE__)} (#{severity}) #{file}:#{line} #{message}", [])
51+
ExDoc.Utils.warning("#{inspect(__MODULE__)} (#{severity}) #{file}:#{line} #{message}")
5352
end
5453
end
5554

lib/ex_doc/retriever.ex

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ defmodule ExDoc.Retriever do
7575
docs
7676

7777
{:error, reason} ->
78-
ExDoc.WarningCounter.increment()
79-
IO.warn("skipping docs for module #{inspect(module)}, reason: #{reason}", [])
78+
ExDoc.Utils.warning("skipping docs for module #{inspect(module)}, reason: #{reason}")
8079

8180
false
8281
end

lib/ex_doc/utils.ex

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,4 +147,17 @@ defmodule ExDoc.Utils do
147147
nil
148148
end
149149
end
150+
151+
@doc """
152+
Prints `message` as a warning in :stderr.
153+
154+
It automatically increases the counter in `ExDoc.WarningCounter`.
155+
"""
156+
def warning(message) do
157+
ExDoc.WarningCounter.increment()
158+
159+
prefix = IO.ANSI.format([:yellow, "warning: ", :reset])
160+
161+
IO.puts(:stderr, [prefix, message])
162+
end
150163
end

0 commit comments

Comments
 (0)