ocaml-ppx / ocamlformat

Auto-formatter for OCaml code
MIT License
633 stars 179 forks source link

Improve formatting of assignment operators with comments #2617

Closed Julow closed 1 week ago

Julow commented 1 week ago

Avoids outputting the assignment operator on the right of a long comment and removes the inconsistent 1-indent of the operator in some cases:

 let _ =
-  r (* _________________________________________________________________ *) :=
-    1
+  r
+  (* _________________________________________________________________ *)
+  := 1

 let _ =
   r
-    (* _________________________________________________________________ *)
-    (* _________________________________________________________________ *)
-   := 1
+  (* _________________________________________________________________ *)
+  (* _________________________________________________________________ *)
+  := 1

Also fix an unstable comment in this case:

let _ =
  aaaaaaa
  (* __________________________________________________________________________________ *)
  := bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

Which now formats the same way as other infix operators:

let _ =
  aaaaaaa
  (* __________________________________________________________________________________ *)
  <> bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb