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

fix(formatter): fix small issue where there was only one newline added #13867

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

pdgonzalez872
Copy link
Contributor

to a def that is followed by a module attribute.

Closes #13866


I'm not sure this implementation is the best, but it seems to do the job. I wouldn't be surprised if there is a better way to solve it though. This was my naive approach.

The test cases show the current behavior (def + def works, but def + mod attr doesn't).

Feel free to adjust/modify/close/do whatever you'd like to it if you see it fit.

Thank you for all of your work as usual! ❤️

to a def that is followed by a module attribute.
@@ -656,6 +656,14 @@ defmodule Code.Formatter do
defp block_next_line(:@), do: @empty
defp block_next_line(_), do: break("")

defp maybe_add_newlines({:def, [{:@, _, _} = _next | _]}, _meta) do
Copy link
Member

Choose a reason for hiding this comment

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

We should not look at def, because we can have def, defp, defmacro, defmacrop... and projects can define defn, defnp, etc. We do have some code today that skips adding new lines if they are module attributes but perhaps the code should only avoid adding lines below, not lines up.

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.

Potential formatter bug - newlines don't seem to be added as expected
2 participants