nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: dashbitco/nimble_options
Pull request #81 (2022-05-09 08:53:03)

Add the :reference option type
I think once we support `:pid`, it makes sense to support `:reference` too. I have an actual use case too, for some internal option validation in Xandra :smile:


Patch:
diff --git a/lib/nimble_options.ex b/lib/nimble_options.ex
index a3cd584..0de7277 100644
--- a/lib/nimble_options.ex
+++ b/lib/nimble_options.ex
@@ -100,6 +100,8 @@ defmodule NimbleOptions do
 
     * `:pid` - A PID (process identifier).
 
+    * `:reference` - A reference (see `t:reference/0`).
+
     * `:mfa` - A named function in the format `{module, function, arity}` where
       `arity` is a list of arguments. For example, `{MyModule, :my_fun, [arg1, arg2]}`.
 
@@ -253,7 +255,8 @@ defmodule NimbleOptions do
     :string,
     :boolean,
     :timeout,
-    :pid
+    :pid,
+    :reference
   ]
 
   @typedoc """
@@ -554,6 +557,14 @@ defmodule NimbleOptions do
     error_tuple(key, value, "expected #{inspect(key)} to be a pid, got: #{inspect(value)}")
   end
 
+  defp validate_type(:reference, _key, value) when is_reference(value) do
+    {:ok, value}
+  end
+
+  defp validate_type(:reference, key, value) do
+    error_tuple(key, value, "expected #{inspect(key)} to be a reference, got: #{inspect(value)}")
+  end
+
   defp validate_type(:mfa, _key, {mod, fun, args} = value)
        when is_atom(mod) and is_atom(fun) and is_list(args) do
     {:ok, value}


Test patch:
diff --git a/test/nimble_options_test.exs b/test/nimble_options_test.exs
index f4d4d00..d190713 100644
--- a/test/nimble_options_test.exs
+++ b/test/nimble_options_test.exs
@@ -41,7 +41,7 @@ defmodule NimbleOptionsTest do
 
       Available types: :any, :keyword_list, :non_empty_keyword_list, :atom, \
       :integer, :non_neg_integer, :pos_integer, :float, :mfa, :mod_arg, :string, :boolean, :timeout, \
-      :pid, {:fun, arity}, {:in, choices}, {:or, subtypes}, {:custom, mod, fun, args}, \
+      :pid, :reference, {:fun, arity}, {:in, choices}, {:or, subtypes}, {:custom, mod, fun, args}, \
       {:list, subtype}, {:tuple, list_of_subtypes} \
       (in options [:stages])\
       """
@@ -437,6 +437,24 @@ defmodule NimbleOptionsTest do
                 }}
     end
 
+    test "valid reference" do
+      schema = [name: [type: :reference]]
+      opts = [name: make_ref()]
+      assert NimbleOptions.validate(opts, schema) == {:ok, opts}
+    end
+
+    test "invalid reference" do
+      schema = [name: [type: :reference]]
+
+      assert NimbleOptions.validate([name: 1], schema) ==
+               {:error,
+                %ValidationError{
+                  key: :name,
+                  value: 1,
+                  message: "expected :name to be a reference, got: 1"
+                }}
+    end
+
     test "valid mfa" do
       schema = [transformer: [type: :mfa]]
Repository: dashbitco/nimble_options
Pull request #94 (2022-10-02 16:21:09)

Support `tuple` type in typedoc generation
If an option of type `tuple` was defined a FunctionClauseError was raised because `NimbleOptions.Docs.get_raw_type_str` did not pattern match.


Patch:
diff --git a/lib/nimble_options/docs.ex b/lib/nimble_options/docs.ex
index 0606c21..d1f4070 100644
--- a/lib/nimble_options/docs.ex
+++ b/lib/nimble_options/docs.ex
@@ -138,6 +138,15 @@ defmodule NimbleOptions.Docs do
     end
   end
 
+  defp get_raw_type_str({:tuple, value_types}) do
+    value_types =
+      value_types
+      |> Enum.map(&get_raw_type_str/1)
+      |> Enum.join(", ")
+
+    "tuple of #{value_types} values"
+  end
+
   defp indent_doc(text, indent) do
     [head | tail] = String.split(text, ["\r\n", "\n"])
 


