Skip to content

Formatter keeps quotes in atom keys #13108

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

Merged
merged 1 commit into from
Nov 15, 2023

Conversation

sabiwara
Copy link
Contributor

Close #13103

else
IO.iodata_to_binary([?", Atom.to_string(atom), ?", ?:])
[?", atom |> Atom.to_string() |> String.replace("\"", "\\\""), ?", ?:]
Copy link
Member

Choose a reason for hiding this comment

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

I think we should use Macro.inspect_atom(:key, atom). This way we can even skip the Macro.classify_atom call.

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 that's a nice one, totally forgot about inspect_atom!

But it seems to be over-escaping backslashes for our usage:
Screenshot 2023-11-15 at 20 55 05

Will try to figure out if we can remove the double escape.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also noticed that this code here is almost the same, there's probably a way to refactor it (maybe with Macro.inspect_atom/2)

Copy link
Member

@josevalim josevalim Nov 15, 2023

Choose a reason for hiding this comment

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

Ah, it is because strings in the formatter are already unescaped. My bad. Your PR is good to go!

@sabiwara sabiwara merged commit e58e267 into elixir-lang:main Nov 15, 2023
@sabiwara sabiwara deleted the format-atom-quotes branch November 15, 2023 12:35
josevalim pushed a commit that referenced this pull request Nov 15, 2023
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.

mix format strips escapes from atoms with double quotes in that are used as keys in Keyword lists or maps
2 participants