Skip to content

Commit 8470c85

Browse files
committed
Minor improvements
1 parent d5351b8 commit 8470c85

File tree

8 files changed

+39
-28
lines changed

8 files changed

+39
-28
lines changed

lib/ex_doc/cli.ex

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -192,13 +192,13 @@ defmodule ExDoc.CLI do
192192
--package Hex package name
193193
--paths Prepends the given path to Erlang code path. The path might contain a glob
194194
pattern but in that case, remember to quote it: --paths "_build/dev/lib/*/ebin".
195-
This option can be given multiple times
196-
--proglang The project's programming language, default: "elixir"
197-
-q, --quiet Only output warnings and errors
198-
--source-ref Branch/commit/tag used for source link inference, default: "master"
199-
-u, --source-url URL to the source code
200-
-v, --version Print ExDoc version
201-
--warnings-as-errors Exit with non-zero status if doc generation has one or more warnings.
195+
This option can be given multiple times.
196+
--proglang The project's programming language, default: "elixir".
197+
-q, --quiet Only output warnings and errors.
198+
--source-ref Branch/commit/tag used for source link inference, default: "master".
199+
-u, --source-url URL to the source code.
200+
-v, --version Print ExDoc version.
201+
--warnings-as-errors Exit with non-zero status if doc generation produces warnings.
202202
203203
## Custom config
204204

lib/ex_doc/formatter/epub.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ defmodule ExDoc.Formatter.EPUB do
66
alias ExDoc.Formatter.HTML
77

88
@doc """
9-
Generate EPUB documentation for the given modules.
9+
Generates EPUB documentation for the given modules.
1010
"""
1111
@spec run([ExDoc.ModuleNode.t()], [ExDoc.ModuleNode.t()], ExDoc.Config.t()) :: String.t()
1212
def run(project_nodes, filtered_modules, config) when is_map(config) do
13+
ExDoc.Utils.unset_warned()
14+
1315
config = normalize_config(config)
1416
File.rm_rf!(config.output)
1517
File.mkdir_p!(Path.join(config.output, "OEBPS"))

lib/ex_doc/formatter/html.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ defmodule ExDoc.Formatter.HTML do
88
@assets_dir "assets"
99

1010
@doc """
11-
Generate HTML documentation for the given modules.
11+
Generates HTML documentation for the given modules.
1212
"""
1313
@spec run([ExDoc.ModuleNode.t()], [ExDoc.ModuleNode.t()], ExDoc.Config.t()) :: String.t()
1414
def run(project_nodes, filtered_modules, config) when is_map(config) do
15+
ExDoc.Utils.unset_warned()
16+
1517
config = normalize_config(config)
1618
config = %{config | output: Path.expand(config.output)}
1719

