Make formatter plugins which target .ex/.exs run alongside (not "instead of") standard formatting and other plugins which target sigils. - #15742
Conversation
…em should all format, after standard .ex/.exs formatting.
… should all format, after standard .ex/.exs formatting.
|
This is definitely a breaking change. What we could try to do is to either have an option that allows you to call the original formatter or pass a function with the original formatter that you could call. |
|
It is probably better as an option because of you have multiple .ex plugins, we only need to format it once. But then there is the question if we run it before or after. |
|
fwiw, styler does the equivalent of so anything non-optional would be redundant cpu in styler's case. perhaps the plugins themselves can flag something in their you could get the same behaviour by having it be user configured in .formatter.exs, but i'd guess that in practice the user is only going to do that when a plugin's README tells them to, at which point the plugin could've just told the formatter itself. OR if the status quo is preferable, maybe the Formatter |
Expected behavior
.ex/.exsfile extensions, plugin formatting is run after standardmix formatformatting for those files..ex/.exsfile extensions, alongside plugin B which specifies sigils within those files,pluginslist in.formatter.exs)Observed behavior
.ex/.exsfile extensions, standardmix formatformatting is not applied to those files..ex/.exsfile extensions, alongside plugin B which targets sigils within those files,.ex/.exsfiles)Working with some mix format plugins, I noticed that a plugin targeting
.exfiles would cause a second plugin targeting~H"""..."""sigils to not format them at all. After looking intoformat.ex, it seems like this is because of the current implementation of find_formatter_for_file which has a cond with three branches:It looks like sigil formatting happens during
elixir_format, which iiuc won't run at all if a plugin is found for an.exor.exsfile matching the first case of thiscond. Because of this, it seems that sigil-targeting plugins won't run at all for files where another plugin was found targeting.exor.exs. I think it also means standard elixir formatting won't run on.ex/.exsfiles if a plugin targets them. These interpretations seem to be verified by the three tests cases in 12a14ef which fail prior to the fix.Perhaps this is all intentional behavior? I found it a bit surprising, and didn't see mention of it at https://mix.hexdocs.pm/main/Mix.Tasks.Format.html#plugins, but happy to simply be informed here as well!
Using this command to run the three test cases:
Now, I can't help but add something you've likely heard many times before: Elixir has been (and continues to be) a joy to work with, thank you for all your labors making it the wonderful set of tools it is today.