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 flag to dune fmt to disable promoting #8289

Merged
merged 1 commit into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions bin/build_cmd.ml
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,25 @@ let fmt =
]
in
let term =
let+ common = Common.term in
let common = Common.set_promote common Dune_engine.Clflags.Promote.Automatically in
let+ common = Common.term
and+ no_promote =
Arg.(
value
& flag
& info
[ "preview" ]
~doc:
"Just print the changes that would be made without actually applying them. \
This takes precedence over auto-promote as that flag is assumed for this \
command.")
in
let common =
Common.set_promote
common
(if no_promote
then Dune_engine.Clflags.Promote.Never
else Dune_engine.Clflags.Promote.Automatically)
in
let config = Common.init common in
let request (setup : Import.Main.build_system) =
let dir = Path.(relative root) (Common.prefix_target common ".") in
Expand Down
2 changes: 2 additions & 0 deletions doc/changes/8289.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Add a `--preview` flag to `dune fmt` which causes it to print out the changes
it would make without applying them (#8289, @gridbugs)
34 changes: 34 additions & 0 deletions test/blackbox-tests/test-cases/formatting/fmt-no-promote.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
$ cat > dune-project << EOF
> (lang dune 3.0)
> EOF

Make a dune file that should be formatted.
$ cat > dune << EOF
> (rule (write-file a b))
> EOF

Run `dune fmt --preview` twice to test it is idempotent. In a terminal these
commands would also print the diff of what would be changed.
$ dune fmt --preview
File "dune", line 1, characters 0-0:
Error: Files _build/default/dune and _build/default/.formatted/dune differ.
[1]
$ dune fmt --preview
File "dune", line 1, characters 0-0:
Error: Files _build/default/dune and _build/default/.formatted/dune differ.
[1]

Show the formatted file from _build.
$ cat _build/default/.formatted/dune
(rule
(write-file a b))

Actually format the file
$ dune fmt
File "dune", line 1, characters 0-0:
Error: Files _build/default/dune and _build/default/.formatted/dune differ.
Promoting _build/default/.formatted/dune to dune.
[1]

Now the output of `dune fmt --preview is empty`.
$ dune fmt --preview