stephenh / ts-poet

A code generator DSL for typescript
Apache License 2.0
100 stars 12 forks source link

add prettier formatting overrides #60

Open angelinashepherd opened 3 months ago

angelinashepherd commented 3 months ago
stephenh commented 3 months ago

Hi @angelinashepherd ! We started out using prettier, but in projects with lots of code generation, the "just a little bit of time" per file really added up, so we've switched to dprint-node, which uses the Deno's project Rust-based formatter.

We attempt to output "prettier-ish" by default, just to match the rest of a codebase's output (which we assume will be using prettier), but we do overhead a few things like line-length.

You can customize these by passing opts like code.toString({ dprintOptions: ... }) with any of the options listed here:

https://dprint.dev/plugins/typescript/config/

Originally when we used prettier, it would automatically pick a project's .prettierrc / etc files, and it'd probably be doable to have ts-poet scan for .prettierrcs and convert a subset of prettier settings over to their dprint equivalents.

If you'd be interested in working on a PR for that, that'd be great. Thanks!

stephenh commented 3 months ago

Thinking about this again, if you're using ts-poet via Joist, we could probably add like a dprintOptions: ... setting within joist-config.json, which would allow easily configuring the dprint options that Joist would later push to dprint-node.

Although looks like dprint has its own config file, which is probably even better, i.e. setting up a .dprint.json:

https://dprint.dev/setup/#hidden-config-file

I'll add that to the docs for ts-poet as well as Joist.