Skip to content

Conversation

eksperimental
Copy link
Contributor

--source-ref passed to the CLI was being lost,
meaning all links to commits/tags were being lost and the docs were always
linked to master

@sourcelevel-bot
Copy link

Hello, @eksperimental! This is your first Pull Request that will be reviewed by Ebert, an automatic Code Review service. It will leave comments on this diff with potential issues and style violations found in the code as you push new commits. You can also see all the issues found on this Pull Request on its review page. Please check our documentation for more information.

@source_root File.cwd!

def run(relative_path) do
ExDoc.Retriever.docs_from_dir(relative_path, relative_path |> doc_config)

Choose a reason for hiding this comment

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

Use a function call when a pipeline is only one function long

source_beam: Path.expand relative_path
}
end
end No newline at end of file

Choose a reason for hiding this comment

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

There should be a final \n at the end of each file.

@@ -0,0 +1,17 @@
# file: lib/ex_doc/issue446.ex
defmodule ExDoc.Issue446 do

Choose a reason for hiding this comment

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

Modules should have a @moduledoc tag.

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 Thanks! I just leave some comments.

e: :extra, v: :version, n: :canonical, s: :extra_section,
a: :assets, i: :filter_prefix],
switches: [extra: :keep])
{opts, args, _invalid} = OptionParser.parse(args,
Copy link
Member

Choose a reason for hiding this comment

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

Why not something like this?

{opts, args, _invalid} =
  OptionParser.parse(args, ...

a: :assets,
l: :logo,
n: :canonical,
v: :version,
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about sorting this aliases?

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. the idea (as the title of the commit suggests) is to keep the same order as the exdoc --help command lists them

Copy link
Member

Choose a reason for hiding this comment

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

Ok, I see, then, It would be nice to see an inline note about your suggestion because it's easy to see the pattern when those aliases are ordered alphabetically, but no when they are listed in same order as the docs, wdyt?

@@ -0,0 +1,17 @@
# file: lib/ex_doc/issue446.ex
Copy link
Member

Choose a reason for hiding this comment

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

Do you really want to include this file?

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. it was a mistake. it's from a really old PR

]

{project, version, opts} =
run(args)
Copy link
Member

Choose a reason for hiding this comment

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

Why not something like this:

{project, version, opts} = run(args)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops. that was not intented

--source-ref passed to the CLI was being lost,
meaning all links to commits/tags were being lost and the docs were always
linked to master
@eksperimental
Copy link
Contributor Author

@milmazz thank your for your input. please have a look again.

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.


switches: [
extra: :keep,
]
Copy link
Member

Choose a reason for hiding this comment

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

Missing comma after ]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it will be weird to have a ) after the comma, ex: switches: [...], )

a: :assets,
l: :logo,
n: :canonical,
v: :version,
Copy link
Member

Choose a reason for hiding this comment

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

Ok, I see, then, It would be nice to see an inline note about your suggestion because it's easy to see the pattern when those aliases are ordered alphabetically, but no when they are listed in same order as the docs, wdyt?

output: "doc",
project: nil,
retriever: ExDoc.Retriever,
source_beam: nil,
Copy link
Member

Choose a reason for hiding this comment

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

WDYT about removing those nil from defstruct/1?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually, I was thinking of that. should we use an empty string?

Copy link
Member

Choose a reason for hiding this comment

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

The default value is nil, so, you can have something like this:

defstruct [
  :main,
  :project,
  output: "doc",
  retriever: ExDoc.Retriever
]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but what's the point since those are not required.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh. I see now what you mean.
I was thinking why not have a default empty string.
I will be submitting another PR, and because we are using nil I need to check agains nil, false or "" to see if an option is unset. If by default we set to to empty, we just need to check against false or "" (and false is because people may have just used --foo without value, and it because a boolean argv.

Copy link
Member

Choose a reason for hiding this comment

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

I will be submitting another PR, and because we are using nil I need to check agains nil, false or "" to see if an option is unset.

We should continue only checking for nil. In Elixir, nil is used for absence of information (except if we have a field that may be boolean).

If the field can be an empty string and an empty string also mean "emptiness", we need to convert the empty string to nil before putting it in the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have another PR that is waiting for this one to be merged, and it deals with normalizing options individually, I guess I can include this one rule

Copy link
Member

Choose a reason for hiding this comment

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

If the field can be an empty string and an empty string also mean "emptiness", we need to convert the empty string to nil before putting it in the struct.

Yes, we should preprocess those empty strings and convert the data to nil. Also, it looks better doing this:

if options.string_field do
  # ...
end

than this:

if  options.string_field != "" do
  # ...
end

:)

lib/ex_doc.ex Outdated
project: nil,
retriever: ExDoc.Retriever,
source_beam: nil,
source_ref: "master",
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 understand why this is needed. :source_ref is not needed in the struct inside ExDoc. We only use it initially when building the source_url.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

shouldn't the struct reflect what can be passed via config, such as CLI or the docs task?

* `:source_url_pattern` - Public URL of the project. Derived from

Copy link
Member

Choose a reason for hiding this comment

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

There is no need to keep the source_ref around if we don't use it internally. The goal of ExDoc.build_config is build a set of options and build a struct that is relevant internally, if we don't use source_ref past building the config, there is no point in keeping it in the struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I guess if we ever need to find out what was passed by the user, we can add it later to it


switches: [
extra: :keep,
source_ref: :string,
Copy link
Member

Choose a reason for hiding this comment

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

Same here. This is not needed.

Copy link
Contributor Author

@eksperimental eksperimental Mar 3, 2017

Choose a reason for hiding this comment

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

This is the line that was missing and that caused source_ref to be ditched. So I would say it is a total must to be here.

Copy link
Member

Choose a reason for hiding this comment

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

Ah, it is missing it because of the changes in Elixir v1.4 regarding atoms.

Copy link
Member

Choose a reason for hiding this comment

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

It would be best for us to use :strict then and define all inputs. We can even move to use parse! so we get proper argument handling.


@type t :: %__MODULE__{
canonical: nil | String.t,
deps: [{ebin_path :: String.t, doc_url :: String.t}],
Copy link
Contributor Author

@eksperimental eksperimental Mar 3, 2017

Choose a reason for hiding this comment

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

@josevalim according to what you said, I am uncertain whether these typespecs should be nil | String.t or just String.t as they are.

@josevalim josevalim merged commit 2228073 into elixir-lang:master Mar 3, 2017
@josevalim
Copy link
Member

I have merged this right now so we get proper docs but further improvements based on the comments are still welcome. :)

@eksperimental eksperimental deleted the source_ref2 branch August 19, 2020 07:42
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.

3 participants