Possibility to specify another formatter for OCaml/ReasonML
Nobody has claimed this yet.
- Dominant language
- OCaml
- Stars
- 1.9k
- Forks
- 500
- Avg merge
- 15h 21m
- Merged PRs (30d)
- 277
Description
Desired Behavior
I have started using Topiary to format my OCaml code. I think it would make sense for me to be able to dune fmt to run topiary on OCaml files. It is already possible to specify a custom formatter for a custom dialect but it is not, to my knowledge, possible to override the formatter for OCaml (or the one for ReasonML or, why not, the one for Dune files).
Example
I think the right place for this would be in the (formatting) stanza. For now, it is already possible to do something like:
(dialect
(name quux)
(implementation
(extension quux)
(format (run quux-fmt --impl %{input-file})))
(interface
(extension quuxi)
(format (run quux-fmt --intf %{input-file}))))
(formatting
(enabled_for ocaml quux))
I think we could extend the (formatting) stanza with eg. (format_for <name> <action>). The previous file would become something like:
(dialect
(name quux)
(implementation (extension quux))
(interface (extension quuxi)))
(formatting
(enabled_for ocaml quux))
(format_for quux
(implementation (run quux-fmt --impl %{input-file}))
(interface (run quux-fmt --intf %{input-file}))))
This could make the (format) field of (dialect) obsolete, bringing everything formatting-related to (formatting). This would then also allow overriding the defaults for dune, ocaml or reason:
(formatting
(enabled_for ocaml quux)
(format_for ocaml
(implementation (run topiary --language ocaml-implementation --input-file %{input-file}))
(interface (run topiary --language ocaml-interface --input-file %{input-file}))))
And if some formatters were to become very common, one could imagine
(formatting
(enabled_for ocaml quux)
(format_for ocaml topiary))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the existing (formatting) and (dialect) examples in the issue, then trace how dune fmt handles OCaml, ReasonML, Dune files, and custom dialects. Compare the proposed (format_for <name> <action>) forms and determine the intended configuration behavior; done means the accepted design is implemented and covered for the formatter overrides described here.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ocaml
- Domain
- build-system
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100