Skip to content
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

Add (format-dune-file) action #11166

Merged
merged 8 commits into from
Dec 4, 2024
Merged

Add (format-dune-file) action #11166

merged 8 commits into from
Dec 4, 2024

Conversation

nojb
Copy link
Collaborator

@nojb nojb commented Nov 28, 2024

Context is #10892 (comment).

This exposes a user action (format-dune-file file) which outputs the formatted contents of file (assumed to contain S-expressions) to standard output. It uses the version for the formatting specified by the current project.

This action should be used instead of calling dune format-dune-file from inside a user rule, which does not work well (calling Dune recursively is not really well supported).

cc @maiste @Leonidas-from-XIV

doc/reference/actions/format-dune-file.rst Outdated Show resolved Hide resolved
@@ -62,6 +62,7 @@ let atom_table =
; "aliases", Field
; "alias", Field
; "enabled_if", Field
; "format-dune-file", Field
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be this?

Suggested change
; "format-dune-file", Field
; "format-dune-file", Since ((3,18), Field)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed.

Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's already a format action defined in Format_rules. You can just use that instead of extending the engine.

@nojb
Copy link
Collaborator Author

nojb commented Dec 1, 2024

There's already a format action defined in Format_rules. You can just use that instead of extending the engine.

Thanks, I had missed this. This is now done: a7abf53. For simplicity, the action now has the form (format-dune-file <src> <dst>) and outputs the formatted contents to <dst> (a file), instead of standard output.

@@ -188,3 +188,47 @@ Non 0 error code:
File "", line 2, characters 0-0:
Error: unclosed parenthesis at end of input
1

Using the built-in action.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a test demonstraating how the action fails when given an invalid dune file?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks.

@rgrinberg
Copy link
Member

Would be appreciated if the update to dune lang 3.18 was done in a separate PR

@nojb
Copy link
Collaborator Author

nojb commented Dec 2, 2024

Would be appreciated if the update to dune lang 3.18 was done in a separate PR

Good idea, done in #11175

@nojb nojb force-pushed the format-dune-file-action branch from a7abf53 to 6978294 Compare December 3, 2024 08:19
@nojb
Copy link
Collaborator Author

nojb commented Dec 3, 2024

Thanks for the review @rgrinberg. I think all issues have been addressed.

nojb added 7 commits December 3, 2024 11:17
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
Signed-off-by: Nicolás Ojeda Bär <[email protected]>
@nojb
Copy link
Collaborator Author

nojb commented Dec 4, 2024

Planning to merge soon if the CI passes. Yell if you object!

@nojb nojb merged commit a09c51f into ocaml:main Dec 4, 2024
28 checks passed
@nojb nojb deleted the format-dune-file-action branch December 4, 2024 08:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants