From 1dd8ec9843194a7e3250a03685996fcd9490ba7a Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Sun, 22 Mar 2026 16:53:04 -0500 Subject: [PATCH] Check referenced target text in skip_undefined_reference_warnings_on `skip_undefined_reference_warnings_on` only checked the source document (id, module, file) against the skip list - not the referenced path. So adding a target like "LICENSES/LICENSE.txt" to the list had no effect. Now the target path is also checked (with and without a fragment). Related issue: #2221 --- lib/ex_doc/autolink.ex | 14 +++++++++---- test/ex_doc/language/elixir_test.exs | 30 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/lib/ex_doc/autolink.ex b/lib/ex_doc/autolink.ex index 8fa342b70..fb9697ed4 100644 --- a/lib/ex_doc/autolink.ex +++ b/lib/ex_doc/autolink.ex @@ -156,10 +156,16 @@ defmodule ExDoc.Autolink do def maybe_warn(config, ref, visibility, metadata) do file = Path.relative_to_cwd(config.file) - unless Enum.any?( - [config.id, config.module_id, file], - config.skip_undefined_reference_warnings_on - ) do + skip_checks = + case metadata do + %{file_path: file_path} when is_binary(file_path) -> + [config.id, config.module_id, file, file_path] + + _ -> + [config.id, config.module_id, file] + end + + if not Enum.any?(skip_checks, config.skip_undefined_reference_warnings_on) do warn(config, ref, visibility, metadata) end end diff --git a/test/ex_doc/language/elixir_test.exs b/test/ex_doc/language/elixir_test.exs index 4023708c1..704c51d8d 100644 --- a/test/ex_doc/language/elixir_test.exs +++ b/test/ex_doc/language/elixir_test.exs @@ -644,6 +644,30 @@ defmodule ExDoc.Language.ElixirTest do ~s|Foo| end) =~ ~s|documentation references file "Foo Bar.md" but it does not exist| + # skip_undefined_reference_warnings_on matches file_path (without fragment) + refute_warn(fn -> + assert autolink_doc( + "[Foo](Foo Bar.md)", + opts ++ + [ + extras: %{}, + skip_undefined_reference_warnings_on: &(&1 == "Foo Bar.md") + ] + ) == ~s|Foo| + end) + + # skip_undefined_reference_warnings_on matches file_path even with fragment + refute_warn(fn -> + autolink_doc( + "[Foo](Foo Bar.md#section)", + opts ++ + [ + extras: %{}, + skip_undefined_reference_warnings_on: &(&1 == "Foo Bar.md") + ] + ) + end) + assert warn(fn -> assert autolink_doc("[Bar A](`Bar.A`)", opts) == "Bar A" end) =~ ~s|module "Bar.A" but it is undefined| @@ -718,6 +742,12 @@ defmodule ExDoc.Language.ElixirTest do message end + defp refute_warn(fun) when is_function(fun, 0) do + fun.() + + refute_received {:warn, _, _} + end + defp autolink_spec(spec, options \\ []) do config = struct!(ExDoc.Autolink, Keyword.merge(@default_options, options)) ExDoc.Language.Elixir.autolink_spec(spec, config)