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

dune format-dune-file doesn't respect the formatting stanza #3516

Open
Khady opened this issue May 30, 2020 · 9 comments
Open

dune format-dune-file doesn't respect the formatting stanza #3516

Khady opened this issue May 30, 2020 · 9 comments

Comments

@Khady
Copy link
Contributor

Khady commented May 30, 2020

In a project with a dune-project that says (formatting (enabled_for ocaml reason)), running dune format-dune-file will still format the dune file despite the formatting stanza saying that it shouldn't happen.

The problem mostly appears when using ocamllsp as dune format-dune-file is a low level command that one usually doesn't call directly.

dune 2.5

@ghost
Copy link

ghost commented Jun 1, 2020

/cc @rgrinberg @emillon

My understanding is that dune format-dune-file is indeed a low-level command that doesn't read the dune-project file. Though it seems like it should given that the formatting of dune files is versioned as per this discussion.

@rgrinberg
Copy link
Member

rgrinberg commented Jun 8, 2020 via email

@ghost
Copy link

ghost commented Jun 8, 2020

If we start doing the formatting in-process, do we still need dune format-dune-file to be low-level?

@emillon
Copy link
Collaborator

emillon commented Jun 8, 2020

To confirm, yes, dune format-dune-file is supposed to be a low level command and always format its input. A high level frontend to @fmt to check (or fix) formatting of all (or some) files based on the dune-project configuration would probably be enough to fix this problem.

@ghost
Copy link

ghost commented Jun 8, 2020

We should probably compare what dune does to what ocamlformat does. My understand is that right now, the editor calls ocamlformat <file> and this command will read the ocamlformat configuration files to decide whether and how to format the file. Is that correct?

@jberdine
Copy link
Contributor

jberdine commented Jun 8, 2020 via email

@ghost
Copy link

ghost commented Jun 8, 2020

Do we think this mode of operation is the right one? From a distance, it seems good to me.

If we think it is, then we should add a similar feature in Dune. i.e. add a dune command to format a dune file taking into account the dune configuration files, and taking a similar -name flag.

For formatting dune files as part of the build, we decided that it's ok to do the formatting in-process, so we shouldn't really need the low-level command anymore.

@nojb
Copy link
Collaborator

nojb commented Jun 8, 2020

For formatting dune files as part of the build, we decided that it's ok to do the formatting in-process, so we shouldn't really need the low-level command anymore.

See #3536

@Leonidas-from-XIV
Copy link
Collaborator

I ran into a case where I wanted to reformat dune files even if it wasn't enabled in the project (due to programmatic editing of dune files with tools like sexplib and then cleaning up the processed output by reformatting). In this case dune format-dune-file reformatting always enabled independently of the project settings is quite helpful.

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

No branches or pull requests

6 participants