Test patch:
diff --git a/test/nimble_options_test.exs b/test/nimble_options_test.exs
index e616631..a7aef91 100644
--- a/test/nimble_options_test.exs
+++ b/test/nimble_options_test.exs
@@ -1931,7 +1931,8 @@ defmodule NimbleOptionsTest do
         nested_list_of_ints: [type: {:list, {:list, :integer}}],
         list_of_kws: [type: {:list, {:keyword_list, []}}],
         map: [type: :map],
-        map_of_strings: [type: {:map, :string, :string}]
+        map_of_strings: [type: {:map, :string, :string}],
+        tuple: [type: {:tuple, [:integer, :atom, {:list, :string}]}]
       ]
 
       assert NimbleOptions.docs(schema) == """
@@ -1961,6 +1962,8 @@ defmodule NimbleOptionsTest do
 
              * `:map_of_strings` (map of `t:String.t/0` keys and `t:String.t/0` values)
 
+             * `:tuple` (tuple of `t:integer/0`, `t:atom/0`, list of `t:String.t/0` values)
+
              """
     end
   end
Repository: dashbitco/nimble_options
Pull request #125 (2024-02-28 21:51:05)

Add deprecated to docs
Adds deprecated information to docs.

Example from [Finch docs](https://hexdocs.pm/finch/Finch.html#start_link/1-pool-configuration-options)
| Before         |  After         |
:---------------:|:---------------:
![](https://github.com/dashbitco/nimble_options/assets/1627293/c37cfa7c-55c4-4cbf-af5a-007e33e77ade) | ![](https://github.com/dashbitco/nimble_options/assets/1627293/96769160-c061-43c0-9f13-c8ac9b5a75c2)


coveralls: ## Pull Request Test Coverage Report for [Build a58ec1da6a498c50f4a6fb4b019bb987d8cb4b60-PR-125](https://coveralls.io/builds/65992842)


### Details

* **2** of **2**   **(100.0%)**  changed or added relevant lines in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage increased (+**0.05%**) to **93.0%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/65992842/badge)](https://coveralls.io/builds/65992842) |
| :-- | --: |
| Change from base [Build 57f5a479e7d96b8926704481c907b94196431a8a](https://coveralls.io/builds/65382720): |  0.05% |
| Covered Lines: | 279 |
| Relevant Lines: | 300 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/lib/nimble_options/docs.ex b/lib/nimble_options/docs.ex
index e3be50a..7febe50 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


Test patch:
diff --git a/test/nimble_options/docs_test.exs b/test/nimble_options/docs_test.exs
index 013869a..6747aae 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."],
Repository: dashbitco/nimble_options
Pull request #130 (2024-08-01 09:54:29)

Allow map options in validate/2 when schema is a list
If I have the following:

```elixir
NimbleOptions.validate(opts, NimbleOptions.new!(schema))
```

Everything works fine, but if I do:

```elixir
NimbleOptions.validate(opts, schema)
```

It doesn't work 😢

josevalim: Can you please add a test as well? Thank you!
cheerfulstoic: Right, of course!  Done!

I temporarily put in a `if(is_map(options), do: IO.inspect(options))` in `validate/2` to confirm that none of the tests were receiving a map as the first argument.  I thought to make all of the tests use `opts_to_type` to exercise both the list and map versions of options, but I just went for a sanity test here assuming for now that if you pass in a map it will work everywhere the same as a list 🤷 

Patch:
diff --git a/lib/nimble_options.ex b/lib/nimble_options.ex
index c609ded..f4f94ae 100644
--- a/lib/nimble_options.ex
+++ b/lib/nimble_options.ex
@@ -342,7 +342,7 @@ defmodule NimbleOptions do
     validate_options_with_schema(options, schema)
   end
 
-  def validate(options, schema) when is_list(options) and is_list(schema) do
+  def validate(options, schema) when (is_list(options) or is_map(options)) and is_list(schema) do
     validate(options, new!(schema))
   end
 


Test patch:
diff --git a/test/nimble_options_test.exs b/test/nimble_options_test.exs
index 18379df..aaedb0c 100644
--- a/test/nimble_options_test.exs
+++ b/test/nimble_options_test.exs
@@ -1735,6 +1735,32 @@ defmodule NimbleOptionsTest do
     end
   end
 
+  # No other test is passing in `opts` as a map, so these are just some white box tests for sanity checking
+  describe "can use a map for validate/2" do
+    schema = []
+    opts = %{}
+    assert NimbleOptions.validate(opts, schema) == {:ok, %{}}
+
+    schema = [
+      name: [type: :string, required: true],
+      context: [type: :atom, required: false]
+    ]
+
+    opts = %{}
+
+    assert NimbleOptions.validate(opts, schema) ==
+             {:error,
+              %ValidationError{
+                key: :name,
+                value: nil,
+                keys_path: [],
+                message: "required :name option not found, received options: []"
+              }}
+
+    opts = %{name: "primary 1"}
+    assert NimbleOptions.validate(opts, schema) == {:ok, %{name: "primary 1"}}
+  end
+
   describe "validate!/2 (raising version)" do
     test "returns the direct options if the options are valid" do
       schema = [name: [], context: []]
Repository: dashbitco/nimble_options
Pull request #142 (2025-04-04 14:36:21)

Fix ignoring schema when wildcard-key is defined
Currently, schemas with wildcard-key defined misbehave:

```elixir
iex(1)> NimbleOptions.validate [], [table: [doc: "ETS table to use", type: :atom, default: nil], *: [type: :any]]
{:ok, []}
iex(2)> NimbleOptions.validate [], [table: [doc: "ETS table to use", type: :atom, default: nil]]
{:ok, [table: nil]}
```

The reason is that `NimbleOptions.expand_star_to_option_keys/2` ignores all other keys, except *present in the data* when handling wildcard.

Is that intended?

josevalim: Yeah, I feel it should be [table: nil] for both, right @whatyouhide?
coveralls: ## Pull Request Test Coverage Report for [Build e7ed4c95ea219a988286bc04378fe70620abab1a-PR-142](https://coveralls.io/builds/73087266)


### Details

* **1** of **1**   **(100.0%)**  changed or added relevant line in **1** file are covered.
* No unchanged relevant lines lost coverage.
* Overall coverage remained the same at **93.793%**

---



|  Totals | [![Coverage Status](https://coveralls.io/builds/73087266/badge)](https://coveralls.io/builds/73087266) |
| :-- | --: |
| Change from base [Build 19f7b2409832fade7541c576cfae03bd57b8a871](https://coveralls.io/builds/71465635): |  0.0% |
| Covered Lines: | 272 |
| Relevant Lines: | 290 |

---
##### 💛  - [Coveralls](https://coveralls.io)


Patch:
diff --git a/lib/nimble_options.ex b/lib/nimble_options.ex
index 4c00ad3..1653f0f 100644
--- a/lib/nimble_options.ex
+++ b/lib/nimble_options.ex
@@ -898,7 +898,7 @@ defmodule NimbleOptions do
         keys
 
       schema_opts ->
-        Enum.map(opts, fn {k, _} -> {k, schema_opts} end)
+        keys ++ Enum.map(opts, fn {k, _} -> {k, schema_opts} end)
     end
   end
 


Test patch:
diff --git a/test/nimble_options_test.exs b/test/nimble_options_test.exs
index 72c487e..39d319b 100644
--- a/test/nimble_options_test.exs
+++ b/test/nimble_options_test.exs
@@ -93,6 +93,11 @@ defmodule NimbleOptionsTest do
       assert NimbleOptions.validate([context: :given], schema) == {:ok, [context: :given]}
     end
 
+    test "is used when wildcard-key is defined" do
+      schema = [context: [default: :ok], *: [type: :any]]
+      assert NimbleOptions.validate([], schema) == {:ok, [context: :ok]}
+    end
+
     test "is validated" do
       schema = [
         processors: [