We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
From issues such as issue #41 and prettier/prettier#5814, I am starting to wonder if we should consider a better way to format ternary expressions.
As described in prettier/prettier#5814 (comment) & prettier/prettier#5814 (comment), my idea would be to format JavaScript & TypeScript ternaries just like Prettier formats ternaries in JSX:
const result = type === 'first' ? ( getFirstThing() ) : type === 'second' ? ( getSecondThing() ) : ( getOtherThing() )
I tried the following update and it seems to do what we want here:
--- a/src/language-js/printer-estree.js +++ b/src/language-js/printer-estree.js @@ -370,6 +370,7 @@ function printTernaryOperator(path, options, print, operatorOptions) { const lastConditionalParent = previousParent; if ( + true || // [prettierx option goes here instead of `true`] operatorOptions.shouldCheckJsx && (isJSXNode(testNode) || isJSXNode(consequentNode) ||
/cc @aMarCruz @sheerun
The text was updated successfully, but these errors were encountered:
I just tried the following JavaScript on standard with no issues:
standard
const a1 = process.env.a ? ( 1 + 2 * 3 ) : ( 4 * 5 + 6 ) console.log(`a1 value: ${a1}`)
Sorry, something went wrong.
I'm for as much similarity to prettier as possible, unless standard has conflicting rule for something
prettier
prettier format above as:
const a1 = process.env.a ? 1 + 2 * 3 : 4 * 5 + 6; console.log(`a1 value: ${a1}`);
and for longer ternaries:
const a1 = process.env.a ? 123412341234 + 34523452345234523 * 34123412341234 : 34123412341234 * 34123412341234 + 34123412341234; console.log(`a1 value: ${a1}`);
but for JSX it outputs:
const StorybookLoader = ({ match }) => match.params.storyId === "button" ? ( <ButtonStorybook /> ) : match.params.storyId === "color" ? ( <ColorBook /> ) : match.params.storyId === "typography" ? ( <TypographyBook /> ) : match.params.storyId === "loading" ? ( <LoaderStorybook /> ) : match.params.storyId === "deal-list" ? ( <DealListStory /> ) : ( <Message> <Title>{"Missing story book"}</Title> <Content> <BackButton /> </Content> </Message> );
brodybits
No branches or pull requests
From issues such as issue #41 and prettier/prettier#5814, I am starting to wonder if we should consider a better way to format ternary expressions.
As described in prettier/prettier#5814 (comment) & prettier/prettier#5814 (comment), my idea would be to format JavaScript & TypeScript ternaries just like Prettier formats ternaries in JSX:
I tried the following update and it seems to do what we want here:
/cc @aMarCruz @sheerun
The text was updated successfully, but these errors were encountered: