dprint-plugin-typescript
dprint-plugin-typescript copied to clipboard
conditionals: add support for nested indentation
We've had this in our fork for over a year now, and I noticed https://github.com/dprint/dprint-plugin-typescript/issues/432 pop up.
This PR adds support for nested indentation in conditional types and expressions, so that it formats as a tree.
Ah, I think I accidentally made the commit on my personal account so the CLA assistant thinks I haven't signed it...
edit: yep, all fixed, just signed it on my personal account.
Cool. Thanks @declanvong! I'll try to take a look on the weekend. Very busy next few weeks because of work work.
Bump on this one! I also have a couple more PRs - would you rather I just raise them all immediately? and then we can comment / discuss there? Most of them have linkable issues as well.
Otherwise I'm happy to raise them one by one if that makes it less stressful, lol
Ah yep, I can take a look!
Note: I've literally just started back at work today and I might be busy with onboarding, so I might take some time as well :)
I checked out the new tests; I think that I will have to add something like conditionalType.linePerExpression in order to achieve the same thing that we have right now for conditional expr.
Does that sound okay?
Updates:
- Added
conditionalType.linePerExpression. Although name tbd, since it's not an expression... so maybelinePerBranchorlinePerTypemight be might accurate? Not sure. - I lifted all of the conditional logic up into the head section instead of being in the body, so the same
force_cons_alt_newlinethat's currently there will drive the forced newline.
Hopefully this PR can be resurrected, the lack of this feature is one of my only gripes with dprint!
@declanvong @dsherret Hi guys. Researching the code formatter for our company as ESLint announced their stylistic rule deprecation. DPrint not supporting conditional types syntax is a blocker for us (we consider Prettier and Biome, but DPrint seems to be the best). What is the status of this PR?
Hey, @dsherret can we do something to help move this along? We would love to see it merged.
would like to also see this hopefully soon
I've forked this fork and made a wasm release if anyone wants to use this now you can reference it directly in your plugins block.
I'm planning on using dprint for the new version of semantic to enforce styles and this was a blocker for me i noticed on my first codebase wide format run.
"plugins": [
"https://github.com/jlukic/dprint-plugin-typescript/releases/download/0.94.0-tern/dprint_plugin_typescript.wasm",
]
Error when formatting const generics in functions.
function foo<const T>(x: T){
return x
}
Error formatting .../index.ts. Message: Line 1, column 27: Expected ',', got 'T'
function foo<const T>(x: T){
I've forked this fork and made a wasm release if anyone wants to use this now you can reference it directly in your plugins block.
I'm planning on using
dprintfor the new version of semantic to enforce styles and this was a blocker for me i noticed on my first codebase wide format run."plugins": [ "https://github.com/jlukic/dprint-plugin-typescript/releases/download/0.94.0-tern/dprint_plugin_typescript.wasm", ]
Hi @jlukic! thanks for doing this, and sorry if its a dumb question but when attempting to use your fork and explicitly setting the rules
{
"conditionalExpression.linePerExpression": true,
"conditionalType.linePerExpression": true,
"conditionalExpression.useNestedIndentation": true,
"conditionalType.useNestedIndentation": true,
}
I get an error for these configs not being valid. Do you have any pointers here for how to resolve this?
I get an error for these configs not being valid. Do you have any pointers here for how to resolve this?
@shaunak-thea I built a version of this that seems to be working so far. this is my first time interacting with dprint and rust. YMMV.
https://github.com/NtTestAlert/dprint-plugin-typescript/releases/tag/0.95.11-tern
"plugins": [
"https://github.com/NtTestAlert/dprint-plugin-typescript/releases/download/0.95.11-tern/dprint_plugin_typescript.wasm",
]
(I have no idea what implications of just merging origin to the fork and using the resulting wasm are because I didn't read almost any of the code but it works.)
would be nice to have this in the main library because the original behavior is unreadable. especially since with out it I need to patch the ben_12/eslint-plugin-dprint package to use a locally stored .wasm and schema.json :(