package ocamlformat

  1. Overview
  2. Docs

Description

ocamlformat is a code formatter for OCaml. It comes with opinionated default settings but is also fully customizable to suit your coding style.

  • Profiles: ocamlformat offers profiles we predefined formatting configurations. Profiles include default, ocamlformat, janestreet.
  • Configurable: Users can change the formatting profile and configure every option in their .ocamlformat configuration file.
  • Format Comments: ocamlformat can format comments, docstrings, and even code blocks in your comments.
  • RPC: ocamlformat provides an RPC server that can be used by other tools to easily format OCaml Code.

Published: 03 Dec 2024

README

ocamlformat

OCaml Code Formatter.

OCaml-CI Build Status

ocamlformat is a code formatter for OCaml. It comes with opinionated default settings but is also fully customizable to suit your coding style.

  • Profiles: ocamlformat offers profiles we predefined formatting configurations. Profiles include default, ocamlformat, janestreet.
  • Configurable: Users can change the formatting profile and configure every option in their .ocamlformat configuration file.
  • Format Comments: ocamlformat can format comments, docstrings, and even code blocks in your comments.
  • RPC: ocamlformat provides an RPC server that can bed used by other tools to easily format OCaml Code.

ocamlformat is part of the OCaml Platform, the recommended set of tools for OCaml.

Getting Started

Installation

To use ocamlformat, you will need OCaml and opam (the OCaml package manager) installed on your system. Visit the OCaml.org installation page for instructions.

With OCaml and opam installed, you can install ocamlformat with:

opam install ocamlformat

Usage

Formatting your code is as easy as running:

ocamlformat file.ml

To configure ocamlformat to your liking, create an .ocamlformat configuration file in your project with settings like:

profile = default
version = 0.27.0

Refer to our documentation or use ocamlformat --help for a full list of configuration options.

To make formatting your code even easier, use the dune build system:

dune fmt

Documentation

The full documentation for ocamlformat, including comprehensive user and API guides, can be found on OCaml.org.

Contributing

Contributing Guide

We wholeheartedly welcome contributors! To start, please read our Contributing Guide to familiarize yourself with our development process, including how to propose and how to start hacking on ocamlformat.

Hacking Guide

In addition to the Contributing Guide, we provide a Hacking Guide for ocamlformat developers. It contains in-depth explanation of development processes, such as running tests, releasing ocamlformat, etc.

Code of Conduct

In order to foster a welcoming and respectful community, ocamlformat has adopted the OCaml Code of Conduct.

Roadmap

Interested in the future of ocamlformat? Take a look at our Roadmap to understand our vision and planned advancements for ocamlformat.

Discussions

For conversations on ongoing development, be sure to visit the ocamlformat section of the OCaml Discuss forum.

License

ocamlformat is distributed under the terms of the MIT License. See the LICENSE file for complete details.

Acknowledgments

We gratefully acknowledge the individuals and organizations that have significantly contributed to ocamlformat.

ocamlformat owes its existance to its initial author, Josh Berdine. We also want to express our appreciation to Hugo Heuzard, Guillaume Petiot, and Jules Aguillon. Their significant contributions have been instrumental to the advancement of ocamlformat.

Moreover, our gratitude extends to Facebook, who fostered the inception of ocamlformat as part of their work on the ReasonML project. Jane Street and Tarides have also provided financial support and contributed to the ongoing development of the project.

Dependencies (5)

  1. re >= "1.10.3"
  2. ocamlformat-lib = version
  3. dune >= "2.8"
  4. csexp >= "1.4.0"
  5. ocaml >= "4.08" & < "5.4"

Dev Dependencies (3)

  1. odoc with-doc
  2. ocamlformat-rpc-lib with-test & = version
  3. cmdliner with-test = "false" & >= "1.1.0" | with-test & >= "1.2.0"

Used by (87)

  1. ask
  2. ask-integrator
  3. autofonce
  4. autofonce_config
  5. autofonce_core
  6. autofonce_lib
  7. autofonce_m4
  8. autofonce_misc
  9. autofonce_patch
  10. autofonce_share
  11. awsm-codegen
  12. bastet < "2.0.0"
  13. bitpack_serializer
  14. brisk-reconciler
  15. CamelCase
  16. claudius
  17. coap
  18. coap-core
  19. coap-server-lwt
  20. diff
  21. diskuvbox < "0.1.2"
  22. dream-inertia
  23. drom
  24. drom_lib
  25. drom_toml
  26. dump_ocamlformat
  27. dune_deps_extra
  28. ez_cmdliner >= "0.2.0"
  29. ez_config >= "0.2.0"
  30. ez_file >= "0.2.0"
  31. ez_hash < "0.5.3"
  32. ez_opam_file
  33. ez_search
  34. ez_subst
  35. fromager
  36. giflib
  37. guardian < "0.1.0"
  38. header-check
  39. html_of_jsx >= "0.0.6"
  40. js_of_ocaml-webgpu >= "0.2"
  41. junit >= "2.2.0"
  42. junit_alcotest >= "2.2.0"
  43. junit_ounit >= "2.2.0"
  44. letters >= "0.2.0" & != "0.3.1"
  45. melange-fest
  46. melange-json >= "1.2.0"
  47. melange-radix-icons >= "0.1.0"
  48. merge-fmt >= "0.4"
  49. miou
  50. mlx
  51. module-graph
  52. mqtt
  53. noCanren >= "0.3.0~alpha1"
  54. ocaml-lsp-server < "1.9.0" | >= "1.21.0-4.14"
  55. ocp-search
  56. ocplib_stuff >= "0.3.0"
  57. opam-bin >= "0.9.5"
  58. opam_bin_lib >= "0.9.5"
  59. opentelemetry >= "0.12"
  60. owi >= "0.2"
  61. polars
  62. polars_async
  63. ppx_deriving_jsonschema
  64. prelude >= "0.4"
  65. primavera
  66. psmt2-frontend >= "0.3.0"
  67. rea < "0.2.0"
  68. reason-react >= "0.16.0"
  69. reason-react-ppx >= "0.16.0"
  70. red-black-tree
  71. runtime_events_tools >= "0.5.3"
  72. scope
  73. signal
  74. sihl < "0.1.0"
  75. slipshow >= "0.1.1"
  76. smtml >= "0.10.0"
  77. solidity-alcotest
  78. solidity-common
  79. solidity-parser
  80. solidity-test
  81. solidity-typechecker
  82. sqids
  83. styled-ppx
  84. synchronizer
  85. tabr
  86. yocaml >= "2.0.0"
  87. zanuda != "1.1.0"

Conflicts

None