ocaml/dune

dune fmt should be able to format single files

Open

#7,287 opened on Mar 11, 2023

 (7 comments) (2 reactions) (1 assignee)OCaml (478 forks)github user discovery
good first issue

Repository metrics

Stars
 (1,882 stars)
PR merge metrics
 (Avg merge 1d 20h) (345 merged PRs in 30d)

Description

We should expand the capabilities of dune fmt so that it can format files passed on the command line. This would probably involve making a more serious implementation for it rather than just being a command line alias for dune build @fmt --auto-promote.

We have two cases for dune fmt file1.

  • If a file can be formatted, then we should format it according to whatever rule @fmt uses.
  • If it cannot be formatted then either we error or do nothing.

Perhaps we can control the behaviour of the second with an option which will allow users to hook up commit scripts like those proposed in https://github.com/ocaml/dune/issues/5107.

It would also pave the way for requesting a file to be formatted, which we can use to implement more sophisticated features like having the latest files changed in version control only be formatted. Again suggested in https://github.com/ocaml/dune/issues/5107.

I will need to do some more thinking about the implementation so making this ticket in the mean time.

Contributor guide