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

How can I configurate formatting of ternary operator? #432

Open
doox911 opened this issue Oct 4, 2022 · 3 comments
Open

How can I configurate formatting of ternary operator? #432

doox911 opened this issue Oct 4, 2022 · 3 comments
Labels

Comments

@doox911
Copy link

doox911 commented Oct 4, 2022

For example:

const value = is_prod 
  ? do() 
  :  is_laptop 
    ? do2()
    : do3();

Language: Javascript, Typescript,
Files: Vue, React, jsx and tsx.

@dsherret
Copy link
Member

Sorry for my delay. Do you mean the operator position? You can use the "conditionalExpression.operatorPosition" configuration for that (see https://dprint.dev/plugins/typescript/config/ and search for "operatorPosition").

Or are you wondering how to indent the second conditional expression? It's not possible to do that at the moment.

@doox911
Copy link
Author

doox911 commented Oct 17, 2022

Yes, it is nesting(second conditional expression) that interests me. Then let it be a wish for improvement)!

@unicornware
Copy link

unicornware commented Sep 6, 2023

@dsherret what option can i use to maintain the formatting below?

/**
 * @file Type Definitions - Writable
 * @module tutils/types/Writable
 */

/**
 * Construct a type where all properties of `T` are writable.
 *
 * This is the opposite of {@linkcode Readonly}.
 *
 * @todo examples
 *
 * @template T - Type to evaluate
 */
type Writable<T> = T extends unknown
  ? { -readonly [K in keyof T]: T[K] }
  : never

export type { Writable as default }

i tried changing operatorPosition (and its variants) to maintain, but the new formatting is still ugly. the only workaround is adding dprint-ignore comments, but that of course ignores more than what i am intending to. in my case, i have to add 80+ comments for one project.

edit: i updated the playground link to include more than just the above example. i'm trying to migrate from prettier, but i'm finding that all conditional type formatting results are less than desirable. line break/indentation removal is making my code less readable.

edit 2: i read through #450. from what i understand, that pr may actually fix my issue. is that correct?

unicornware added a commit to flex-development/tutils that referenced this issue Sep 7, 2023
- prettier 3.0 formatting has degraded in quality for js-like files, but the team refuses to fix it
- prettier can be removed completely once dprint has its own yaml plugin
- prettier formatting markdown was always subpar; it never played nicely with markdownlint
- prettier/prettier#15358
- prettier/prettier#5715
- prettier/prettier#11881
- dprint/dprint-plugin-typescript#432

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/tutils that referenced this issue Sep 7, 2023
- prettier 3.0 formatting has degraded in quality for js-like files, but the team refuses to fix it
- prettier can be removed completely once dprint has its own yaml plugin
- prettier formatting markdown was always subpar; it never played nicely with markdownlint
- prettier/prettier#15358
- prettier/prettier#5715
- prettier/prettier#11881
- dprint/dprint#736
- dprint/dprint-plugin-typescript#432

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/tutils that referenced this issue Sep 7, 2023
- prettier 3.0 formatting has degraded in quality for js-like files, but the team refuses to fix it
- prettier can be removed completely once dprint has its own yaml plugin
- prettier formatting markdown was always subpar; it never played nicely with markdownlint
- prettier/prettier#15358
- prettier/prettier#5715
- prettier/prettier#11881
- dprint/dprint#736
- dprint/dprint-plugin-typescript#432

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/tutils that referenced this issue Sep 7, 2023
- prettier 3.0 formatting has degraded in quality for js-like files, but the team refuses to fix it
- prettier can be removed completely once dprint has its own yaml plugin
- prettier formatting markdown was always subpar; it never played nicely with markdownlint
- prettier/prettier#15358
- prettier/prettier#5715
- prettier/prettier#11881
- dprint/dprint#736
- dprint/dprint-plugin-typescript#432

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/mkbuild that referenced this issue Sep 9, 2023
- prettier 3.0 formatting has degraded in quality for js-like files, but the team refuses to fix it
- prettier can be removed completely once dprint has its own yaml plugin + better json5 support
- prettier markdown formatting was always subpar; it never played nicely with markdownlint
- prettier/prettier#15358
- prettier/prettier#5715
- prettier/prettier#11881
- dprint/dprint#736
- dprint/dprint-plugin-typescript#432

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
unicornware added a commit to flex-development/nest-commander that referenced this issue Oct 22, 2023
- prettier 3.0 formatting has degraded in quality for js-like files, but the team refuses to fix it
- prettier can be removed completely once dprint has its own yaml plugin
- prettier formatting markdown was always subpar; it never played nicely with markdownlint
- prettier/prettier#15358
- prettier/prettier#5715
- prettier/prettier#11881
- dprint/dprint-plugin-typescript#432

Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants