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

Pass sigil/modifiers through to formatter #11348

Merged
merged 6 commits into from
Oct 26, 2021

Conversation

maartenvanvliet
Copy link
Contributor

I created a formatter for graphql documents, see this PR absinthe-graphql/absinthe#1114 (comment) and @benwilson512 asked whether the formatting could be dependent on whether it's a sigil being formatted or a file.

As mentioned in the discussion it can be inferred by checking the extension of the file being formatted, but this seems brittle. Also it doesn't pass through which sigil is used or any of the applied sigil modifiers. This PR changes that by passing through sigil: {name, modifiers} to the opts of the format(content, opts) in a formatter plugin.

This allows the formatter plugins to format content
based on whether it's a file or a sigil being formatted.
The modifiers could be used for additional options.
@josevalim
Copy link
Member

Thank you! This is perfect feedback just in time for the release. I have dropped two tiny comments. Also, I have a question: should we pass those as arguments instead of options then? We can have a first argument being {:extension, ".w"} | {:sigil, :W, 'modifier'}. I think I prefer your current approach, but I thought I would ask.

Also, finally, can you please update the docs to talk about those? We need to update one of Code.format_* docs and the docs for mix format plugins.

lib/elixir/lib/code.ex Outdated Show resolved Hide resolved
@maartenvanvliet
Copy link
Contributor Author

One note, the opening delimiter of the sigil could also be passed in the tuple. I don't think it adds much here but since it's public facing it would be harder to add later on. Wdyt?

@josevalim
Copy link
Member

@maartenvanvliet we can always add that as a separate option. Maybe it should be sigil: :W, modifiers: []? Then it is easier to add delimiter later on?

@maartenvanvliet
Copy link
Contributor Author

Yes, let's do that

@josevalim
Copy link
Member

Alright, I will wait for that and once it is ready I will ship it. :)

@josevalim josevalim merged commit b166e8e into elixir-lang:master Oct 26, 2021
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@maartenvanvliet maartenvanvliet deleted the sigil-formatting branch October 26, 2021 12:15
@benwilson512
Copy link
Contributor

This is amazing! ❤️

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.

3 participants