Skip to content

Commit

Permalink
Require Elixir v1.14+
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Oct 25, 2024
1 parent 39960b5 commit cf49545
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 82 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
fail-fast: false
matrix:
include:
- pair: # Test very old elixir and Erlang
elixir: "1.13"
otp: "22"
- pair: # Test very old Elixir and Erlang
elixir: "1.14"
otp: "23"
- pair: # Test Erlang without -doc attribute support
elixir: "1.16"
otp: "26"
Expand Down
16 changes: 4 additions & 12 deletions lib/ex_doc/autolink.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,9 @@ defmodule ExDoc.Autolink do
app_url(base_url, module, config, path, config.ext, "#{anchor}")
end

defp string_app_module_url(string, tool, module, anchor, config) do
defp string_app_module_url(tool, module, anchor, config) do
if Enum.any?(config.filtered_modules, &(&1.module == module)) do
# TODO: Remove on Elixir v1.14
prefix =
if unquote(Version.match?(System.version(), ">= 1.14.0")) do
""
else
~s|"#{string}" |
end

warn(config, prefix <> "reference to a filtered module")
warn(config, "reference to a filtered module")
nil
else
app_module_url(tool, module, anchor, config)
Expand Down Expand Up @@ -269,7 +261,7 @@ defmodule ExDoc.Autolink do

case {mode, Refs.get_visibility(ref)} do
{_link_type, visibility} when visibility in [:public, :limited] ->
string_app_module_url(string, tool(module, config), module, anchor, config)
string_app_module_url(tool(module, config), module, anchor, config)

{:regular_link, :undefined} ->
nil
Expand Down Expand Up @@ -493,7 +485,7 @@ defmodule ExDoc.Autolink do
if same_module? do
fragment(kind, name, arity)
else
url = string_app_module_url(original_text, tool, module, nil, config)
url = string_app_module_url(tool, module, nil, config)
url && url <> fragment(kind, name, arity)
end

Expand Down
21 changes: 5 additions & 16 deletions lib/ex_doc/language/elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ defmodule ExDoc.Language.Elixir do
extra_annotations =
case {kind, name, arity} do
{:macro, _, _} -> ["macro"]
{_, :__struct__, 0} -> ["struct"]
{_, :__struct__, _} -> ["struct"]
_ -> []
end

Expand Down Expand Up @@ -122,19 +122,8 @@ defmodule ExDoc.Language.Elixir do
end

# If content is a map, then it is ok.
defp doc?({_, _, _, %{}, _}, _) do
true
end

# If it is none, then we need to look at underscore.
# TODO: We can remove this on Elixir v1.13 as all underscored are hidden.
defp doc?({{_, name, _}, _, _, :none, _}, _type) do
not match?([?_ | _], Atom.to_charlist(name))
end

# Everything else is hidden.
defp doc?({_, _, _, _, _}, _) do
false
defp doc?({_, _, _, doc, _}, _) do
doc != :hidden
end

@impl true
Expand Down Expand Up @@ -424,8 +413,8 @@ defmodule ExDoc.Language.Elixir do

defp module_type_and_skip(module) do
cond do
function_exported?(module, :__struct__, 0) and
match?(%{__exception__: true}, module.__struct__()) ->
function_exported?(module, :__info__, 1) and
Enum.any?(module.__info__(:struct) || [], &(&1.field == :__exception__)) ->
{:exception, false}

function_exported?(module, :__protocol__, 1) ->
Expand Down
59 changes: 28 additions & 31 deletions lib/ex_doc/language/erlang.ex
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,40 @@ defmodule ExDoc.Language.Erlang do
def function_data(entry, module_data) do
{{kind, name, arity}, _anno, _signature, doc_content, metadata} = entry

# TODO: Edoc on Erlang/OTP24.1+ includes private functions in
# the chunk, so we manually yank them out for now.
if kind == :function and doc_content != :hidden and
function_exported?(module_data.module, name, arity) do
if kind == :function and doc_content != :hidden do
function_data(name, arity, doc_content, module_data, metadata)
else
:skip
end
end

defp function_data(name, arity, _doc_content, module_data, metadata) do
specs =
case Map.fetch(module_data.private.specs, {name, arity}) do
{:ok, spec} ->
[spec]

:error ->
case Map.fetch(module_data.private.specs, {module_data.module, name, arity}) do
{:ok, spec} ->
[spec]

:error ->
[]
end
end

{file, line} = Source.fetch_function_location!(module_data, {name, arity})

%{
doc_fallback: fn -> equiv_data(module_data.module, file, line, metadata) end,
extra_annotations: [],
source_line: line,
source_file: file,
specs: specs
}
end

defp equiv_data(module, file, line, metadata, prefix \\ "") do
case metadata[:equiv] do
nil ->
Expand Down Expand Up @@ -102,33 +126,6 @@ defmodule ExDoc.Language.Erlang do
end
end

defp function_data(name, arity, _doc_content, module_data, metadata) do
specs =
case Map.fetch(module_data.private.specs, {name, arity}) do
{:ok, spec} ->
[spec]

:error ->
case Map.fetch(module_data.private.specs, {module_data.module, name, arity}) do
{:ok, spec} ->
[spec]

:error ->
[]
end
end

{file, line} = Source.fetch_function_location!(module_data, {name, arity})

%{
doc_fallback: fn -> equiv_data(module_data.module, file, line, metadata) end,
extra_annotations: [],
source_line: line,
source_file: file,
specs: specs
}
end

@impl true
def callback_data(entry, module_data) do
{{_kind, name, arity}, anno, signature, _doc, metadata} = entry
Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ defmodule ExDoc.Mixfile do
use Mix.Project

@source_url "https://github.com/elixir-lang/ex_doc"
@version "0.34.2"
@version "0.35.0-dev"

def project do
[
app: :ex_doc,
version: @version,
elixir: "~> 1.13",
elixir: "~> 1.14",
deps: deps(),
aliases: aliases(),
package: package(),
Expand Down
9 changes: 1 addition & 8 deletions test/ex_doc/cli_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,7 @@ defmodule ExDoc.CLITest do
@ebin "_build/test/lib/ex_doc/ebin"

defp run(args) do
# TODO: Use with_io on Elixir v1.13
io =
capture_io(fn ->
send(self(), ExDoc.CLI.main(args, &{&1, &2, &3}))
end)

assert_receive response
{response, io}
with_io(fn -> ExDoc.CLI.main(args, &{&1, &2, &3}) end)
end

test "minimum command-line options" do
Expand Down
12 changes: 2 additions & 10 deletions test/ex_doc/formatter/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -337,17 +337,13 @@ defmodule ExDoc.Formatter.HTMLTest do
)
)

assert File.read!(tmp_dir <> "/html/old-license.html") == """
assert File.read!(tmp_dir <> "/html/old-license.html") =~ """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Elixir v1.0.1 — Documentation</title>
<meta http-equiv="refresh" content="0; url=license.html">
<meta name="generator" content="ExDoc v0.34.2">
</head>
<body></body>
</html>
"""
end

Expand All @@ -361,17 +357,13 @@ defmodule ExDoc.Formatter.HTMLTest do
)
)

assert File.read!(tmp_dir <> "/html/old-license.html") == """
assert File.read!(tmp_dir <> "/html/old-license.html") =~ """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Elixir v1.0.1 — Documentation</title>
<meta http-equiv="refresh" content="0; url=license.html">
<meta name="generator" content="ExDoc v0.34.2">
</head>
<body></body>
</html>
"""
end
end
Expand Down

0 comments on commit cf49545

Please sign in to comment.