lib/ex_doc/utils.ex

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defmodule ExDoc.Utils do
77
Emits a warning.
88
"""
99
def warn(message, stacktrace_info) do
10-
put_warned()
10+
set_warned()
1111

1212
# TODO: remove check when we require Elixir v1.14
1313
if @elixir_gte_1_14? do
@@ -17,22 +17,29 @@ defmodule ExDoc.Utils do
1717
end
1818
end
1919

20-
@doc false
21-
def put_warned() do
20+
@doc """
21+
Stores that a warning has been generated.
22+
"""
23+
def set_warned() do
2224
unless warned?() do
2325
:persistent_term.put({__MODULE__, :warned?}, true)
2426
end
2527

2628
true
2729
end
2830

29-
@doc false
30-
def delete_warned() do
31+
@doc """
32+
Removes that a warning has been generated.
33+
"""
34+
def unset_warned() do
3135
if warned?() do
3236
:persistent_term.put({__MODULE__, :warned?}, false)
3337
end
3438
end
3539

40+
@doc """
41+
Returns `true` if any warning has been generated during the document building. Otherwise returns `false`.
42+
"""
3643
def warned?() do
3744
:persistent_term.get({__MODULE__, :warned?}, false)
3845
end

test/ex_doc/cli_test.exs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ defmodule ExDoc.CLITest do
7272
@describetag :warnings
7373

7474
test "exits with code 0 when no warnings" do
75-
ExDoc.Utils.delete_warned()
75+
ExDoc.Utils.unset_warned()
7676

7777
{[html, epub], _io} = run(["ExDoc", "1.2.3", @ebin, "--warnings-as-errors"])
7878

@@ -98,7 +98,7 @@ defmodule ExDoc.CLITest do
9898
end
9999

100100
test "exits with 1 when there is a warning" do
101-
ExDoc.Utils.put_warned()
101+
ExDoc.Utils.set_warned()
102102

103103
fun = fn ->
104104
run(["ExDoc", "1.2.3", @ebin, "--warnings-as-errors"])
@@ -114,9 +114,9 @@ defmodule ExDoc.CLITest do
114114
end
115115

116116
test "exits with 1 when there are multiple warnings" do
117-
ExDoc.Utils.put_warned()
118-
ExDoc.Utils.put_warned()
119-
ExDoc.Utils.put_warned()
117+
ExDoc.Utils.set_warned()
118+
ExDoc.Utils.set_warned()
119+
ExDoc.Utils.set_warned()
120120

121121
fun = fn ->
122122
run(["ExDoc", "1.2.3", @ebin, "--warnings-as-errors"])

test/ex_doc/formatter/epub_test.exs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ defmodule ExDoc.Formatter.EPUBTest do
255255
@describetag :warnings
256256

257257
test "multiple warnings are registered when using warnings_as_errors: true", context do
258-
ExDoc.Utils.delete_warned()
258+
ExDoc.Utils.unset_warned()
259259

260260
output =
261261
capture_io(:stderr, fn ->
@@ -279,7 +279,7 @@ defmodule ExDoc.Formatter.EPUBTest do
279279
end
280280

281281
test "warnings are registered even with warnings_as_errors: false", context do
282-
ExDoc.Utils.delete_warned()
282+
ExDoc.Utils.unset_warned()
283283

284284
capture_io(:stderr, fn ->
285285
generate_docs(

test/ex_doc/formatter/html_test.exs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ defmodule ExDoc.Formatter.HTMLTest do
152152
@describetag :warnings
153153

154154
test "single warning is registered when using warnings_as_errors: true", context do
155-
ExDoc.Utils.delete_warned()
155+
ExDoc.Utils.unset_warned()
156156

157157
output =
158158
capture_io(:stderr, fn ->
@@ -166,7 +166,7 @@ defmodule ExDoc.Formatter.HTMLTest do
166166
end
167167

168168
test "multiple warnings are registered when using warnings_as_errors: true", context do
169-
ExDoc.Utils.delete_warned()
169+
ExDoc.Utils.unset_warned()
170170

171171
output =
172172
capture_io(:stderr, fn ->
@@ -190,7 +190,7 @@ defmodule ExDoc.Formatter.HTMLTest do
190190
end
191191

192192
test "warnings are registered even with warnings_as_errors: false", context do
193-
ExDoc.Utils.delete_warned()
193+
ExDoc.Utils.unset_warned()
194194

195195
capture_io(:stderr, fn ->
196196
generate_docs(

test/mix/tasks/docs_test.exs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,16 +417,16 @@ defmodule Mix.Tasks.DocsTest do
417417
end
418418

419419
test "exits with 1 due to warning, with flag --warnings_as_errors", context do
420-
ExDoc.Utils.put_warned()
420+
ExDoc.Utils.set_warned()
421421

422422
assert catch_exit(run(context, [], app: :ex_doc, docs: [warnings_as_errors: true])) ==
423423
{:shutdown, 1}
424424
end
425425

426426
test "exits with 1 due to multiple warnings, with flag --warnings_as_errors", context do
427-
ExDoc.Utils.put_warned()
428-
ExDoc.Utils.put_warned()
429-
ExDoc.Utils.put_warned()
427+
ExDoc.Utils.set_warned()
428+
ExDoc.Utils.set_warned()
429+
ExDoc.Utils.set_warned()
430430

431431
assert catch_exit(run(context, [], app: :ex_doc, docs: [warnings_as_errors: true])) ==
432432
{:shutdown, 1}

0 commit comments

Comments
 (0)