ocaml / ocaml/dune

Ability to format non-OCaml files

Open
#3,368 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
OCaml
Stars
1.9k
Forks
500
Avg merge
15h 21m
Merged PRs (30d)
277

Description

Desired Behavior

dune build @fmt can format anything with a dialect defined, but dialect requires the files to be OCaml-like (have an implementation and interface and compile into OCaml). It would be nice if we could define formatters for non-OCaml files. For example, Dune internally has a formatter for dune files, but I don't think it's possible for users to define similar formatters.

Examples of things we want to format:

  • atdgen files
  • random Python scripts in our build system
  • Various other sexp files we use in our builds

Example

Something like:

; dune-project
(formatter
  (extension py)
  (format python3 -m yapf -))

.. and then dune build @fmt would run the equivalent of python3 -m yapf < python_file.py for each Python file.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the formatter behavior behind dune build @fmt and the existing formatter definition for Dune files; the issue also gives a proposed (formatter ...) entry in dune-project. Done means users can register formatters for non-OCaml files, including the shown Python command, and have them run for matching files through @fmt.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.