-
Notifications
You must be signed in to change notification settings - Fork 406
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
Auto format dune-project
files with dune fmt
#10716
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Max Große <[email protected]>
Signed-off-by: Max Große <[email protected]>
src/dune_rules/format_rules.ml
Outdated
| true -> | ||
Dune_project.file project | ||
|> Memo.Option.iter ~f:(fun path -> | ||
if String.equal "_build/default" (Path.Build.to_string dir) |
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'm not happy with this if check for the hard-coded build directory, but I didn't find a way to check if we are in the "_build/default" directory other than this.
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.
How about checking it for equality against Context.build_dir
?
EDIT: No longer relevant. |
Thanks.
|
Thanks for the feedback! I'll take another look |
Signed-off-by: Max Große <[email protected]>
Signed-off-by: Max Große <[email protected]>
416edcc
to
c47472e
Compare
Signed-off-by: Max Große <[email protected]>
Signed-off-by: Max Große <[email protected]>
Signed-off-by: Max Große <[email protected]>
Signed-off-by: Max Große <[email protected]>
Signed-off-by: Max Große <[email protected]>
@@ -190,7 +190,8 @@ Sometimes, the suggestion is to just remove the configuration. | |||
5 | (using fmt 1.2) | |||
^^^^^^^^^^^^^^^ | |||
Error: Starting with (lang dune 2.0), formatting is enabled by default. | |||
To port it to the new syntax, you can delete this part. | |||
To port it to the new syntax, you can replace this part by: | |||
(formatting (enabled_for dune ocaml reason)) |
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.
Unsure whether we should extend the help message by mentioning the differences between > 3.17 dune and 3.17+
i.e. that you can remove the stanza, but that it will also format dune-project
files.
@emillon I've added a version check so it will only automatically format from 3.17 (?) onwards. There's no explicit way to disable just formatting for |
src/dune_lang/format_config.ml
Outdated
@@ -14,27 +14,35 @@ module Language = struct | |||
type t = | |||
| Dialect of string | |||
| Dune | |||
| DuneProject |
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.
Dune_project
is the convention
Can you enable this feature for dune itself? IIRC, there were some problems with preserving multi line quoted strings in the dune language. |
Sorry, I don't think I understand the question. What feature exactly are you referring to? |
Dune itself has a dune-project file. It would be good to see how this PR works to auto-format it. |
Signed-off-by: Max Große <[email protected]>
Signed-off-by: Max Große <[email protected]>
Ahh, I see what you mean. I added the formatted |
If you could fix it in a separate PR that would be great. It's really an issue for all dune files, but project files include large description strings fairly often. |
Alright, I'm investigating some possible solutions and will try to create a separate draft PR in the coming days. |
Hi!
This PR enables automatic formatting of
dune-project
files when runningdune fmt
. This should close #3223. Note that there were some concerns raised on that issue regarding the formatting, but those should have been addressed by #3928, see also #2291.Note: I'm new to OCaml, especially working on such a mature codebase so there will probably a lot of mistakes in my submission. I hope it can still be of use and I'm more than happy to learn and address any problems with this PR.