Turn off the formatter entirely?

87 views
Skip to first unread message

Brian Cardarella

unread,
Jul 21, 2024, 9:34:15 AMJul 21
to elixir-lang-core
I don't see it in the docs, is there a way to turn off formatting entirely so if `mix format` is run it just turns into a no-op?

José Valim

unread,
Jul 21, 2024, 9:36:27 AMJul 21
to elixir-l...@googlegroups.com
You can probably change its inputs in .formatter.exs to point to a directory that does not exist.

On Sun, Jul 21, 2024 at 10:34 AM Brian Cardarella <bcard...@gmail.com> wrote:
I don't see it in the docs, is there a way to turn off formatting entirely so if `mix format` is run it just turns into a no-op?

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/7ebc1f83-666a-4f5c-b9c5-f9fd04224d3bn%40googlegroups.com.

Brian Cardarella

unread,
Jul 21, 2024, 9:40:42 AMJul 21
to elixir-lang-core
I get that this would work but that feels hacky to me. Would you accept a PR to provides an opt-out option? Also, why does `mix format` format anything at all if `.formatter` isn't defined? I would have expected that to be no-op.

My use cases:

1. I don't like auto-formatters. We don't need to debate the merits of this, just my preference
2. Sourceror forces everything through the formatter. When converting quoted back to strings despite all of the indentation information being included in the AST nodes the formatter is still run. I'd much prefer if the project itself opts out of the formatter that this doesn't happen and re-format entire files on someone.

Brian Cardarella

unread,
Jul 21, 2024, 9:41:41 AMJul 21
to elixir-lang-core
Yes, I know that Sourceror has `patch_string` but that doesn't solve all the problems I'm tackling.

José Valim

unread,
Jul 21, 2024, 9:45:39 AMJul 21
to elixir-l...@googlegroups.com
I think there is some confusion happening here.

1. I don't see a reason to allow mix format to be a no-op? If you don't want to run the formatter, you can simply not run "mix format".

2. On the other hand, I don't think turning off the formatter will address Sourceror. I believe it uses the formatting APIs to stitch the code back together, regardless of mix format.

In other words, I don't think the issue you have is mix format. It is with whatever tool that is invoking it.

Brian Cardarella

unread,
Jul 21, 2024, 9:50:16 AMJul 21
to elixir-l...@googlegroups.com
You're correct that I'm probably coming at this from the wrong end. In lieu of not getting Sourceror to accept opting out of the formatter I was searching for ways to avoid the formatter from doing anything.

As an aside, I realize the ship has sailed on this but I do wish the formatter was opt-in by design. Iteratively build your formatting preferences rather than default being anything at all. A single LOC to have the current settings, but still opt-in

- Brian


You received this message because you are subscribed to a topic in the Google Groups "elixir-lang-core" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elixir-lang-core/SYdxYLcsirM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/CAGnRm4K1JvbNyobyp2mJ3v%2BEgzn4pPriRQHg5ZzQ%2Bfwde32yJw%40mail.gmail.com.

José Valim

unread,
Jul 21, 2024, 9:55:11 AMJul 21
to elixir-l...@googlegroups.com
The formatter is opt-in. Elixir does not call "mix format" for you.

Bruce Tate

unread,
Jul 21, 2024, 9:56:53 AMJul 21
to elixir-l...@googlegroups.com
That's the way I use it. I have projects that use it and those that don't. 

-bt



--

Regards,
Bruce Tate
CEO

Brian Cardarella

unread,
Jul 21, 2024, 9:57:12 AMJul 21
to elixir-l...@googlegroups.com
I've run across too many people that have `mix format` as part of their editor workflow. PRs that include massive reformats. It doesn't happen often but it happens.

- Brian


Brian Cardarella

unread,
Jul 21, 2024, 10:12:05 AMJul 21
to elixir-l...@googlegroups.com
Actually I seem to recall bringing this up with Drogan a few months ago and that there is no way to perfectly preserve the original formatting converting a parsed file’s AST back to string so I have to find a way forward with patch_string


- Brian

José Valim

unread,
Jul 21, 2024, 10:23:12 AMJul 21
to elixir-l...@googlegroups.com
Elixir allows you to parse the code with information to convert the parsed code into formatted code. Someone could perhaps implement a patching mechanism that keeps the code exactly as is, but that is quite complex:

1. If you change, delete, or introduce AST nodes: what does "as is" mean?
2. It will probably take a huge time investment to implement this, if at all possible

In any case, this is not a concern of Elixir core itself. At the same time I think we should acknowledge that the formatter has benefits for tools like Sourceror.

Brian Cardarella

unread,
Jul 21, 2024, 10:41:00 AMJul 21
to elixir-l...@googlegroups.com
I think I just need to re-tool my implementation and come at it from a different angle. Thanks for the discussion

- Brian


Jean Klingler

unread,
Jul 21, 2024, 11:32:35 AMJul 21
to elixir-l...@googlegroups.com
> I've run across too many people that have `mix format` as part of their editor workflow. PRs that include massive reformats. It doesn't happen often but it happens.

I was skeptical but this argument convinced me that we should consider such an opt-out option in .formatter.exs.

Forking a repo, starting to work on a fix, realizing they are not using the formatter and that parts now have changed, tweaking the workspace settings to disable the formatter for this project, reverting the formatter changes...
This is all unnecessary friction that could indeed be avoided by having the settings file stating in the first place: "hey, this project doesn't use the formatter, please don't format the files".

My only concern is that I wish the formatter was more widely used, and adding this feature might send a signal in the opposite direction.

Reply all
Reply to author
Forward
0 new messages