Skip to content

Commit

Permalink
Make index redirect warning case-sensitive (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
cybrox authored and José Valim committed Aug 8, 2019
1 parent 2667bbc commit ac0f1d2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion lib/ex_doc/formatter/html.ex
Original file line number Diff line number Diff line change
Expand Up @@ -375,14 +375,23 @@ defmodule ExDoc.Formatter.HTML do
end

defp generate_redirect(filename, config, redirect_to) do
unless File.regular?("#{config.output}/#{redirect_to}") do
unless case_sensitive_file_regular?("#{config.output}/#{redirect_to}") do
IO.puts(:stderr, "warning: #{filename} redirects to #{redirect_to}, which does not exist")
end

content = Templates.redirect_template(config, redirect_to)
File.write!("#{config.output}/#{filename}", content)
end

defp case_sensitive_file_regular?(path) do
if File.regular?(path) do
files = path |> Path.dirname() |> File.ls!()
Path.basename(path) in files
else
false
end
end

def filter_list(:module, nodes) do
Enum.filter(nodes, &(not (&1.type in [:exception, :task])))
end
Expand Down
6 changes: 3 additions & 3 deletions test/ex_doc/formatter/html_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ defmodule ExDoc.Formatter.HTMLTest do
test "warns when generating an index.html file with an invalid redirect" do
output =
capture_io(:stderr, fn ->
generate_docs(doc_config(main: "Unknown"))
generate_docs(doc_config(main: "Randomerror"))
end)

assert output == "warning: index.html redirects to Unknown.html, which does not exist\n"
assert output == "warning: index.html redirects to Randomerror.html, which does not exist\n"
assert File.regular?("#{output_dir()}/index.html")
refute File.regular?("#{output_dir()}/Unknown.html")
assert File.regular?("#{output_dir()}/RandomError.html")
end

test "warns on undefined functions" do
Expand Down

0 comments on commit ac0f1d2

Please sign in to comment.