Skip to content

Commit

Permalink
Add deprecated to docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagoefmoraes committed Feb 28, 2024
1 parent 57f5a47 commit a58ec1d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/nimble_options/docs.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ defmodule NimbleOptions.Docs do

description =
get_required_str(schema)
|> get_deprecated_str(schema)
|> get_doc_str(schema)
|> get_default_str(schema)
|> case do
Expand Down Expand Up @@ -76,6 +77,13 @@ defmodule NimbleOptions.Docs do
if schema[:required], do: "Required."
end

defp get_deprecated_str(prev_str, schema) do
space_concat(
prev_str,
schema[:deprecated] && "This option is deprecated. #{String.trim(schema[:deprecated])}"
)
end

defp get_doc_str(prev_str, schema) do
space_concat(prev_str, schema[:doc] && String.trim(schema[:doc]))
end
Expand Down
16 changes: 16 additions & 0 deletions test/nimble_options/docs_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,22 @@ defmodule NimbleOptions.DocsTest do
assert NimbleOptions.docs(schema) == docs
end

test "generates deprecated information" do
schema = [
old: [type: :atom, doc: "Old option.", deprecated: "Use `:new` instead."],
new: [type: :string, doc: "New option."]
]

docs = """
* `:old` (`t:atom/0`) - This option is deprecated. Use `:new` instead. Old option.
* `:new` (`t:String.t/0`) - New option.
"""

assert NimbleOptions.docs(schema) == docs
end

test "the option doesn't appear in the documentation when the :doc option is false" do
schema = [
name: [type: :atom, doc: "An atom."],
Expand Down

0 comments on commit a58ec1d

Please # to comment.