ocaml-ppx / ocamlformat

Auto-formatter for OCaml code
MIT License
619 stars 174 forks source link

Question: Isn't it a regression? 0.25.1 -> 0.26.1 #2484

Open Kakadu opened 9 months ago

Kakadu commented 9 months ago

The placement of a comma looks weird.

➜  /tmp cat a.ml                                                                       
      let rez =
        [%type:
          ( [%t ptyp_constr ~loc lident (List.map names ~f:(ptyp_var ~loc))]
          , [%t ptyp_constr ~loc lident_g (List.map names_2 ~f:(ptyp_var ~loc))] )
          OCanren.Reifier.t]
➜  /tmp ocamlformat a.ml                                                           
let rez =
  [%type:
    ( [%t ptyp_constr ~loc lident (List.map names ~f:(ptyp_var ~loc))]
    , [%t ptyp_constr ~loc lident_g (List.map names_2 ~f:(ptyp_var ~loc))] )
    OCanren.Reifier.t]
;;
➜  /tmp ocamlformat --version                                                               
0.25.1
➜  /tmp opam install ocamlformat.0.26.1                                                    
...
Done.
➜  /tmp ocamlformat a.ml                                                                          
let rez =
  [%type:
    ( [%t ptyp_constr ~loc lident (List.map names ~f:(ptyp_var ~loc))]
      , [%t ptyp_constr ~loc lident_g (List.map names_2 ~f:(ptyp_var ~loc))] )
      OCanren.Reifier.t]
;;
➜  /tmp ocamlformat --version                                                                       
0.26.1                                                                          
➜  /tmp cat .ocamlformat                                                                        
profile=janestreet
Julow commented 9 months ago

This is done to improve compatibility with ocp-indent for those that use both in their formatting pipeline. This appeared in https://github.com/ocaml-ppx/ocamlformat/pull/2428 and can be avoided with the option ocp-indent-compat=false (--no-ocp-indent-compat on the CLI)

Kakadu commented 9 months ago

Thanks, it helps. Another question: is there a list of options to migrate from version A to A+1 without changing the OCaml code? I believe that ocamlformat --print-config --profile=janestreet doesn't give a full list.

P.S. The answer is probably no, because you mention hidden options which are not available outside https://github.com/ocaml-ppx/ocamlformat/issues/2414 P.P.S. It is not a shortcoming of janestreet profile, it hapens with default too. It looks like 0.26.1 had increased indent somehow, in a manner that it is not controlled my 'max-indent='

@@ -1731,8 +1722,8 @@ module Make (AstHelpers : GTHELPERS_sig.S) = struct
         self#wrap_tr_function_str ~loc tdecl
           (Exp.app_list ~loc (Exp.new_ ~loc @@ Lident class_name)
           @@ List.map rec_typenames ~f:(fun name ->
-                 Exp.fun_ ~loc (Pat.unit ~loc)
-                 @@ Exp.sprintf ~loc "%s_%s" self#plugin_name name)
+               Exp.fun_ ~loc (Pat.unit ~loc)
+               @@ Exp.sprintf ~loc "%s_%s" self#plugin_name name)
           @ self#apply_fas_in_new_object ~loc tdecl)

       method fancy_app ~loc trf (inh : Exp.t) subj = Exp.app ~loc trf subj
Julow commented 9 months ago

There's no such backward compatibility options. We are very careful at the changes made to the default profile but that's not the case of the janestreet profile, which changes often.