Skip to content

Conversation

wojtekmach
Copy link
Member

Closes #799

@wojtekmach
Copy link
Member Author

I did some random testing on Ecto & Elixir codebases and looks pretty good, the only minor regression I've seen is so far is:

before:

zrzut ekranu 2017-11-27 o 02 30 15

(https://hexdocs.pm/elixir/master/File.html#t:mode/0)

after:

zrzut ekranu 2017-11-27 o 02 30 20

@josevalim
Copy link
Member

How can we fix this regression?

@wojtekmach
Copy link
Member Author

it looks like existing code that was breaking on | gets in the way, it should probably be disabled or adjusted when formatter is present. Looks relatively easy to fix, stay tuned!

@sourcelevel-bot
Copy link

Ebert has finished reviewing this Pull Request and has found:

  • 1 possible new issue (including those that may have been commented here).

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

end
end

# TODO: remove when we require Elixir v1.6+

Choose a reason for hiding this comment

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

TODO found


if formatter_available?() do
string
|> Code.format_string!(line_length: @line_length)
Copy link
Member Author

Choose a reason for hiding this comment

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

for line_length: 70 I noticed it caused churn in a few places, e.g.: https://hexdocs.pm/elixir/master/Access.html#elem/1 vs:

zrzut ekranu 2017-11-30 o 01 24 31

It might be better to stick to default line length on formatter (which then breaks other tests and I didn't want to necessarily add more if formatter_available? clauses or adjust tests 😅 )

Copy link
Member

Choose a reason for hiding this comment

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

Let's stick with 80, yeah?

@wojtekmach
Copy link
Member Author

@josevalim fixed 🎉 :

zrzut ekranu 2017-11-30 o 01 25 14


assert Autolink.typespec(quote(do: (really_long_name_that_will_trigger_multiple_line_breaks(1) :: bar | baz)), [], []) ==
~s[really_long_name_that_will_trigger_multiple_line_breaks(1) ::\n bar |\n baz]
if formatter_available?() do
Copy link
Member Author

Choose a reason for hiding this comment

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

another option to manage these tests is to have:

test "add new lines on |" do
  ...
end

@tag :formatter
test "add new lines on | with formatter" do
  ...
end

@tag :no_formatter
test "add new lines on | without formatter" do
  ...
end

and then configure proper exclude in test_helper.exs

Copy link
Member

Choose a reason for hiding this comment

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

I like the tag approach the most.


def typespec({:when, _, [{:::, _, [left, {:|, _, _} = center]}, right]} = ast, typespecs, aliases, lib_dirs) do
defp format_typespec({:when, _, [{:::, _, [left, {:|, _, _} = center]}, right]} = ast, typespecs, aliases, lib_dirs) do
if short_typespec?(ast) do
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 we need this? We should let the formatter handle it all, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

this is left as is for when formatter is not available. When we require 1.6 I'd be happy to 🔥 this

Copy link
Member Author

Choose a reason for hiding this comment

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

Just to clarify, format_typespec, short_typespec, format_typespec_with_new_line, normalize_left will all be gone when we depend on 1.6

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry. I got confused. I thought format_typespecused the formatter (since it says format in the name) and I thought that typespec_to_string used Macro.to_string since it has to_string. Should we flip the names?

Copy link
Member Author

Choose a reason for hiding this comment

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

doh, good call! All fixed now

defp short_typespec?(ast) do
byte_size(Macro.to_string(ast)) <= 70
defp put_placeholder(form, string, placeholders) do
id = zero_pad(map_size(placeholders), 3)
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 we need to pad, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

yup, not anymore as there's always a trailing _

@josevalim josevalim merged commit f96dd73 into elixir-lang:master Nov 30, 2017
@josevalim
Copy link
Member

❤️ 💚 💙 💛 💜

@wojtekmach wojtekmach deleted the wm-format branch November 30, 2017 19:24
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.

2 participants