Deno: Migrate from prettier to dprint for internal formatting

Created on 9 Mar 2020  Â·  10Comments  Â·  Source: denoland/deno

Currently we use the Rust parts of dprint to power deno fmt, but we utilise prettier for formatting as part of our toolchain.

Is suspect this means we would need to create a standalone minimalistic binary that wraps dprint to do the file system bindings.

cc/ @dsherret

Most helpful comment

I "finished" writing a markdown formatter. Over the next week I'm going to try it out on deno's codebase and probably spend some time fixing more bugs.

image

All 10 comments

Yes, creating a small binary would be your best option for now.

By the way, I tried using dprint on the internal deno code last night then opened up around 20 minor issues on the dprint issue tracker. There are also a few parsing issues I also need to still open in swc. Overall works well, but I will be working on fixing those.

Yes I'm for it - I think dprint is almost working - I think we should hold off for another release or so. (At least we should be able to format cli/js without getting a panic.)

Maybe this could be done in a special dprint crate in tools/dprint/ ? Ideally the config would be done in that crate and then imported in the CLI so we don't have duplicate configuration or deps that get out of sync.

Maybe this could be done in a special dprint crate in tools/dprint/ ? Ideally the config would be done in that crate and then imported in the CLI so we don't have duplicate configuration or deps that get out of sync.

deno fmt can be factored out to a separate crate; we could just move definition of Clap app and cli/fmt.rs. Similarly to cli it could have both lib.rs and main.rs so it can be consumed as Deno subcommand as well as standalone shell to format internal code.

I've created a milestone so progress can be tracked on the bugs in dprint related to this:

https://github.com/dsherret/dprint/milestone/2

I went through and checked for anymore debug panics and erroneous syntax errors, but I didn't find any.

As I fix these and reduce the noise from number of changes I'll keep opening issues, but let me know if you see anything else that should be fixed. I'll report back once it's done.

By the way, here's a list of configuration you might want to change to more align with prettier:

.brace_position(BracePosition::SameLine) // default is NextLineIfHanging
.comment_line_force_space_after_slashes(false)
.construct_signature_space_after_new_keyword(true)

I'll update that list as I remember more.

@dsherret Thanks (updated in https://github.com/denoland/deno/pull/4314). It would be cool to have a configuration method like .prettier(true) to default as closely as possible to prettier.

@ry I was thinking about that earlier today too. Opened https://github.com/dsherret/dprint/issues/147 just now (I was also thinking perhaps .deno(true) could be another possibility)

Update: dprint can now be installed using cargo install dprint. Waiting on milestone finish to use it internally

Still a lot of work to do, but Dprint is probably good enough to use internally at the moment or at least to start getting some feedback on. Lots of issues have been resolved. I published dprint 0.1.3 as a Rust crate and there is a deno config option—{ "deno": true } (I replaced the "prettier" option with a "deno" option because Deno defaults use trailing commas where allowed in runtime, but Prettier defaults use trailing commas only where allowed in ES5).

Edit: I just remembered I’ve only been testing out the std folder. I’ll have a look at the other folders tomorrow.

I "finished" writing a markdown formatter. Over the next week I'm going to try it out on deno's codebase and probably spend some time fixing more bugs.

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JosephAkayesi picture JosephAkayesi  Â·  3Comments

doutchnugget picture doutchnugget  Â·  3Comments

justjavac picture justjavac  Â·  3Comments

ry picture ry  Â·  3Comments

ry picture ry  Â·  3Comments