-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Closed
Labels
lang:javascriptIssues affecting JSIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.type:duplicateIssues that are a duplicate of a previous issueIssues that are a duplicate of a previous issue
Description
Prettier 1.14.3
Playground link
Input:
const chainExample = someValue === 'a' ? 'a long non-nested ternary'
: someValue === 'b' ? 'to demonstrate that'
: someValue === 'c' ? 'a less ug style'
: someValue === 'd' ? 'for line starts and indentation'
: null;
const nestedExample = someValue === 'a'
? someValue === 'b'
? someValue === 'c' ? 'with a long nested ternary'
: 'not sure what to do here'
: 'but indentation doesn\'t help enough'
: 'to connect results with the predicates'
Output:
const chainExample =
someValue === "a"
? "a long non-nested ternary"
: someValue === "b"
? "to demonstrate that"
: someValue === "c"
? "indenting and newlines"
: someValue === "d"
? "are ug"
: null;
const nestedExample =
someValue === "a"
? someValue === "b"
? someValue === "c"
? "with a long nested ternary"
: "not sure what to do here"
: "but indentation doesn't help enough"
: "to connect results with the predicates";
Terminology
Given: condition ? exprT : exprF
Ternaries are chained when the exprF
contains another ternary.
Ternaries are nested when the exprT
contains another ternary.
Expected behavior:
When ternary statements are chained, do not over-indent, and use the :
as the line start. When ternary statements are nested, do something else...
RebeccaStevens and drhumlen
Metadata
Metadata
Assignees
Labels
lang:javascriptIssues affecting JSIssues affecting JSlocked-due-to-inactivityPlease open a new issue and fill out the template instead of commenting.Please open a new issue and fill out the template instead of commenting.type:duplicateIssues that are a duplicate of a previous issueIssues that are a duplicate of a previous issue