-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable ocaml code formatting with dune fmt
#207
Conversation
Some OBus_value.C.(value |> cast_single basic_string) | ||
with | ||
_ -> None | ||
try Some OBus_value.C.(value |> cast_single basic_string) with _ -> None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a fan of these single-line try .. with ...
's, not sure if it can be turned off.
return @@ Error (MissingRequestedInputs mandatory_inputs) | ||
| Passphrase p, [ "Passphrase" ] -> | ||
return | ||
@@ Ok [ ("Passphrase", p |> OBus_value.C.(make_single basic_string)) ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the way it breaks the line after return
here is odd to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Me too
; ipv6; ethernet; proxy; nameservers; security | ||
}) | ||
pure | ||
(fun |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the issue here is not the formatting, but the fun
with 10+ arguments.
I prefer lists with the let not_connected_form service =
let requires_passphrase = service.security <> [None] in
form
~a:
[ a_action ("/network/" ^ service.id ^ "/connect")
; a_method `Post
; Unsafe.string_attrib "is" "disable-after-submit"
]
(Option.to_list
(maybe_elem requires_passphrase
(label
~a:[a_class ["d-Label"]]
[ txt "Password"
; input
~a:
[ a_input_type `Password
; a_class ["d-Input"; "d-Network__Input"]
; a_name "passphrase"
; Unsafe.string_attrib "is" "show-password"
]
()
]
)
)
@ [ p
[ input
~a:[a_input_type `Submit; a_class ["d-Button"]; a_value "Connect"]
()
]
]
) |
I see the visual appeal, but I find that it is more cumbersome to edit, because with |
That’s right. But I find it so hard to see blocks with the Did you notice other important differences between |
c8d9fcd
to
2c5996e
Compare
@guyonvarch I pushed the code formatted with |
Use space around elements?
|
Don't have a strong opinion about it, but would opt for less customization of the default profile settings to avoid causing unexpected formatting. |
@guyonvarch anything else that sticks out / looks annoying? The current config is decent enough for me and I think consistency is more important than a specific style. @knuton we have converged towards something, please take another look. |
Using |
And apart from removing the |
We’ll need a CI check to enforce the formatting afterward. And also consider formating in |
Cherry-picked |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good, one thing I have an issue with is operator pipelines. Maybe there is a decent enough fix for that.
| Passphrase of string | ||
(** The passphrase for authentication. For example a WEP key, a PSK passphrase or a passphrase for EAP authentication methods.*) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe putting comments above would yield less weird formatting?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Putting it above actually yields a warning: Warning 50 [unexpected-docstring]: unattached documentation comment
from_string body | ||
|> get_dict | ||
|> List.assoc "address" | ||
|> get_string | ||
|> fun address -> return {address} | ||
from_string body |> get_dict |> List.assoc "address" |> get_string | ||
|> fun address -> return { address } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems quite unfortunate to me, pipelines are sometimes on multiple lines, sometimes not, and overall harder for me to read.
Have you considered break-infix = wrap-or-vertical
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That definitely helps, added in fc2b21b
( "" | ||
, (* path to Curl executable (uses PATH if empty string) *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably move this before the comma so it stays close to the string literal it refers to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, will do some manual fixes once we settle on the final formatting rules.
Added a simple check in d672360
My personal preference would be not to have anything interrupting development due to incorrect formatting, so I would vote for not adding it there. |
What we normally have is not a check that fails, but an option to auto-format as part of the dev loop |
Added in 3c8004e. It will cause a double reload/restart (due to the written changes), but I guess that's OK? If this was the last thing, I can squash the commits, deal with |
I think so, but do we need to get #209 through first? Or how would we resolve conflicts? |
Yes, that would certainly be preferable! |
#209 is merged |
3.11 is the latest available on current nixpkgs channel used
3c8004e
to
9535b67
Compare
squashed and rebased on top of main, ready for merging. |
This is a preview of automatic code formatting using
ocamlformat
/dune fmt
I tried to tweak it (see
.ocamlformat
), but a couple of issues I see with all 3ocamlformat
profiles (and that I am not sure are configurable):let a = { ... }
) get squashed into a single line, which is not good for readability (therefore currentlymargin = 80
, to prevent this as much as possible)|>
)dune
files are formatted weirdly too (sometimes it breaks libraries into separate lines, sometimes it doesn't?), did not try to tweak thatIn general,
ocamlformat
is meant to produce a canonical format regardless of how the input source is formatted, so it does not preserve any manual breaks/whitepsace.@knuton @guyonvarch please check it out and see what you think.
You can experiment with the options here: https://gpetiot.github.io/ocamlformat-preview/