dune
dune copied to clipboard
More general support for formatters?
Currently dune supports (via dune build @fmt) formatting of Reason code using refmt, OCaml code using ocamlformat and dune files. Dialects can also provide a custom formatting action and if they do they will also be able to make use of this feature.
In #3811 there is a request to support formatting of OCaml sources by ocp-indent. That issue was closed because it was deemed too specific, and a more general mechanism was desired. This issue is to explore generalisation of the formatting mechanism in this direction.
Some points:
-
Currently there isn't much support for formatter configuration (just a single on/off switch on a per-language/dialect basis). Technically, the code for
dune build @fmtis a hardcoded "top-level" action so it would need to be refactored if this action is to take arguments specified at the project or workspace level. -
Formatters typically depend on side configuration files to function (eg
.ocamlformator.ocp-indent). The precise list of files is a function of the formatter and a more flexible mechanism should allow to specify these as well. -
Inside JS there is a formatter tool called
apply-styleused for a variety of different file formats. Could this be used as inspiration for a more general mechanism? Or perhaps the mechanism could be designed so that it could subsume this tool? More details from someone familiar with this tool could be useful here. -
An interesting point of comparison is the
inline-testsmechanism which is not aware of specific backends (such asppx-expect) in the same way that the formatting functionality is aware ofocamlformat.
See also #3368
Topiary user/proponent here…
Stepping back, why is Dune even used to call these tools at all? ocamlformat & topiary run fine on there own. Isn’t this just creating maintenance burden if we already see that users might want differing formatters? Would it be simpler if Dune just formatted itself & left everything else alone instead of trying to create wrappers (or worse trying to create files for users not using certain tools ala #9567)? What is the value?
why is Dune even used to call these tools at all?
I am not an ocamlformat user, but just to play devil's advocate: one reason is that the Dune integration can make use of the "promote" feature, which is nice.
Would it be simpler if Dune just formatted itself & left everything else alone instead of trying to create wrappers (or worse trying to create files for users not using certain tools ala #9567)? What is the value?
I agree that not everyone has the same wants and needs. What may be useful for some may be irritating for others :) Rather than choose one or the other, I would rather make dune init interactive and ask the user what she wants.
Nothing actionable here, let's close.