From a58ec1da6a498c50f4a6fb4b019bb987d8cb4b60 Mon Sep 17 00:00:00 2001 From: Tiago Moraes Date: Wed, 28 Feb 2024 18:36:51 -0300 Subject: [PATCH] Add deprecated to docs --- lib/nimble_options/docs.ex | 8 ++++++++ test/nimble_options/docs_test.exs | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/lib/nimble_options/docs.ex b/lib/nimble_options/docs.ex index e3be50a..246c420 100644 --- a/lib/nimble_options/docs.ex +++ b/lib/nimble_options/docs.ex @@ -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 @@ -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 diff --git a/test/nimble_options/docs_test.exs b/test/nimble_options/docs_test.exs index 013869a..1d6f260 100644 --- a/test/nimble_options/docs_test.exs +++ b/test/nimble_options/docs_test.exs @@ -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."],