Environment
Elixir & Erlang/OTP versions (elixir --version): Elixir 1.9.1 (compiled with Erlang/OTP 22)
Operating system: Fedora 30
Current behavior
mix format.all doesn't apply format rules on valid code on doctests
e.g.:
On code like this
@doc """
Given a list of Either, it returns `{:ok, list}` if every element of the list is of type `{:ok, _}`. Otherwise the first `{:error, _}` is returned.
## Examples
iex> sequence([{:ok, 1}, {:ok, 2}])
{:ok, [1, 2]}
iex> sequence([{:ok, 1}, {:error, 2}, {:ok, 3}])
{:error, 2}
iex> sequence([{:error, 1}, {:error, 2}])
{:error, 1}
"""
The task does not apply correct formatting rules.
Expected behavior
I expect the rules application to doctests
Yes, this is a known limitation and implementing it would be a large effort, because we would also need a complete markdown parser. In fact, a markdown formatter wouldn鈥檛 be a bad idea also, but this is a large effort that should most likely be implemented outside of the language and then contributed in once complete. When that happens, we can gladly revisit this discussion. Thank you!
Would a full markdown parser be needed? or just a parser that extracts the iex> lines from indented code? I'm thinking we could use nimble_parse for that.
Somebody with more experience on markdown would have to answer that but I am afraid of false positives. Although, on the other hand, we do parse only iex> for doctests.
Somebody with more experience on markdown would have to answer that but I am afraid of false positives. Although, on the other hand, we do parse only
iex>for doctests.
yes. I was thinking of that after I wrote my comment. Just extract the iex> lines.
Regarding parsing markdown, I think it was mentioned in a discussion in ExDoc that nimble_parsec wouldn't be that usefull for a full markdown parser.
Somebody with more experience on markdown would have to answer that but I am afraid of false positives. Although, on the other hand, we do parse only
iex>for doctests.
I was thing exactly to parse everything after iex>, the part that is executed in the test suite.
The logic for extracting the tests is in ExUnit.DocTest.
I can try to put some time aside and have a look, and submit a PR if there's interest in this feature
@eksperimental let me know if we can try together
@lucazulian if there is a will to include the change, we can give it a go.