Skip to content

Releases: ocaml-ppx/ocamlformat

0.28.1

24 Oct 13:05

Choose a tag to compare

CHANGES:

Highlight

  • * Support for OCaml 5.4
    (#2717, #2720, #2732, #2733, #2735, @Julow, @Octachron, @cod1r, @EmileTrotignon)
    OCamlformat now supports OCaml 5.4 syntax.
    Module packing of the form ((module M) : (module S)) are no longer
    rewritten to (module M : S) because these are now two different syntaxes.

  • * Reduce indentation after |> map (fun (#2694, @EmileTrotignon)
    Notably, the indentation no longer depends on the length of the infix
    operator, for example:

    (* before *)
    v
    |>>>>>> map (fun x ->
                x )
    (* after *)
    v
    |>>>>>> map (fun x ->
        x )

    @@ match can now also be on one line.

Added

  • Added option module-indent option (#2711, @HPRIOR) to control the indentation
    of items within modules. This affects modules and signatures. For example,
    module-indent=4:

    module type M = sig
        type t
    
        val f : (string * int) list -> int
    end
  • exp-grouping=preserve is now the default in default and ocamlformat
    profiles. This means that its now possible to use begin ... end without
    tweaking ocamlformat. (#2716, @EmileTrotignon)

Deprecated

  • Starting in this release, ocamlformat can use cmdliner >= 2.0.0. When that is
    the case, the tool no longer accepts unambiguous option names prefixes. For
    example, --max-iter is not accepted anymore, you have to pass the full
    option --max-iters. This does not apply to the keys in the .ocamlformat
    configuration files, which have always required the full name.
    See dbuenzli/cmdliner#200.
    (#2680, @emillon)

Changed

  • * The formatting of infix extensions is now consistent with regular
    formatting by construction. This reduces indentation in f @@ match%e
    expressions to the level of indentation in f @@ match. Other unknown
    inconsistencies might also be fixed. (#2676, @EmileTrotignon)

  • * The spacing of infix attributes is now consistent across keywords. Every
    keyword but begin function, and fun had attributes stuck to the keyword:
    match[@a], but fun [@a]. Now its also fun[@a]. (#2676, @EmileTrotignon)

  • * The formatting oflet a = b in fun ... is now consistent with other
    contexts like a ; fun .... A check for the syntax let a = fun ... in ...
    was made more precise. (#2705, @EmileTrotignon)

  • * |> begin, ~arg:begin, begin if, lazy begin, begin match,
    begin fun and map li begin fun can now be printed on the same line, with
    one less indentation level for the body of the inner expression.
    (#2664, #2666, #2671, #2672, #2681, #2685, #2693, @EmileTrotignon)
    For example :

    (* before *)
    begin
      fun x ->
        some code
    end
    (* after *)
    begin fun x ->
      some code
    end
  • * break-struct=natural now also applies to sig ... end. (#2682, @EmileTrotignon)

Fixed

  • Fixed wrap-comments=true not working with the janestreet profile (#2645, @Julow)
    Asterisk-prefixed comments are also now formatted the same way as with the
    default profile.

  • Fixed nested-match=align not working with match%ext (#2648, @EmileTrotignon)

  • Fixed the AST generated for bindings of the form let pattern : type = function ...
    (#2651, @v-gb)

  • Print valid syntax for the corner case (1).a (#2653, @v-gb)

  • Ast_mapper.default_mapper now iterates on the location of in in let+ .. in ..
    (#2658, @v-gb)

  • Fix missing parentheses in let+ (Cstr _) : _ = _ (#2661, @Julow)
    This caused a crash as the generated code wasn't valid syntax.

  • Fix bad indentation of let%ext { ... (#2663, @EmileTrotignon)
    with dock-collection-brackets enabled.

  • ocamlformat is now more robust when used as a library to print modified ASTs
    (#2659, @v-gb)

  • Fix crash due to edge case with asterisk-prefixed comments (#2674, @Julow)

  • Fix crash when formatting mld files that cannot be lexed as ocaml (e.g.
    containing LaTeX or C code) (#2684, @emillon)

  • * Fix double parens around module constraint in functor application :
    module M = F ((A : T)) becomes module M = F (A : T). (#2678, @EmileTrotignon)

  • Fix misplaced ;; due to interaction with floating doc comments.
    (#2691, @EmileTrotignon)

  • The formatting of attributes of expression is now aware of the attributes
    infix or postix positions: ((fun [@a] x -> y) [@b]) is formatted without
    moving attributes. (#2676, @EmileTrotignon)

  • begin%e ... end and begin [@a] ... end nodes are always preserved.
    (#2676, @EmileTrotignon)

  • begin end syntax for () is now preserved. (#2676, @EmileTrotignon)

  • Fix a crash on type 'a t = A : 'a. {a: 'a} -> 'a t. (#2710, @EmileTrotignon)

  • Fix a crash where type%e nonrec t = t was formatted as type nonrec%e t = t,
    which is invalid syntax. (#2712, @EmileTrotignon)

  • Fix commandline parsing being quadratic in the number of arguments
    (#2724, @let-def)

  • * Fix ;; being added after a documentation comment (#2683, @EmileTrotignon)
    This results in more ;; being inserted, for example:

    (* before *)
    print_endline "foo"
    let a = 3
    
    (* after *)
    print_endline "foo" ;;
    let a = 3
  • Fix dropped comment in if then (* comment *) begin .. end (#2734, @Julow)

0.27.0

02 Dec 15:39
5bac2e7

Choose a tag to compare

CHANGES:

Highlight

  • * Support OCaml 5.2 syntax (#2519, #2544, #2590, #2596, #2621, #2628, @Julow, @EmileTrotignon, @hhugo)
    This includes local open in types, raw identifiers, and the new
    representation for functions.
    This might change the formatting of some functions due to the formatting code
    being completely rewritten.

  • Support OCaml 5.3 syntax (#2609, #2610, #2611, #2622, #2623, #2562, #2624, #2625, #2627, @Julow, @Zeta611)
    This adds support for effect patterns, short functor type arguments and utf8
    identifiers.
    To format code using the new effect syntax, add this option to your
    .ocamlformat:

    ocaml-version = 5.3
    
  • Documentation comments are now formatted by default (#2390, @Julow)
    Use the option parse-docstrings = false to restore the previous behavior.

  • * Consistent indentation of polymorphic variant arguments (#2427, @Julow)
    Increases the indentation by one to make the formatting consistent with
    normal variants. For example:

      ...
      (* before *)
        (`Msg
          (foo bar))
      (* after *)
        (`Msg
           (foo bar))
    
  • Build on OCaml 5.3 (#2603, @adamchol, @Julow)

Added

  • Improve the emacs plugin (#2577, #2600, @gridbugs, @thibautbenjamin)
    Allow a custom command to be used to run ocamlformat and add compatibility
    with emacs ocaml tree-sitter modes.

  • Added option let-binding-deindent-fun (#2521, @henrytill)
    to control the indentation of the fun in:

    let f =
     fun foo ->
      bar
    
  • Added back the flag --disable-outside-detected-project (#2439, @gpetiot)
    It was removed in version 0.22.

  • Support newer Odoc syntax (#2631, #2632, #2633, @Julow)

Changed

  • * Consistent formatting of comments (#2371, #2550, @Julow)
    This is mostly an internal change but some comments might be formatted differently.

  • * Improve formatting of type constraints with type variables (#2437, @gpetiot)
    For example:

    let f : type a b c.
        a -> b -> c =
      ...
    
  • * Improve formatting of functor arguments (#2505, @Julow)
    This also reduce the indentation of functor arguments with long signatures.

  • Improvements to the Janestreet profile (#2445, #2314, #2460, #2593, #2612, @Julow, @tdelvecchio-jsc)

  • * Undo let-bindings and methods normalizations (#2523, #2529, @gpetiot)
    This remove the rewriting of some forms of let-bindings and methods:

    • let f x = (x : int) is no longer rewritten into let f x : int = x
    • let f (type a) (type b) ... is no longer rewritten into let f (type a b) ...
    • let f = fun x -> ... is no longer rewritten into let f x = ...
  • * The break-colon option is now taken into account for method type constraints (#2529, @gpetiot)

  • * Force a break around comments following an infix operator (fix non-stabilizing comments) (#2478, @gpetiot)
    This adds a line break:

      a
      ||
      (* this comment is now on its own line *)
      b
    

Fixed

  • Fix placement of comments in some cases (#2471, #2503, #2506, #2540, #2541, #2592, #2617, @gpetiot, @Julow)
    Some comments were being moved or causing OCamlformat to crash.
    OCamlformat refuses to format if a comment would be missing in its output, to avoid loosing code.

  • Fix attributes being dropped or moved (#2247, #2459, #2551, #2564, #2602, @EmileTrotignon, @tdelvecchio-jsc, @Julow)
    OCamlformat refuses to format if the formatted code has a different meaning than the original code, for example, if an attribute is removed.
    We also try to avoid moving attributes even if that doesn't change the original code, for example we no longer format open[@attr] M as open M [@@attr].

  • Remove trailing space inside a wrapping empty signature (#2443, @Julow)

  • Fix extension-point spacing in structures (#2450, @Julow)

  • * Consistent break after string constant argument (#2453, @Julow)

  • * Fix cinaps comment formatting to not change multiline string contents (#2463, @tdelvecchio-jsc)

  • * Fix the indentation of tuples in attributes and extensions (#2488, @Julow)

  • * Fix weird indentation and line breaks after comments (#2507, #2589, #2606, @Julow)

  • * Fix unwanted alignment in if-then-else (#2511, @Julow)

  • Fix missing parentheses around constraint expressions with attributes (#2513, @alanechang)

  • Fix formatting of type vars in GADT constructors (#2518, @Julow)

  • Fix [@ocamlformat "disable"] in some cases (#2242, #2525, @EmileTrotignon)
    This caused a bug inside class type constructs and when attached to a let ... in

  • Display a##b instead of a ## b and similarly for operators that start with # (#2580, @v-gb)

  • * Fix arrow type indentation with break-separators=before (#2598, @Julow)

  • Fix missing parentheses around a let in class expressions (#2599, @Julow)

  • Fix formatting of paragraphs in lists in documentation (#2607, @Julow)

  • Avoid unwanted space in references and links text in documentation (#2608, @Julow)

  • * Improve the indentation of attributes in patterns (#2613, @Julow)

  • * Avoid large indentation in patterns after let%ext (#2615, @Julow)

0.26.2

18 Apr 10:07

Choose a tag to compare

CHANGES:

Changed

0.26.1

15 Sep 09:44

Choose a tag to compare

CHANGES:

Changed

  • Compatible with OCaml 5.1.0 (#2412, @Julow)
    The syntax of let-bindings changed sligthly in this version.
  • Improved ocp-indent compatibility (#2428, @Julow)
  • * Removed extra break in constructor declaration with comment (#2429, @Julow)
  • * De-indent the object keyword in class types (#2425, @Julow)
  • * Consistent formatting of arrows in class types (#2422, @Julow)

Fixed

  • Fix dropped attributes on a begin-end in a match case (#2421, @Julow)
  • Fix dropped attributes on begin-end in an if-then-else branch (#2436, @gpetiot)
  • Fix non-stabilizing comments before a functor type argument (#2420, @Julow)
  • Fix crash caused by module types with nested with module (#2419, @Julow)
  • Fix ';;' formatting between doc-comments and toplevel directives (#2432, @gpetiot)

0.26.0

18 Jul 15:34
fe70498

Choose a tag to compare

CHANGES:

Removed

Deprecated

Bug fixes

  • Fix crash caused by let f (type a) :> a M.u = .. (#2399, @Julow)
  • Fix crash caused by module T = (val (x : (module S))) (#2370, @Julow)
  • Fix invalid formatting of then begin end (#2369, @Julow)
  • Protect match after fun _ : _ -> (#2352, @Julow)
  • Fix invalid formatting of (::) (#2347, @Julow)
  • Fix indentation of module-expr extensions (#2323, @gpetiot)

Changes

  • Indent as-patterns that have parentheses (#2359, @Julow)
  • Improve formatting of module arguments (#2322, @Julow)
  • Don't indent attributes after a let/val/external (#2317, @Julow)
  • Consistent indentation of @@ let+ x = ... (#2315, #2396, @Julow)
    It was formatted differently than @@ let x = ....

New features

  • Handle short syntax for generative functor types (#2348, @gpetiot)
  • Improved error reporting for unstable or dropped comments (#2292, @gpetiot)

0.25.1

06 Mar 19:16
651f767

Choose a tag to compare

CHANGES:

Bug fixes

  • Janestreet: Fix indentation of functions passed as labelled argument (#2259, @Julow)

0.25.0

24 Feb 09:51
c94ead5

Choose a tag to compare

CHANGES:

Library

Bug fixes

  • Fix indentation when ocamlformat is disabled on an expression (#2129, @gpetiot)
  • Reset max-indent when the max-indent option is not set (#2131, @hhugo, @gpetiot)
  • Add missing parentheses around immediate objects having attributes attached in 4.14 (#2144, @gpetiot)
  • Fix dropped comment attached to the identifier of an open-expression (#2155, @gpetiot)
  • Correctly format chunks of file in presence of enable/disable floating attributes (#2156, @gpetiot)
  • Remove abusive normalization in docstrings references (#2159, #2162, @EmileTrotignon)
  • Fix parentheses around symbols in if-then-else branches (#2169, @gpetiot)
  • Preserve position of comments around variant identifiers (#2179, @gpetiot)
  • Fix parentheses around symbol identifiers (#2185, @gpetiot)
  • Fix alignment inconsistency between let-binding and let-open (#2187, @gpetiot)
  • Fix reporting of operational settings origin in presence of profiles (#2188, @EmileTrotignon)
  • Fix alignment inconsistency of if-then-else in apply (#2203, @gpetiot)
  • Fix automated Windows build (#2205, @nojb)
  • Fix spacing between recursive module bindings and recursive module declarations (#2217, @gpetiot)
  • ocamlformat-rpc: use binary mode for stdin/stdout (#2218, @rgrinberg)
  • Fix interpretation of glob pattern in .ocamlformat-ignore under Windows (#2206, @nojb)
  • Remove conf mutability, and correctly display the conventional profile when using print-config (#2233, @EmileTrotignon)
  • Preserve position of comments around type alias (#2239, @EmileTrotignon)
  • Preserve position of comments around constructor record (#2237, @EmileTrotignon)
  • Preserve position of comments around external declaration strings (#2238, @EmileTrotignon, @gpetiot)
  • Preserve position of comments around module pack expressions (#2234, @EmileTrotignon, @gpetiot)
  • Correctly parenthesize array literals with attributes in argument positions (#2250, @ccasin)

Changes

  • Indent 2 columns after initializer keyword (#2145, @gpetiot)
  • Preserve syntax of generative modules ((struct end) vs ()) (#2135, #2146, @trefis, @gpetiot)
  • Preserve syntax of module unpack with type constraint (((module X) : (module Y)) vs (module X : Y)) (#2136, @trefis, @gpetiot)
  • Normalize location format for warning and error messages (#2139, @gpetiot)
  • Preserve syntax and improve readability of indexop-access expressions (#2150, @trefis, @gpetiot)
    • Break sequences containing indexop-access assignments
    • Remove unnecessary parentheses around indices
  • Mute warnings for odoc code blocks whose syntax is not specified (#2151, @gpetiot)
  • Improve formatting of odoc links (#2152, @gpetiot)
  • Preserve sugared extension node attached to an if carrying attributes (#2167, @trefis, @gpetiot)
  • Remove unnecessary parentheses around partially applied infix operators with attributes (#2198, @gpetiot)
  • JaneStreet profile: doesn't align infix ops with open paren (#2204, @gpetiot)
  • Re-use the type let_binding from the parser instead of value_binding, improve the spacing of let-bindings regarding of having extension or comments (#2219, @gpetiot)
  • The ocamlformat package now only contains the binary, the library is available through the ocamlformat-lib package (#2230, @gpetiot)

New features

  • Add a break-colon option to decide whether to break before or after the : symbol in value binding declarations and type constraints. This behavior is no longer ensured by ocp-indent-compat. (#2149, @gpetiot)
  • Format .mld files as odoc documentation files (#2008, @gpetiot)
  • New value vertical for option if-then-else (#2174, @gpetiot)
  • New value vertical for option break-cases (#2176, @gpetiot)
  • New value wrap-or-vertical for option break-infix that only wraps high precedence infix ops (#1865, @gpetiot)

0.24.1

18 Jul 11:57

Choose a tag to compare

CHANGES:

New features

  • Support odoc-parser.2.0.0 (#2123, @gpetiot)
    • Breaking change: incompatible with earlier versions of odoc-parser
    • New inline math elements {m ...} available in doc-comments
    • New block math elements {math ...} available in doc-comments

0.24.0

11 Jul 19:32

Choose a tag to compare

CHANGES:

New features

  • Support odoc-parser.2.0.0 (#2123, @gpetiot)
    • Breaking change: incompatible with earlier versions of odoc-parser
    • New inline math elements {m ...} available in doc-comments
    • New block math elements {math ...} available in doc-comments

0.23.0

07 Jul 08:04

Choose a tag to compare

CHANGES:

Removed

  • bench binary is not distributed anymore to avoid name collisions (#2104, @gpetiot)

Bug fixes

Changes

  • Use the API of ocp-indent to parse the .ocp-indent files (#2103, @gpetiot)
  • JaneStreet profile: set max-indent = 2 (#2099, @gpetiot)
  • JaneStreet profile: align pattern-matching bar | under keyword instead of parenthesis (#2102, @gpetiot)