[new release] ocamlformat-lib, ocamlformat and ocamlformat-rpc-lib (0.28.1) #28774
+176
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Auto-formatter for OCaml code
CHANGES:
Highlight
* Support for OCaml 5.4
(Build with OCaml 5.4 ocaml-ppx/ocamlformat#2717, OCaml 5.4 syntax support ocaml-ppx/ocamlformat#2720, consider case when a labeled tuple element has an infix expression so… ocaml-ppx/ocamlformat#2732, Fix precedence of tuples with labels ocaml-ppx/ocamlformat#2733, Fix issue #2729 ocaml-ppx/ocamlformat#2735, @Julow, @Octachron, @cod1r, @EmileTrotignon)
OCamlformat now supports OCaml 5.4 syntax.
Module packing of the form
((module M) : (module S))are no longerrewritten to
(module M : S)because these are now two different syntaxes.* Reduce indentation after
|> map (fun(promote ocp docking for infix apply. ocaml-ppx/ocamlformat#2694, @EmileTrotignon)Notably, the indentation no longer depends on the length of the infix
operator, for example:
@@ matchcan now also be on one line.Added
Added option
module-indentoption (Add module indent option ocaml-ppx/ocamlformat#2711, @HPRIOR) to control the indentationof items within modules. This affects modules and signatures. For example,
module-indent=4:
exp-grouping=preserveis now the default indefaultandocamlformatprofiles. This means that its now possible to use
begin ... endwithouttweaking ocamlformat. (makes exp-grouping=preserve the default ocaml-ppx/ocamlformat#2716, @EmileTrotignon)
Deprecated
the case, the tool no longer accepts unambiguous option names prefixes. For
example,
--max-iteris not accepted anymore, you have to pass the fulloption
--max-iters. This does not apply to the keys in the.ocamlformatconfiguration files, which have always required the full name.
See Remove the ability to specify command and option name prefixes dbuenzli/cmdliner#200.
(Cmdliner 2.0.0 compat ocaml-ppx/ocamlformat#2680, @emillon)
Changed
* The formatting of infix extensions is now consistent with regular
formatting by construction. This reduces indentation in
f @@ match%eexpressions to the level of indentation in
f @@ match. Other unknowninconsistencies might also be fixed. (infix attrs and expression are encoded in the AST ocaml-ppx/ocamlformat#2676, @EmileTrotignon)
* The spacing of infix attributes is now consistent across keywords. Every
keyword but
beginfunction, andfunhad attributes stuck to the keyword:match[@a], butfun [@a]. Now its alsofun[@a]. (infix attrs and expression are encoded in the AST ocaml-ppx/ocamlformat#2676, @EmileTrotignon)* The formatting of
let a = b in fun ...is now consistent with othercontexts like
a ; fun .... A check for the syntaxlet a = fun ... in ...was made more precise. (fun after let-in is now consistent ocaml-ppx/ocamlformat#2705, @EmileTrotignon)
*
|> begin,~arg:begin,begin if,lazy begin,begin match,begin funandmap li begin funcan now be printed on the same line, withone less indentation level for the body of the inner expression.
(
begin fun x ->now can be printed on a single line ocaml-ppx/ocamlformat#2664, overhaul begin match formatting ocaml-ppx/ocamlformat#2666, displaylazy beginon one line. ocaml-ppx/ocamlformat#2671, formatbegin ifon one line ocaml-ppx/ocamlformat#2672, Label arg begin ocaml-ppx/ocamlformat#2681,|> beginis now printed on a single line ocaml-ppx/ocamlformat#2685,map begin funon one line, second attempt ocaml-ppx/ocamlformat#2693, @EmileTrotignon)For example :
*
break-struct=naturalnow also applies tosig ... end. (break-struct apply on sig ocaml-ppx/ocamlformat#2682, @EmileTrotignon)Fixed
Fixed
wrap-comments=truenot working with the janestreet profile (Fix 'wrap-comments' not working with the janestreet profile ocaml-ppx/ocamlformat#2645, @Julow)Asterisk-prefixed comments are also now formatted the same way as with the
default profile.
Fixed
nested-match=alignnot working withmatch%ext(nest-match=align now works with match%ext. ocaml-ppx/ocamlformat#2648, @EmileTrotignon)Fixed the AST generated for bindings of the form
let pattern : type = function ...(generate better asts for function bindings ocaml-ppx/ocamlformat#2651, @v-gb)
Print valid syntax for the corner case (1).a (print valid syntax for the corner case (1).a ocaml-ppx/ocamlformat#2653, @v-gb)
Ast_mapper.default_mappernow iterates on the location ofininlet+ .. in ..(fix Ast_mapper not mapping over
inlocation inlet+ .. in ..ocaml-ppx/ocamlformat#2658, @v-gb)Fix missing parentheses in
let+ (Cstr _) : _ = _(Add missing parens in pattern in 'let+ (Cstr _) : t = ...' ocaml-ppx/ocamlformat#2661, @Julow)This caused a crash as the generated code wasn't valid syntax.
Fix bad indentation of
let%ext { ...(fix issue 2660 ocaml-ppx/ocamlformat#2663, @EmileTrotignon)with
dock-collection-bracketsenabled.ocamlformat is now more robust when used as a library to print modified ASTs
(fix a few failures when printing a modified AST ocaml-ppx/ocamlformat#2659, @v-gb)
Fix crash due to edge case with asterisk-prefixed comments (Fix error when asterisk prefixed comment looses its asterisks ocaml-ppx/ocamlformat#2674, @Julow)
Fix crash when formatting
mldfiles that cannot be lexed as ocaml (e.g.containing LaTeX or C code) (fix: handle case where doc does not lex as ocaml ocaml-ppx/ocamlformat#2684, @emillon)
* Fix double parens around module constraint in functor application :
module M = F ((A : T))becomesmodule M = F (A : T). (bugfix : Double parens functor constraint ocaml-ppx/ocamlformat#2678, @EmileTrotignon)Fix misplaced
;;due to interaction with floating doc comments.(fix doc comment interaction with ;; ocaml-ppx/ocamlformat#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 withoutmoving attributes. (infix attrs and expression are encoded in the AST ocaml-ppx/ocamlformat#2676, @EmileTrotignon)
begin%e ... endandbegin [@a] ... endnodes are always preserved.(infix attrs and expression are encoded in the AST ocaml-ppx/ocamlformat#2676, @EmileTrotignon)
begin endsyntax for()is now preserved. (infix attrs and expression are encoded in the AST ocaml-ppx/ocamlformat#2676, @EmileTrotignon)Fix a crash on
type 'a t = A : 'a. {a: 'a} -> 'a t. ([bugfix] fix crash with inline record type variable ocaml-ppx/ocamlformat#2710, @EmileTrotignon)Fix a crash where
type%e nonrec t = twas formatted astype nonrec%e t = t,which is invalid syntax. (type nonrec infix ext bugfix ocaml-ppx/ocamlformat#2712, @EmileTrotignon)
Fix commandline parsing being quadratic in the number of arguments
(Fix quadratic command-line parsing ocaml-ppx/ocamlformat#2724, @let-def)
* Fix
;;being added after a documentation comment (fix floating doc comments interaction with;;expressions ocaml-ppx/ocamlformat#2683, @EmileTrotignon)This results in more
;;being inserted, for example:Fix dropped comment in
if then (* comment *) begin .. end(Fix dropped comment in 'if then begin .. end' ocaml-ppx/ocamlformat#2734, @Julow)