Skip to content

Fix formatter comment handling in calls and interpolations - #16016

Merged
josevalim merged 2 commits into
elixir-lang:mainfrom
mandar1045:fix-formatter-comment-interpolation
Oct 27, 2026
Merged

josevalim merged 2 commits into
elixir-lang:mainfrom
mandar1045:fix-formatter-comment-interpolation

Conversation

@mandar1045

Copy link
Copy Markdown
Contributor

Closes #16015.

Three comment bugs in the formatter. The first two only happen on main, since #15893:

  • Comments inside interpolations in sigils, charlists and quoted atoms were moved into the interpolation, so they could comment out the closing } and the output didn't compile. In heredoc sigils and charlists the comment was dropped. They're now moved outside, like for strings.
  • A comment after the first keyword value of a call without parens, like @moduledoc deprecated: "..." # comment, ended up after the key, with the value at column 0. The value now goes on its own line, under the comment.
  • A comment between the arguments of a call with trailing keywords put the arguments on separate lines but kept the keywords glued to the last one, so a second format changed it again. This one happens on 1.20 too.

I checked by adding comments to Elixir's own lib files and formatting them twice: nothing changes on the second run. Formatting the repo itself doesn't change any file.

Comments between arguments of a call with trailing keywords forced
the leading arguments into separate lines, but the keyword list was
still glued to the last argument, so formatting was not idempotent.

Comments inside interpolations were only moved out of strings, so
they were dropped in heredoc sigils and charlists and could end up
commenting out the closing interpolation delimiter in sigils and
quoted atoms.
A comment after the value of the first keyword in a call without
parens, such as @moduledoc deprecated: "..." # comment, was written
after the key, with the value at the start of the next line.

Closes elixir-lang#16015
@josevalim
josevalim merged commit c57b016 into elixir-lang:main Oct 27, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@mandar1045
mandar1045 deleted the fix-formatter-comment-interpolation branch October 27, 2026 16:35
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.

Formatter breaks or drops comments inside interpolations

2 participants