Skip to content
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

Closed

Conversation

eksperimental
Copy link
Contributor

Replace ExDoc.normalize_options/1 with a more general function named ExDoc.normalize_options/3

Introduce:

  • ExDoc.normalize_source_url_pattern/2
  • ExDoc.normalize_directory/2

@josevalim
Copy link
Member

Thanks @eksperimental!

Replace ExDoc.normalize_options/1 with a more general function named ExDoc.normalize_options/3

Why? What are we solving with this? Which issues are we trying to prevent? What do we gain? :)

@eksperimental
Copy link
Contributor Author

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.
Let's hold it off for now until we sort the other issue

@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 1 fixed issue! 🎉

You can see more details about this review at https://ebertapp.io/github/elixir-lang/ex_doc/pulls/709.

@eksperimental
Copy link
Contributor Author

eksperimental commented May 19, 2017

@josevalim, view check the new changes.
After reworking it out for a while I ended up leaving normalize_options/1 and adding normalize_options/3.

The reason for introducing normalize_options/3 is because it allows us to modify options directly without the need to create new functions and duplicate code as in https://github.com/elixir-lang/ex_doc/pull/709/files#diff-817174a6c3600e5759b5cf9117b0f39fL164

Copy link
Member

@milmazz milmazz left a 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
Copy link
Member

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))

Copy link
Contributor Author

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


if args != [] do
Mix.raise "Extraneous arguments on the command line"
{cli_options, remaining_args, _invalid} =
Copy link
Member

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.

|> 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/presedence/precedence/

# CLI options have presedence over config
|> Keyword.merge(cli_options)
# source_url is accepted at root level config
|> (&(if value = config[:source_url],
Copy link
Member

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?

Copy link
Contributor Author

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.

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
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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).

@josevalim
Copy link
Member

The reason for introducing normalize_options/3 is because it allows us to modify options directly without the need to create new functions and duplicate code

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.

@eksperimental
Copy link
Contributor Author

Thank you for the review @milmazz,
I have implement most of your suggestions, please have a look one last time.
I have reworked the helper so it doesn't break the pipe line flow.

@josevalim If you are still not convinced,
please close the PR.

Introduce:
- ExDoc.normalize_source_url_pattern/2
- ExDoc.normalize_paths/2
@josevalim
Copy link
Member

Ok, I will close the PR then. Thank you @eksperimental for the different attempts.

@josevalim josevalim closed this May 20, 2017
@eksperimental eksperimental deleted the default_config3 branch May 20, 2017 07:35
@josevalim
Copy link
Member

josevalim commented May 20, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants