New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce ExDoc.normalize_options/3 and new helpers #709
Introduce ExDoc.normalize_options/3 and new helpers #709
Conversation
47ce3ca
to
625ad2f
Compare
Thanks @eksperimental!
Why? What are we solving with this? Which issues are we trying to prevent? What do we gain? :) |
I will report back later here, as I have found other issues, and I would like to sort that first and then see what's the best approach here. |
625ad2f
to
7d7446d
Compare
Ebert has finished reviewing this Pull Request and has found:
You can see more details about this review at https://ebertapp.io/github/elixir-lang/ex_doc/pulls/709. |
7d7446d
to
711777d
Compare
@josevalim, view check the new changes. The reason for introducing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eksperimental I left a few comments.
lib/ex_doc.ex
Outdated
def normalize_options(options) do | ||
options = normalize_options(options, :source_ref, ExDoc.Config.default(:source_ref)) | ||
|
||
options |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about this option:
options
|> normalize_options(:source_ref, ExDoc.Config.default(:source_ref))
|> normalize_directory([:assets, :output, :source_root])
|> normalize_source_url_pattern(options[:source_ref] || ExDoc.Config.default(:source_ref))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope. this was done intentionally.
You cannot do that, because in the last line when I access options[:source_ref]
I need the updated version that normalize_options($options, :source_ref, ExDoc.Config.default(:source_ref))
updates
lib/mix/tasks/docs.ex
Outdated
|
||
if args != [] do | ||
Mix.raise "Extraneous arguments on the command line" | ||
{cli_options, remaining_args, _invalid} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section does not seems to be related with your original goal, which is add ExDoc.normalize_options/3
.
lib/mix/tasks/docs.ex
Outdated
|> Keyword.merge(cli_opts) | ||
|> normalize_source_url(config) # accepted at root level config | ||
|> normalize_homepage_url(config) # accepted at root level config | ||
# CLI options have presedence over config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/presedence/precedence/
lib/mix/tasks/docs.ex
Outdated
# CLI options have presedence over config | ||
|> Keyword.merge(cli_options) | ||
# source_url is accepted at root level config | ||
|> (&(if value = config[:source_url], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At least for me, this anonymous function trick brakes the normal workflow of the data transformation. I like the way it was before, normalize_source_url/1
and normalize_homepage_url/1
are explicit and show their intention without looking the implementation details, if you want to look into the details you can go straight to that function. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. that's correct. I will use those then.
test/ex_doc/formatter/html_test.exs
Outdated
assert "#{output_dir()}/another_dir/dist/app-*.css" |> Path.wildcard |> File.regular? | ||
assert "#{output_dir()}/another_dir/dist/app-*.js" |> Path.wildcard |> File.regular? | ||
for file <- Path.wildcard("#{output_dir()}/another_dir/dist/app-*.{js,css}") do | ||
assert File.regular?(file) == true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't need the == true
at the end, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's the convention in the Elixir project. I probably got it from there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is a convention in Elixir. For example, the tests for File.regular?/1
(or for File
in general for that matter) never use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right.
It is used only with similar lines, and the value will be true
or false
.
as in
assert ("abcd" =~ ~R/c(d)/) == true
assert ("abcd" =~ ~R/e/) == false
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even that should be rewritten to
assert "abcd" =~ ~R/.../
refute ...
so that ExUnit can potentially produce a diff in case of failure. The only reason to use == true
(or false
) as far as I know is when the function can return something else than a boolean and you want to assert that the specific case you're testing returns a boolean (for example assert foo
would pass if foo
was anything non-nil
and non-false
).
I don't understand, if this change is about duplicate code, why is it adding more lines of code than removing? Sorry but I really can't see what we are gaining with those changes. |
19722d8
to
c0d192d
Compare
Thank you for the review @milmazz, @josevalim If you are still not convinced, |
Introduce: - ExDoc.normalize_source_url_pattern/2 - ExDoc.normalize_paths/2
c0d192d
to
2ad6df3
Compare
Ok, I will close the PR then. Thank you @eksperimental for the different attempts. |
We may check for explicit bools in Elixir because we may be checking that
=~ returns a Boolean. Other than that, there is no reason for a explicit
book check.
--
*José Valimwww.plataformatec.com.br
<http://www.plataformatec.com.br/>Founder and Director of R&D*
|
Replace ExDoc.normalize_options/1 with a more general function named ExDoc.normalize_options/3
Introduce: